How to user the serial read byte -example
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
sizet read (uint8t *buffer, sizet size) sizet read (std::vector< uint8t > &buffer, sizet 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);
}
Asked by Rickardo Leos on 2016-11-06 08:49:09 UTC
Comments
@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?Asked by gvdhoorn on 2016-11-06 10:56:59 UTC
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".
Asked by NEngelhard on 2016-11-06 11:26:55 UTC
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.
Asked by William on 2016-11-06 17:17:00 UTC