GVKun编程网logo

如何在Windows和Java下与USB设备通信?(java跟usb设备交互)

31

本文将带您了解关于如何在Windows和Java下与USB设备通信?的新内容,同时我们还将为您解释java跟usb设备交互的相关知识,另外,我们还将为您提供关于.net–以编程方式在Windows中重

本文将带您了解关于如何在Windows和Java下与USB设备通信?的新内容,同时我们还将为您解释java跟usb设备交互的相关知识,另外,我们还将为您提供关于.net – 以编程方式在Windows中重启USB设备、build立与USB设备的通信、c# – 获取有关Windows和NET中已连接USB设备的所有可用信息、Delphi 2009:如何在Vista下的Windows服务和桌面应用程序之间进行通信?的实用信息。

本文目录一览:

如何在Windows和Java下与USB设备通信?(java跟usb设备交互)

如何在Windows和Java下与USB设备通信?(java跟usb设备交互)

我想在Windows和Java下与USB设备通信,但是找不到一个很好的库来进行通信。我不希望用户必须安装任何额外的硬件或设备驱动程序才能使此工作正常进行。也就是说,我希望能够像其他Windows应用程序一样与USB交互。

我熟悉jUSB和JSR 80,但它们似乎都是无效项目(至少对于Windows)。

答案1

小编典典

不久前,我对此进行了大量研究,不幸的是,所有有用的免费USB + Windows +
Java项目均已失效。有商业的和昂贵的(不是每个开发人员39.99美元的价格,而是每个软件副本的价格!)JCommUSB库可能有用,尽管我没有经验。我们必须为USB驱动程序构建自己的自定义C包装程序,并通过JNI与它们通信。

.net – 以编程方式在Windows中重启USB设备

.net – 以编程方式在Windows中重启USB设备

我正在开发的一些软件需要USB设备(我作为SerialPort与USB-to-UART桥接器进行交互).

有时,在计算机从休眠状态重新启动后,设备未被检测到,我无法再通过其串行端口向设备写入或读取设备.必须具有对设备的读/写访问权限.

我不能依赖用户采取任何行动(物理或其他),所以我需要一种方法以编程方式重启设备.

我应该如何使用.NET框架以编程方式在Windows XP / Vista / 7中重新启动USB设备?

解决方法

您可以使用 WDK(Windows驱动程序工具包).提供了大量源代码示例,但期望陡峭的学习曲线.

Devcon是由MS开发的一个程序,用于演示目的,有时可以工作并做你想要的.但请注意,这是奇怪和狂野.无论如何,提供了源代码,所以如果你想搞乱设备驱动程序,你可以推出自己的“Devcon”代码.

从MS站点:

DevCon(Devcon.exe)是设备控制台,是一个显示的命令行工具
        有关设备的详细信息.使用DevCon,您可以搜索和
        从命令行操作设备. DevCon启用,禁用,安装,
        配置并删除本地计算机上的设备并显示详细信息
        有关本地和远程计算机上的设备的信息.
  

HTH!

build立与USB设备的通信

build立与USB设备的通信

我正在尝试与USB设备build立通信。 我有安装在Python中的libusb1和libusb以及为我正在与之通信的设备安装的驱动程序。 设备在设备pipe理器中显示为libusb-win32-设备。 我试图按照这个教程https://github.com/walac/pyusb/blob/master/docs/tutorial.rst我不知道我在做什么错。 在Windows上运行

import usb dev = usb.core.find(idvendor=0x0683,idProduct=0x4108) if dev is None: print 'Unable to find the usb device' dev.set_configuration()

我得到这个错误:

