0

I develop a linux application, which works with ttyUSB*/ttyACM* devices. Now I have a task:
I have to find a way, how to restore communication with device, when connection is temporary lost. Now I see such a behaviour: if port is opened in the app, and device is re-pluged at this moment, the device's name changes, and app can not complete current operation. So, I wrote udev rule to add symlink to device, and the rule works. But app crashes all the same. The reason is that device changes it's tty (ttyACM0->tyyACM1) after re-plugging, and symlink does not help, because file descriptor becames wrong.

Does anybody know a way, how can I replug device without need to restart my app? Are there any settings in Linux to allow device to re-plug to the same tty even if it was opened in the application in the moment of disconnection?

  • 2
    If you have an open file descriptor associated with the device, and you unplug/replug it, you'd have to re-open the device. That doesn't mean you have to restart the program, per se, the program itself could handle that case. – Andy Dalton Mar 13 '18 at 14:56
  • Sad, but true. I'm afraid, you are right =) But, is there at least a way to re-plug device to the same ttyUSB* (not to the same alias)? – Олег Сидоров Mar 13 '18 at 15:21
  • 2
    Can your udev rule uniquely identify the device? Will there ever be only one such device connected at a time? If so, I think you could make your udev rule always update the symlink. – Andy Dalton Mar 13 '18 at 16:09
0

Finally, I came to a conclusion, that a manual management of open/close port descriptor is the only solution to the problem. Also, some moments may affect to the device's behaviour:

  • USB timeout settings
  • modemmanager presence
  • interval between plug and unplug the device

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.