views:

13

answers:

0

I've run into a problem where the open function never returns when I try to open a serial port. It doesn't happen all the time, and the problem disappears for a while if I unplug my USB to serial adapter and plug it back in. My code looks like this:

fileDescriptor = open(bsdPath, O_RDWR | O_NOCTTY);

where bsdPath is /dev/cu.KeySerial1 . I've tried adding the O_NONBLOCK option to the open command, but it still hangs.

Of course I'd like to understand why this is happening. My belief is that whatever the problem, with O_NONBLOCK specified, open should return no matter what even if it was unable to open the port. If it's unable to open the port, fileDescriptor should be -1 and errno should be set (I check for this immediately after the call to open). Of course, this isn't happening. Is my assumption incorrect? Is there some known reason for open() to never return even with O_NONBLOCK specified when an error is encountered?