--------------------------------------------------------------------------- USBError Traceback (most recent call last) Y:All ProjectsLab EquipmentDataQpythonDI-4108DI_4108_SANDBox.py in <module>() 9 10 ---> 11 dev.set_configuration() 12 13 # get an endpoint instance C:Anaconda2libsite-packagesusbcore.pyc in set_configuration(self,configuration) 867 without arguments is enough to get the device ready. 868 """ --> 869 self._ctx.managed_set_configuration(self,configuration) 870 871 def get_active_configuration(self): C:Anaconda2libsite-packagesusbcore.pyc in wrapper(self,*args,**kwargs) 100 try: 101 self.lock.acquire() --> 102 return f(self,**kwargs) 103 finally: 104 self.lock.release() C:Anaconda2libsite-packagesusbcore.pyc in managed_set_configuration(self,device,config) 146 147 self.managed_open() --> 148 self.backend.set_configuration(self.handle,cfg.bConfigurationValue) 149 150 # cache the index instead of the object to avoid cyclic references C:Anaconda2libsite-packagesusbbackendlibusb1.pyc in set_configuration(self,dev_handle,config_value) 792 @methodtrace(_logger) 793 def set_configuration(self,config_value): --> 794 _check(self.lib.libusb_set_configuration(dev_handle.handle,config_value)) 795 796 @methodtrace(_logger) C:Anaconda2libsite-packagesusbbackendlibusb1.pyc in _check(ret) 593 raise NotImplementedError(_strerror(ret)) 594 else: --> 595 raise USBError(_strerror(ret),ret,_libusb_errno[ret]) 596 597 return ret USBError: [Errno 2] Entity not found

我得到了关于我的设备的信息:

> DEVICE ID 0683:4108 on Bus 002 Address 005 ================= bLength > : 0x12 (18 bytes) bDescriptorType : 0x1 Device bcdUSB > : 0x200 USB 2.0 bDeviceClass : 0xff vendor-specific > bDeviceSubClass : 0x0 bDeviceProtocol : 0x0 > bMaxPacketSize0 : 0x40 (64 bytes) idvendor : > 0x0683 idProduct : 0x4108 bcdDevice : > 0x100 Device 1.0 iManufacturer : 0x1 Error Accessing > String iProduct : 0x2 Error Accessing String > iSerialNumber : 0x3 Error Accessing String > bNumConfigurations : 0x1 CONfigURATION 1: 500 mA > ================================== bLength : 0x9 (9 bytes) bDescriptorType : 0x2 Configuration wTotalLength > : 0x20 (32 bytes) bNumInterfaces : 0x1 > bConfigurationValue : 0x1 iConfiguration : 0x5 Error > Accessing String bmAttributes : 0xc0 Self Powered > bMaxPower : 0xfa (500 mA) > INTERFACE 0: vendor Specific =========================== > bLength : 0x9 (9 bytes) > bDescriptorType : 0x4 Interface > bInterfaceNumber : 0x0 > bAlternateSetting : 0x0 > bNumEndpoints : 0x2 > bInterfaceClass : 0xff vendor Specific > bInterfaceSubClass : 0x0 > bInterfaceProtocol : 0x0 > iInterface : 0x4 Error Accessing String > ENDPOINT 0x81: Bulk IN =============================== > bLength : 0x7 (7 bytes) > bDescriptorType : 0x5 Endpoint > bEndpointAddress : 0x81 IN > bmAttributes : 0x2 Bulk > wMaxPacketSize : 0x40 (64 bytes) > bInterval : 0x0 > ENDPOINT 0x1: Bulk OUT =============================== > bLength : 0x7 (7 bytes) > bDescriptorType : 0x5 Endpoint > bEndpointAddress : 0x1 OUT > bmAttributes : 0x2 Bulk > wMaxPacketSize : 0x40 (64 bytes) > bInterval : 0x0

所以,最后的问题是:我如何获得在Windows中的权利? 在Linux中,你可以通过udev来完成。 如何解决这个问题在Windows中?

如何解决运行Node.js的RaspBerry Pi(Debian)上的LIBUSB_ERROR_BUSY

Linux C ++ LibUSB在USB HUB中写入寄存器

应用程序在使用默认HID驱动程序时会忽略USB设备的传入数据包

bluegiga蓝牙LED USBencryption狗固件更新工具无法正常工作

