我想使用以下代码 (AndroidStudio Chipmunk) 将 USB CDC 设备(FTDI 芯片或 CD2010 或定制芯片)连接到我的 Galaxy A12 (Android SDK 30):
\npublic class MainActivity extends AppCompatActivity {\npublic static final String ACTION_USB_PERMISSION = "com.example.usbtestapp.USB_PERMISSION";\nstatic final int intentFlags = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) ? PendingIntent.FLAG_IMMUTABLE : 0;\nstatic final int MY_CAMERA_PERMISSION_CODE = 100;\nprivate Context ContextofMainAcitivity;\npublic IntentFilter USBconnectdisconnect_intentFilter;\npublic Intent GetEXTRA_PERMISSION_GRANTEDIntent;\npublic PendingIntent current_usbpermissionIntent;\npublic UsbDevice current_usbdevice;\npublic UsbManager current_usbManager;\nprivate static final String TAG = "usbtestapp";\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n ContextofMainAcitivity = this;\n current_usbManager = (UsbManager)getSystemService(Context.USB_SERVICE);\n USBconnectdisconnect_intentFilter = new IntentFilter();\n USBconnectdisconnect_intentFilter.addAction(ACTION_USB_PERMISSION);\n USBconnectdisconnect_intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);\n …Run Code Online (Sandbox Code Playgroud) 我需要编写一个客户端 - 服务器应用程序,其中一个小型服务器放在USB小工具上,并与主机上的客户端应用程序通信.
我之前没有做过这类事情,但我已经完成了webapps,通常,它们都是使用lo环回网络接口在本地机器上开发和调试的.这可能影响了我的思维方式,我正在寻找一种在我的机器上模拟USB主机和小工具的方法,这样我就可以在我的PC上完全构建应用程序的两端,然后再深入了解实际的小工具并获得事情进行着.
这是正确的方法吗?我意识到USB协议是不对称的,并且在这里找到了一些参考,但它似乎是最自然的方式来实现它.
如果这是正确的方式,我该如何从这样的事情开始,是否存在其他人都知道我可能会偶然发现的潜在问题?
我之前从谷歌搜索中找到的参考文献.有Linux内核模块(我的Ubuntu安装的一部分)似乎能够模拟主机和小工具端(分别是dummy_hcd和gadgetfs).我的想法是简单地拥有类似的东西
Host application (client) on PC <-> device file 0 <-> Loopback device <-> device file 1 <-> Gadget application (server) also on PC (will be moved to gadget).
Run Code Online (Sandbox Code Playgroud) 我正在编写一个正在写入HID设备的程序,并且在WriteFile函数上收到错误87,无效参数.我从Jan Axelson的USB Complete中获得了功能,所以我不确定为什么我会收到错误.我用它来找到我的设备:
private void USBInit()
{
IntPtr deviceInfoSet;
Int32 memberIndex = 0;
SP_DEVICE_INTERFACE_DATA MyDeviceInterfaceData = new SP_DEVICE_INTERFACE_DATA();
Int32 bufferSize = 0;
IntPtr detailDataBuffer;
Boolean success = false;
deviceFound = false;
HidD_GetHidGuid(ref hidGuid); // Get the GUID
deviceInfoSet = SetupDiGetClassDevs // Get pointer to a device info set
(ref hidGuid,
IntPtr.Zero,
IntPtr.Zero,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
do
{
MyDeviceInterfaceData.cbSize = Marshal.SizeOf(MyDeviceInterfaceData); // Identify Device Interface
success = SetupDiEnumDeviceInterfaces
(deviceInfoSet,
IntPtr.Zero,
ref hidGuid,
memberIndex,
ref MyDeviceInterfaceData);
success = SetupDiGetDeviceInterfaceDetail // Request Structure …Run Code Online (Sandbox Code Playgroud) 我想为Android 2.3手机制作RPG,并认为优秀的老Gameboy拥有这类游戏的完美格式.所以我想建立一个带有D-Pad和几个键的"Case",并通过USB将它们与Android设备连接起来.我不想要蓝牙,因为它需要很多能量.我想过为Case提供自己的Battery Cell,并且可能会加载Android设备.所以我的问题是:
如何从Android设备访问此案例的密钥?
我试着获取usb stick的urb信息.我写的如下:
#include <sys/ioctl.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <usb.h>
/* #include <stropts.h> */
/* #include <inttypes.h> */
#include <linux/usbdevice_fs.h>
/* #include <asm/byteorder.h> */
/* #include <linux/usb/ch9.h> */
#define USBDEVFS_REAPURB _IOW('U', 12, void *)
int main(int argc, char *argv[])
{
int fd;
int result;
int i;
struct usbdevfs_urb * receive;
receive = malloc(sizeof (struct usbdevfs_urb));
bzero(receive, sizeof (struct usbdevfs_urb));
char file[30];
strncpy (file, argv[1], 30);
if ((fd = open(file, O_RDWR)) < 0) …Run Code Online (Sandbox Code Playgroud) 早上好家伙.
我买了一个集成了电阻式触摸屏的LCD嵌入式显示器.TS可通过USB连接.
我已将其连接到运行Android 4.0.3的设备,并且触摸被正确识别为外部HID.问题:敲击(按下)不被认为是选择/确认......出现这种情况,当我点击屏幕,是在协调我finger..like的我感动corrispondance移动指针(箭头)的唯一的事情没有左键单击的鼠标HID
我不可能滚动或选择一些东西 - >对我来说很乱:(
请记住,我有另一台带有集成USB TS的LCD,可以正常工作.我可以选择的情况下,我对他们的挖掘图标,我可以滚动窗口等 - > exactely像左键鼠标点击总是 - >确定对我!
也许这是司机的问题,但我没有具体的想法.
Ps我没有该设备的特定驱动程序.
有什么建议吗?请帮我 :)
先感谢您!!!!!
我刚开始进行硬件编程,一直在尝试从USB设备获取序列号。我正在应用程序级别而不是内核级别实现所有功能。
我已经有一个字典可以匹配USB设备,因此我知道我有正确的设备。我不确定的是要返回的数据,如何解释它以及我是否正确处理了该问题。
因此,这里有一些我一直在尝试使用的代码,用于从设备获取序列号。
IOReturn retSerialIndex;
UInt8 snsi;
retSerialIndex = (*usbDevice)->USBGetSerialNumberStringIndex(usbDevice, &snsi);
if (retSerialIndex != kIOReturnSuccess)
{
printf("Could not get serial number string index (error: %x)\n", retSerialIndex);
}
printf("Serial string index is %x\n", retSerialIndex);
IOReturn retSerial;
IOUSBConfigurationDescriptorPtr *desc;
if (retSerialIndex)
{
retSerial = (*usbDevice)->GetConfigurationDescriptorPtr(usbDevice,
retSerialIndex,
desc);
if (retSerial != kIOReturnSuccess)
{
printf("Could not get serial number using string index (error: %x)\n", retSerial);
}
}
printf("Serial number is %x\n", retSerial);
char serialString;
serialString = getUSBStringDescriptor(usbDevice, retSerial);
printf("Serial string is %c\n", serialString);
Run Code Online (Sandbox Code Playgroud)
这是我的getUSBStringDescriptor实现: …
我正在尝试通过USB将我的Raspberry PI连接到Pic4550.(使用Windows c#程序,Pic功能正常!).所以我安装了rpi 2,pyusb,并尝试在[ https://github.com/walac/pyusb/blob/master/docs/tutorial.rst][1]的帮助下进行通信
我连接到USB设备,lsusb显示:
总线001器件006:ID 04d8:0080 Microchip Technology,Inc.
python prog找到了设备!获取正确的配置但无法写入消息:
usb.core.USBError:[Errno 16]资源忙
我尝试以sudo身份运行,我添加了规则:
SUBSYSTEM =="usb",ATTR {idVendor} =="04d8",ATTR {idProduct} =="0080",MODE ="666"
无论如何,我得到相同的资源忙
任何胶水帮助链接?
我正在使用通过USB连接的ACS ACR1252U读卡器(http://www.acs.com.hk/en/products/342/acr1252u-usb-nfc-reader-iii-nfc-forum-certified-reader/)说实话,我不知道如何让它工作.我用谷歌搜索了很多东西,但没有运气.我正在使用Debian的变种.以下是我所做的或多或少:
我使用dmesg得到以下内容:
[ 7173.059710] usb 1-1.3: new full-speed USB device number 6 using dwc_otg
[ 7173.160500] usb 1-1.3: not running at top speed; connect to a high speed hub
[ 7173.163114] usb 1-1.3: New USB device found, idVendor=072f, idProduct=223b
[ 7173.163147] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 7173.163168] usb 1-1.3: Product: ACR1252 Dual Reader
[ 7173.163186] usb 1-1.3: Manufacturer: ACS
Run Code Online (Sandbox Code Playgroud)
我使用以下Python代码来获取有关设备的更多详细信息:
#!/usr/bin/python
import sys
import usb.core
# find USB devices
dev = usb.core.find(find_all=True) …Run Code Online (Sandbox Code Playgroud) 我的USB触摸屏连接到我的硬件设置.当我使用时,cat /proc/bus/input/devices我得到有关我的设备的以下详细信息:
I: Bus=0003 Vendor=2965 Product=5023 Version=0110
N: Name="Kortek Kortek Touch"
P: Phys=usb-0000:00:14.0-3.4/input2
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.4/3-3.4:1.2/0003:2965:5023.0006/input/input7
U: Uniq=S20131028
H: Handlers=mouse1 event7 js0
B: PROP=0
B: EV=1b
B: KEY=30000 0 0 0 0 0 0 0 0
B: ABS=3
B: MSC=10
Run Code Online (Sandbox Code Playgroud)
我想知道这条线S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.4/3-3.4:1.2/0003:2965:5023.0006/input/input7意味着什么.怎么看?路径中的数字是多少?