If I send the following string to the rpi

echo "#q10"  > /dev/ttyUSB0

Why does the whole string not get read each time its sent? This is the app output

See code below

The code is as follows. I am using the serial wiring library from Gordons project

#include <stdio.h>
#include <wiringSerial.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

int fd;

struct obj_Properties
char *one;
char *two;
char *three;
char *four;

int main()
if ((fd = serialOpen("/dev/ttyUSB0", 9600)) < 0)
 return 1;

while (serialDataAvail (fd))
 struct obj_Properties prop;
 prop.one = serialGetchar(fd);
 prop.two = serialGetchar(fd);
 prop.three = serialGetchar(fd);
 prop.four = serialGetchar(fd);
 printf ("%c %c %c %c\n", prop.one, prop.two, prop.three, prop.four);

 fflush (stdout) ;


1 Answer 1


As soon as the first byte is available you read four bytes. The first byte being ready does not imply all four bytes (plus line feed) have been received.

  • I added an extra char in the code and one less in the string and it is working. It seems obvious now but even though I used differing string sizes I never tested for 2 extra chars - thanks.. Aug 23, 2014 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.