如何检测多个USB端口和使用python从USB读取数据

Libusb以及如何在Ubuntu中使用它的软件包

libnfc:SCL3711在Windows 7上找不到“findNFC设备”

libusb-win32:自动安装驱动程序filter

`libusb_attach_kernel_driver`不工作

如何在linux中获取usb的urb信息

c# – 获取有关Windows和NET中已连接USB设备的所有可用信息

c# – 获取有关Windows和NET中已连接USB设备的所有可用信息

我已经在我的代码中实现了 SO question的解决方案,但我正在寻找来自连接的USB设备的更多信息.

我注意到在我的设备管理器中提供了更多的信息.

enter image description here

我特别想知道这些设备的制造商.

我不确定如何确定从SO question中看到的GetPropertyValue方法使用中可用的其他属性.我在最后尝试了一些关键字,但它们都报告错误,所以我认为这不是可用的属性.

知道如何获取更多只有deviceid,Pnpdeviceid和Description的信息吗?

编辑:对于任何想知道这里的人来说,我会得到完整的属性列表和值.没有任何设备可以提供比我所知道的更多或更少(可能是转换为字符串?).

Availability: 
                    Caption: USB Root Hub
                  ClassCode: 
     ConfigManagerErrorCode: 0
    ConfigManagerUserConfig: False
          CreationClassName: Win32_USBHub
   CurrentAlternateSettings: 
         CurrentConfigValue: 
                Description: USB Root Hub
                   deviceid: USB\ROOT_HUB20\########
               ErrorCleared: 
           ErrorDescription: 
               GangSwitched: 
                InstallDate: 
              LastErrorCode: 
                       Name: USB Root Hub
            NumberOfConfigs: 
              NumberOfPorts: 
                PNPdeviceid: USB\ROOT_HUB20\4&\########&0
PowerManagementCapabilities: 
   PowerManagementSupported: 
               ProtocolCode: 
                     Status: OK
                 StatusInfo: 
               SubclassCode: 
    SystemCreationClassName: Win32_ComputerSystem
                 SystemName: ASystemName
                 USBVersion:

并且编辑了来自链接的SO答案的代码,但具有所有属性.

public class USBDeviceInfo
{
    public String Availability { get; set; }
    public String Caption { get; set; }
    public String ClassCode { get; set; }
    public UInt32 ConfigManagerErrorCode { get; set; }
    public Boolean ConfigManagerUserConfig { get; set; }
    public String CreationClassName { get; set; }
    public String CurrentAlternateSettings { get; set; }
    public String CurrentConfigValue { get; set; }
    public String Description { get; set; }
    public String deviceid { get; set; }
    public String ErrorCleared { get; set; }
    public String ErrorDescription { get; set; }
    public String GangSwitched { get; set; }
    public String InstallDate { get; set; }
    public String LastErrorCode { get; set; }
    public String Name { get; set; }
    public String NumberOfConfigs { get; set; }
    public String NumberOfPorts { get; set; }
    public String PNPdeviceid { get; set; }
    public String PowerManagementCapabilities { get; set; }
    public String PowerManagementSupported { get; set; }
    public String ProtocolCode { get; set; }
    public String Status { get; set; }
    public String StatusInfo { get; set; }
    public String SubclassCode { get; set; }
    public String SystemCreationClassName { get; set; }
    public String SystemName { get; set; }
    public String USBVersion { get; set; }
}

