c++ - Receiving information from serial port in while loop -


i'm reading information serial port using code:

struct termios tio; memset(&tio, 0, sizeof(tio));  // open serial port in mode `8n1', non-blocking tio.c_cflag = cs8 | cread | clocal; tio.c_cc[vmin] = 1; tio.c_cc[vtime] = 10;  int fd = open("/dev/ttyacm1", o_rdonly);  cfsetospeed(&tio, b9600); cfsetispeed(&tio, b9600); tcsetattr(fd, tcsanow, &tio); unsigned char byte = '0';  // check input arduino while (!quit) {     keyboardinput(quit);     read(fd, &byte, 1);      if ((byte == '1' || quit)     {         oldbytedoor = '1';         break;     } } 

where keyboardinput(quit) sets quit true when close button of window pressed.

if nothing in serial port gets stuck @ read(fd, &byte, 1) forever.

how can prevent this?

thanks


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -