I have read many questions and answers but didn't find any solution. May be my question is not right but I need some guidance. I am using serial port in Linux which is reading data from my Arduino device. Whenever I want to send data from Arduino to Linux, I first send two bytes which indicate the total bytes which will come from Arduino. I convert these two bytes to integer value and start reading data from Serial Port. Say, I want to send 300 bytes from Ardiuno to Linux, I will just write {1, 44} first and then convert this 1 and 44 byte into int by the following formula:
char data[] = {1, 44};
int to_read = data[0]
to_read = to_read << 8;
to_read = to_read | data[1];
return to_read;
this will give me 300 int value, this is working like charm. but problem comes when I have to read data less then 255. Say I want to read 100 bytes, then first two bytes will be {0, 100}. 0 is null character, serial port doesn't process it (I manually wrote 0s to serial port, it always give me 0 bytes written), and my all sequence goes wrong. So my question is can I read null characters from serial port OR someone please give me better solution..
thanks in Advance.