How to user the serial read byte -example [closed]
Can anyone give me an example to use the serial pkg to read byte from serial port to a buffer.
https://github.com/wjwwood/serial
size_t read (uint8_t *buffer, size_t size) size_t read (std::vector< uint8_t > &buffer, size_t size=1)
I tried the method but failed with the following exception.
terminate called after throwing an instance of 'serial::SerialException' what(): SerialException device reports readiness to read but returned no data (device disconnected?) failed. Aborted (core dumped)
size_t size= 1;
uint8_t * buffer = new uint8_t;
size_t read_byte;
if(ser.available())
{
read_byte = ser.read(buffer, size);
}
@NEngelhard: the
serial
library was written by @William, and is used in a nr of ROS packages. Why did you close this question as off-topic or not relevant?With this argument, we would also need to allow OpenCV questions as it is often used in ROS-Nodes. The question itself has nothing to do with ROS. I think this question is exactlty "general debugging/programming questions not specific to ROS".
I'm fine with either. It's ok to have the question posted on https://github.com/wjwwood/serial/issues instead. @Rickardo Leos this error most often happens when a usb-serial device is unplugged while you're trying to read from the device. I can't give you more specific help than that I'm afraid.