serialport / bindings-cpp

The C++ bindings for the node serialport project.
MIT License
22 stars 42 forks source link

fix out of memory crush, when there are no data to read on unix systems #175

Open Kiliar opened 3 months ago

Kiliar commented 3 months ago

You can improve pulling logic on unix systems, by changing recursion to endless loop with some delay.

skadisch commented 3 months ago

This will unfortunately not solve my problem, which is USB serial port disconnect. In this case, read will return 0, not an error. So this loop will run endlessly.

Kiliar commented 3 months ago

Oh.... so you have an issue when serial connection is up, but no data can be send or received using this lib? I had a similar issue and found a workaround by calling simple python script that will initialize serial port & send some data. It helps me most of the time, maybe it will help you to find proper solution.

import sys
import serial
import crc8

serial = serial.Serial()
serial.port = sys.argv[1]
serial.baudrate = int(sys.argv[2])

serial.open()

msg = bytearray.fromhex("0101")

hash = crc8.crc8()
hash.update(msg)
c = hash.digest()
serial.write(msg)
serial.write(c)