0

Like the question suggests, I would like to know if there is a way to increase my VMIN with serial programming. I am using a USB device that opens a Virtual Serial Port as an endpoint in Linux. The device will send a variable size message between 7 and 2047 bytes. When I try to program my port in C++, I am getting an overflow on my VMIN value. My code is as follows

portSettings.c_lflag &= ~(ICANON);
portSettings.c_lflag &= ~(ECHO | ECHOE);
portSettings.c_oflag &= ~(ONLCR);
portSettings.c_cc[VMIN] = 2047;
portSettings.c_cc[VTIME] = 10;
tcsetattr(fd, TCSANOW, &portSettings);

I get an "error: unsigned conversion from 'int' to 'cc_t' {aka 'unsigned char'} changes value from '2047' to '255' [Werror=overflow].

Since I don't know how large the incoming message will be, I put the 1 second VTIME and, if it short, then I will get whatever is there, otherwise, I would expect that my max would come in within time with a 115200 baud rate.

Any suggestions?

sawdust
  • 16,103
  • 3
  • 40
  • 50
MamaShark
  • 19
  • 2
  • 1
    As the erorr states, `portSettings.c_cc[VMIN]` is an `unsigned char` which has a max value of `255` on machines with an 8 bit byte. – NathanOliver Apr 17 '23 at 20:39
  • Is there another setting for VMIN that will allow for larger values? – MamaShark Apr 17 '23 at 21:00
  • No, there is no alternate VMIN. You could look into a line discipline. But it seems like you're trying to use the **read()** syscall to perform message alignment for your program. That's short-sighted, and will cause your program to be fallible, the opposite of robust. "*My code is as follows ...*" -- That's far from being complete or sufficient. – sawdust Apr 18 '23 at 03:49

0 Answers0