public static List<USBDeviceInfo> GetUSBDevices()
{
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub");
    ManagementObjectCollection collection = searcher.Get();

    List<USBDeviceInfo> devices = new List<USBDeviceInfo>();
    foreach (var device in collection)
    {
        USBDeviceInfo deviceInfo = new USBDeviceInfo();
        deviceInfo.Availability = (String)device.GetPropertyValue("Availability");
        deviceInfo.Caption = (String)device.GetPropertyValue("Caption");
        deviceInfo.ClassCode = (String)device.GetPropertyValue("ClassCode");
        deviceInfo.ConfigManagerErrorCode = (UInt32)device.GetPropertyValue("ConfigManagerErrorCode");
        deviceInfo.ConfigManagerUserConfig = (Boolean)device.GetPropertyValue("ConfigManagerUserConfig");
        deviceInfo.CreationClassName = (String)device.GetPropertyValue("CreationClassName");
        deviceInfo.CurrentAlternateSettings = (String)device.GetPropertyValue("CurrentAlternateSettings");
        deviceInfo.CurrentConfigValue = (String)device.GetPropertyValue("CurrentConfigValue");
        deviceInfo.Description = (String)device.GetPropertyValue("Description");
        deviceInfo.deviceid = (String)device.GetPropertyValue("deviceid");
        deviceInfo.ErrorCleared = (String)device.GetPropertyValue("ErrorCleared");
        deviceInfo.ErrorDescription = (String)device.GetPropertyValue("ErrorDescription");
        deviceInfo.GangSwitched = (String)device.GetPropertyValue("GangSwitched");
        deviceInfo.InstallDate = (String)device.GetPropertyValue("InstallDate");
        deviceInfo.LastErrorCode = (String)device.GetPropertyValue("LastErrorCode");
        deviceInfo.Name = (String)device.GetPropertyValue("Name");
        deviceInfo.NumberOfConfigs = (String)device.GetPropertyValue("NumberOfConfigs");
        deviceInfo.NumberOfPorts = (String)device.GetPropertyValue("NumberOfPorts");
        deviceInfo.PNPdeviceid = (String)device.GetPropertyValue("PNPdeviceid");
        deviceInfo.PowerManagementCapabilities = (String)device.GetPropertyValue("PowerManagementCapabilities");
        deviceInfo.PowerManagementSupported = (String)device.GetPropertyValue("PowerManagementSupported");
        deviceInfo.ProtocolCode = (String)device.GetPropertyValue("ProtocolCode");
        deviceInfo.Status = (String)device.GetPropertyValue("Status");
        deviceInfo.StatusInfo = (String)device.GetPropertyValue("StatusInfo");
        deviceInfo.SubclassCode = (String)device.GetPropertyValue("SubclassCode");
        deviceInfo.SystemCreationClassName = (String)device.GetPropertyValue("SystemCreationClassName");
        deviceInfo.SystemName = (String)device.GetPropertyValue("SystemName");
        deviceInfo.USBVersion = (String)device.GetPropertyValue("USBVersion");
        devices.Add(deviceInfo);
    }

    collection.dispose();
    searcher.dispose();
    return devices;
}

解决方法

Properties集合属性将包含您可以访问的所有属性.

https://msdn.microsoft.com/en-us/library/system.management.managementbaseobject.properties(v=vs.110).aspx

Delphi 2009:如何在Vista下的Windows服务和桌面应用程序之间进行通信?

Delphi 2009:如何在Vista下的Windows服务和桌面应用程序之间进行通信?

桌面应用程序如何与Vista / Windows2008 / Windows7下的Windows服务进行通信?应用程序需要向服务发送小字符串并接收字符串响应.两者都是用Delphi 2009编写的.(请提供示例代码)

解决方法

要走的路是 named pipes,你可能要看看不同的 Integrity levels之间的沟通.

This article探讨了如何在Vista中执行此操作.虽然它是用c编写的,但它只是基本的Windows API调用,因此它应该足够快地转换为Delphi.

如果您想要搜索有关此主题的更多信息,此通信称为进程间通信,但更好的搜索术语是IPC.

我们今天的关于如何在Windows和Java下与USB设备通信?java跟usb设备交互的分享已经告一段落,感谢您的关注,如果您想了解更多关于.net – 以编程方式在Windows中重启USB设备、build立与USB设备的通信、c# – 获取有关Windows和NET中已连接USB设备的所有可用信息、Delphi 2009:如何在Vista下的Windows服务和桌面应用程序之间进行通信?的相关信息,请在本站查询。

本文标签: