mattjlewis / diozero

Java Device I/O library that is portable across Single Board Computers and microcontrollers. Tested with Raspberry Pi, Odroid C2, BeagleBone Black, Next Thing CHIP, Asus Tinker Board and Arduinos / Pico. Supports GPIO, I2C, SPI as well as Serial communication. Also known to work with Udoo Quad.
https://www.diozero.com
MIT License
261 stars 59 forks source link

closing serial port causes close eventloop and shutdown #172

Open dafik opened 1 year ago

dafik commented 1 year ago

I have several gpio listeners when call serial.close() gpio listeners are closed INFO com.diozero.internal.provider.builtin.gpio.GpioChip::eventLoop - Event loop finished

probably by this : raise(SIGINT); in native utils https://github.com/mattjlewis/diozero/blob/main/system-utils-native/src/main/c/com_diozero_internal_provider_builtin_serial_NativeSerialDevice.c#L381

having serial port open all time causes 100% cpu utilisation.

mattjlewis commented 1 year ago

Will take a look.

dafik commented 3 months ago

any progess on this ?

mattjlewis commented 3 months ago

Apologies - not a simple fix - the current implementation settled on a blocking read to replicate behaviour similar to Java I/O. I added the SIGINT to interrupt any remaining blocking reads but clearly didn't fully think through the implications. I suspect I will need to switch to an event based read model under the hood to maintain the same exposed API in SerialDevice which will be a bit more complicated.