简体   繁体   English

Linux中通过USB的串行端口意外更改

[英]Serial port over USB in Linux changes unexpectedly

I have a problem with a custom electronic device communicating with a workstation via RS232 on USB interface. 我有一个自定义电子设备通过USB接口上的RS232与工作站通信的问题。 As soon the device is connected, it receive, says, the address /dev/ttyUSB0 , after some (random ) time of sending receive commands, the device appear to hang. 设备连接后,即会收到地址/dev/ttyUSB0 ,在发送接收命令一段时间(随机)后,设备似乎挂起。 By looking at the device events ( dmesg ), we found the following error: 通过查看设备事件( dmesg ),我们发现了以下错误:

ftdi_sio ttyUSB0: failed to get modem status: -32
...
USB disconnect, device number 29
[66208.321174] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[66208.497613] usb 1-1.5: new full-speed USB device number 30 using ehci-pci
[66208.589052] usb 1-1.5: New USB device found, idVendor=0403, idProduct=6001
[66208.589055] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3

So apparently the system notices a device disconnection/reconnection, thus, the device is mounted to another port, ie / dev/ttyUSB1 , causing further communication failure. 因此,显然,系统注意到设备断开/重新连接,因此,该设备安装到另一个端口,即/ dev/ttyUSB1 ,导致进一步的通信失败。 Creating a test bed changes the behavior: error seems to appear less frequently, while using a complete application the error appears recurrently. 创建测试平台会改变行为:错误似乎很少出现,而在使用完整的应用程序时,错误会反复出现。 Application uses jSSC-2.8.0 to communicate with the serial port. 应用程序使用jSSC-2.8.0与串行端口通信。 The whole application is written in java 8, and uses the Restle library to issue some REST requests to some web services. 整个应用程序都是用Java 8编写的,并使用Restle库向一些Web服务发出一些REST请求。 What can cause these strange behavior? 什么会导致这些奇怪的行为?

ADDED as per @DarkFalcon comment below, test bed polls the device usually faster than the real app: this could possibly explain why test perfors better than the other. 通常添加按照下面,试验台民调@DarkFalcon评论设备比真正的应用程序速度更快:这可能可以解释为什么比其他测试perfors更好。

The problem was due to power management: the box decided the device is idle and after a certain time it removes the power. 问题是由于电源管理造成的:盒子判定设备处于空闲状态,经过一段时间后,设备断电。 The device then apparently comes alive again in almost 0 time. 然后,该设备显然在将近0次后又恢复了生命。 So the strange behavior 所以奇怪的行为

This error is printed by driver due to broken pipe. 由于管道破裂,驱动程序会打印此错误。 See ftdi_get_modem_status() in driver file drivers/usb/serial/ftdi_sio.c . 请参阅驱动程序文件drivers/usb/serial/ftdi_sio.c ftdi_get_modem_status()

You may try other libraries like 'serial communication manager', purejavacom etc. And see if problem persist. 您可以尝试使用其他库,例如“串行通信管理器”,purejavacom等。然后查看问题是否仍然存在。 I feel, first identify who is actually creating problem; 我认为,首先要确定是谁真正在制造问题; your app, serial library or driver. 您的应用,串行库或驱动程序。 Then accordingly move forward. 然后相应地前进。 Driver has been tested and probably either library or app might have something we need to rectify. 驱动程序已经过测试,可能库或应用程序都有一些我们需要纠正的问题。

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

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