How to user the serial read byte -example [closed]

asked 2016-11-06 07:49:09 -0600

Rickardo Leos gravatar image

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);
}
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant. Please see http://wiki.ros.org/Support for more details. by NEngelhard
close date 2016-11-06 09:11:30.708078

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?

gvdhoorn gravatar image gvdhoorn  ( 2016-11-06 09:56:59 -0600 )edit

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".

NEngelhard gravatar image NEngelhard  ( 2016-11-06 10:26:55 -0600 )edit

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.

William gravatar image William  ( 2016-11-06 16:17:00 -0600 )edit