digidotcom / xbee_ansic_library

A collection of portable ANSI C code for communicating with Digi International's XBee wireless radio modules in API mode.
204 stars 116 forks source link

Suggestion to the library when detecting whether device is running or not. #15

Closed jiandong1997 closed 6 years ago

jiandong1997 commented 6 years ago

in the function xbee_ser_read, if the result of read is zero 0 when bufsize isn't 0, it means the device is not readable. but as the the function doesn't show the difference between EAGAIN and ended fd, both of cases return 0. this doesn't give external callers, such as wpan_tick, a chance to know if the device is removed. so I suggest to add some state/flag to indicate if the serial port is readable or not.

tomlogic commented 6 years ago

Which platform is this? POSIX? The library was originally written for embedded platforms with hard-wired interfaces. On Win32, it should return -EIO if there's an error reading from the port -- perhaps we could return something similar on the POSIX platform?

jiandong1997 commented 6 years ago

Yes. it is POSIX. it will be great that code could return something similar on POSIX platform which can be checked by application code using the C library.

tomlogic commented 4 years ago

Revisiting this because I recently worked on the POSIX serial driver. I don't think I fully understood your original bug report, but I have pushed commit c8b0d34a03 with changes to pass xbee_ser_read() errors up through xbee_dev_tick() (and wpan_tick()) so you can know when the serial port goes away.