Find the answer to your Linux question:
Results 1 to 3 of 3
New to programming serial comm over usb and cannot find what I am looking for through google yet. When doing I/O multiplexing using a select() call, how do you detect ...
  1. #1
    Just Joined!
    Join Date
    Nov 2007
    Posts
    1

    Serial comm over USB

    New to programming serial comm over usb and cannot find what I am looking for through google yet.

    When doing I/O multiplexing using a select() call, how do you detect when a USB cable is unplugged, as I don't see select returning an error.

  2. #2
    Just Joined!
    Join Date
    Nov 2007
    Location
    Murder Mitten.
    Posts
    57
    If you mean a Serial to USB cable/adapter, for use with serial devices when the computer has no serial port... I believe the that when its plugged in (atleast on my computer) it creates a /dev/ttyUSB0 ... and when I unplug it, it removes it. Also in the /var/debug log's it informs you when the cable is connected/disconnected.

  3. #3
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    edclancy7715, somehow I don't see Christoph15 checking for the existence of the device which he has already open()ed, or examining the content of a log file every time he attempts an I/O. Once he has the device open()ed, he should be able to rely on status bits through the file descriptor to get the status he needs.

    And I haven't done any USB programming, but until someone shows up in this thread who has, maybe my experience might prove instructive. When I do network programming, I do it all asynchronously and through select(). When a network error happens, select() doesn't give me any error indication. It blinks innocently and indicates that the network file descriptor has data ready for me to read. When I do that, the read comes back -1, meaning an error, and I look at errno to discover the error. Or else the read comes back 0, meaning end of file, meaning the connection has been closed from the other end.

    Maybe you should be doing something similar with USB, Christoph15. Or maybe you should also enable select()'s exception file descriptor mask, although I've never had to do that for network programming.

    Hope this helps in some small way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...