使用 USB 串行适配器时,USB 部分(通常)可以被忽略,而您应该只关注串行部分。 USB 适配器驱动程序将为您提供一个虚拟串行端口,可用作任何其他串行端口。
有关通过 Java 使用串行端口的信息,请参阅 Java Communications API 或 < a href="http://serialio.com/products/serialport/serialport.php" rel="nofollow">Serialio
When using a USB-Serial adapter the USB part can (usually) be ignored and instead you should just focus on the serial part. The USB adapter drivers will give you a virtual serial port to use as any other serial port.
如果您的设备将自身标识为 USB CDC,则您的系统可能已经加载驱动程序并允许您将其作为串行端口进行访问。如果骰子将自己标识为 HID(人类交互设备)键盘、鼠标等,情况也是如此。
如果您有自己的设备类型,那么您可以使用 Linux 中的 javax.usb(可能是 Windows 的端口)。您需要根据供应商/设备 ID 识别您的设备,如果需要控制、批量或同步数据,可能需要配置您的端点、设备,创建数据包,用您的字节填充它,然后传输它。 Javax.usb 有一些示例代码。
为简单起见,我建议您的设备是 CDC(可用代码,请检查 google),它会将自己识别为串行端口,并且您在通信时无需处理 USB 的任何复杂性。
You have not specified what kind of USB communication you want, so this is going to be a bit generic.
If your device identifies itself as a USB CDC you system probably already loads a driver and enables you to access it as a serial port. Similar is true if the dice identifies itself as a HID (Human Interaction Device) keyboard, mouse etc.
If you have your own type of device, then you can use javax.usb from linux (might be a port for windows). You need to identify your device from the vendor/device id, possibly configure your endpoints, device if you want control, bulk or isochronous data, create the packet, populate it with your byte(s) and then transfer it. Javax.usb has some example code.
For simplicity I'd recommend your device to be a CDC (code available, check google) and it will identify itself as a serial port and you do not need to handle any of the complexity of USB when communicating.
发布评论
评论(3)
如果您使用的是 USB 转串口转换器(顾名思义),那么操作系统驱动程序软件就会为应用程序提供一个串行接口。
我认为您需要查看的是 JavaComms API - http:// www.oracle.com/technetwork/java/index-jsp-141752.html。
此页面有帮助吗 - http://alumni.media.mit.edu/~benres /simpleserial/ ?
If you are using a USB-to-serial converter (which is what it sounds like) then the OS driver software presents a serial interface to applications.
I think what you need to look at is the JavaComms API - http://www.oracle.com/technetwork/java/index-jsp-141752.html.
Does this page help at all - http://alumni.media.mit.edu/~benres/simpleserial/ ?
使用 USB 串行适配器时,USB 部分(通常)可以被忽略,而您应该只关注串行部分。 USB 适配器驱动程序将为您提供一个虚拟串行端口,可用作任何其他串行端口。
有关通过 Java 使用串行端口的信息,请参阅 Java Communications API 或 < a href="http://serialio.com/products/serialport/serialport.php" rel="nofollow">Serialio
When using a USB-Serial adapter the USB part can (usually) be ignored and instead you should just focus on the serial part. The USB adapter drivers will give you a virtual serial port to use as any other serial port.
For using a serial port with Java see Java Communications API or Serialio
您还没有指定您想要哪种类型的 USB 通信,因此这会有点通用。
如果您的设备将自身标识为 USB CDC,则您的系统可能已经加载驱动程序并允许您将其作为串行端口进行访问。如果骰子将自己标识为 HID(人类交互设备)键盘、鼠标等,情况也是如此。
如果您有自己的设备类型,那么您可以使用 Linux 中的 javax.usb(可能是 Windows 的端口)。您需要根据供应商/设备 ID 识别您的设备,如果需要控制、批量或同步数据,可能需要配置您的端点、设备,创建数据包,用您的字节填充它,然后传输它。 Javax.usb 有一些示例代码。
为简单起见,我建议您的设备是 CDC(可用代码,请检查 google),它会将自己识别为串行端口,并且您在通信时无需处理 USB 的任何复杂性。
You have not specified what kind of USB communication you want, so this is going to be a bit generic.
If your device identifies itself as a USB CDC you system probably already loads a driver and enables you to access it as a serial port. Similar is true if the dice identifies itself as a HID (Human Interaction Device) keyboard, mouse etc.
If you have your own type of device, then you can use javax.usb from linux (might be a port for windows). You need to identify your device from the vendor/device id, possibly configure your endpoints, device if you want control, bulk or isochronous data, create the packet, populate it with your byte(s) and then transfer it. Javax.usb has some example code.
For simplicity I'd recommend your device to be a CDC (code available, check google) and it will identify itself as a serial port and you do not need to handle any of the complexity of USB when communicating.