简体   繁体   English

使用java将字节从PC发送到USB通信端口

[英]Send byte from PC to USB communication port using java

Can I send a byte from PC to usb communication port via java program? 我可以通过Java程序从PC向USB通信端口发送一个字节吗? if yes .Is there any sample code that can help in this issue?? 如果是,是否有任何示例代码可以帮助解决此问题?

I'm looking for sample codes or good tutorials 我正在寻找示例代码或好的教程

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. 如果您使用的是USB到串口的转换器(听起来很像),则OS驱动程序软件会为应用程序提供一个串行接口。

I think what you need to look at is the JavaComms API - http://www.oracle.com/technetwork/java/index-jsp-141752.html . 我认为您需要查看的是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/ ? 此页面是否完全有帮助-http://alumni.media.mit.edu/~benres/simpleserial/

When using a USB-Serial adapter the USB part can (usually) be ignored and instead you should just focus on the serial part. 使用USB串行适配器时,可以(通常)忽略USB部件,而应该只关注串行部件。 The USB adapter drivers will give you a virtual serial port to use as any other serial port. USB适配器驱动程序将为您提供一个虚拟串行端口,以用作任何其他串行端口。

For using a serial port with Java see Java Communications API or Serialio 对于使用Java的串行端口,请参阅Java Communications APISerialio

You have not specified what kind of USB communication you want, so this is going to be a bit generic. 您尚未指定所需的USB通信类型,因此这有点通用。

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. 如果您的设备将自己标识为USB CDC,则系统可能已经加载了驱动程序,并使您能够将其作为串行端口进行访问。 Similar is true if the dice identifies itself as a HID (Human Interaction Device) keyboard, mouse etc. 如果骰子将自己标识为HID(人类交互设备)键盘,鼠标等,则情况类似。

If you have your own type of device, then you can use javax.usb from linux (might be a port for windows). 如果您拥有自己的设备类型,则可以从Linux使用javax.usb(可能是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. 您需要从供应商/设备ID识别设备,可能需要配置端点,设备(如果要控制,批量或同步数据),创建数据包,使用字节填充数据然后进行传输。 Javax.usb has some example code. Javax.usb有一些示例代码。

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. 为简单起见,我建议你的设备是CDC(代码可用,检查谷歌),它会将自己标识为一个串口,你不需要在通信时处理USB的任何复杂性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM