I have a problem with the serial module.
First at all I have a LOT of doubts about set up the UART module with MQX. For example:
serial_fd = fopen(BSP_DEFAULT_IO_CHANNEL, 0);
baud_rate = 9600;
flags=IO_SERIAL_NON_BLOCKING;
ioctl(serial_fd, IO_IOCTL_SERIAL_SET_BAUD, &baud_rate);
ioctl(serial_fd, IO_IOCTL_SERIAL_SET_FLAGS, &flags);
Then for reception I have to do the next:
char receive[248];
if (fstatus(serial_fd)) {
read(serial_fd, &receive, 248);
}
Here my doubt with the flag =IO_SERIAL_NON_BLOCKING
the documentation saids:
"In this mode the _io_read() function doesn’t
wait till the receive buffer is full, but it
immediately returns received characters
and number of received characters."
I've declared char receive[248] with a size of 248 bytes because it's the maximun number of data that i can receive, but my messages have diffrentes size's. I mean in some moment I can receive "FF 00 09 01 01 14 E8" but in other moment i can receive
"FF C8 65 00 00 00 0E 02 EA 00 0E 16 72 00 0D EF 62 00 0D D0 22 00 0E 18 66 00 0D ED 6E 00 0E 04 DE 00 0E 22 2A 00 0E 0E A2 00 0D D2 16 00 0D F7 32 00 0D CE 2E 00 0D E7 92 00 0D FD 0E 00 0E 24 1E 00 0E 10 96 00 0D F1 56 00 0E 1E 42 00 0D E5 9E 00 0D FB 1A 00 0E 14 7E 00 0D CC 3A 00 0D FF 02 00 0D E1 B6 00 0D CA 46 00 0D E9 86 00 0D D4 0A 00 0E 08 C6 00 0E 26 12 00 0E 12 8A 00 0D D7 F2 00 0E 0C AE 00 0D DF C2 00 0E 20 36 00 0E 0A BA 00 0D F5 3E 00 0D DD CE 00 0E 1C 4E 00 0D F9 26 00 0D E3 AA 00 0D C8 52 00 0D DB DA 00 0E 06 D2 00 0E 1A 5A 00 0D F3 4A 00 0D C6 5E 00 0D D9 E6 00 0E 00 F6 00 0D D5 FE 00 0D EB 7A 12 02"
When i call read(serial_fd, &receive, 248); I have 2 problems:
1. When i set the flag IO_SERIAL_NON_BLOCKING I only receipt the first byte
2. When I dont set the flag IO_SERIAL_NON_BLOCKING the read function waits till the receive buffer is full. But it doesnt work for me. i need to receive a variable number of bytes and save the data into a variable.
If anyone can help me I'll be very grateful