PDA

View Full Version : read from USB serial port of raspberry pi with serialGetchar()



isan
31st July 2018, 17:03
I use wiringSerial.h library to read from USB port of raspi in thread

void MyThread::run()
{

qDebug("Thread id inside run %d",(int)QThread::currentThreadId());

int fd ,value;

if ((fd = serialOpen ("/dev/ttyACM0",230400)) < 0)
{
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
}

while (serialDataAvail(fd)>-2)
{

value=serialGetchar (fd) ;

msleep(1);
emit signalValueUpdated(value);
}
serialClose(fd);

}

the data that received is a number between -1 to 255
when use value in emit signal Value Updated(value); or print it
the value is not the same value that send to raspberry pi, what should I do?

Lesiok
2nd August 2018, 10:14
Show serialDataAvail() and serialGetChar().