I'm working in c programming language under Linux, trying to create a communication application with serial port. The program is sending data to a serial port and reading received data from a microcontroller. The received data could reach any number of bytes between 10 and 64 but no more and no less. I use the following code to read and write data:
unsigned char send_bytes[] = { 0x1, 0x6, 0x2, 0xAA, 0x2, 0x3, 0xB8, 0x4 };
int w = write(fd, send_bytes, sizeof(send_bytes)); // send
char buffer[64];
int r = read(fd, buffer, sizeof(buffer)); //read data
My problem is that r never gets more than 8 bytes of data. Does anyone know why is this the case?
Thanks in advance.
int read, Use different name for function and variable. Don't mix them. - Don't You Worry Childreadfunctions and see what they return. - Don't You Worry Childopen()and initialization of the serial port. Also, performing syscalls in the variable declarations in not good practice. - sawdust