Hi i have this code in linux that sends hex data to arduino..
unsigned char pCom[2][7]={{0xFF,0x01,0x00,0x10,0x2F,0x2F,0x6F},
{0xFF,0x01,0x00,0x08,0x2F,0x2F,0x67}};
write(fd,pCom[0],8); // write to arduino which is /dev/ttyS0..
Now how can i let arduino read this stream of bytes?..
Here's the code im using in reading in the serial..
The call to Serial.flush() makes no sense. If you are using a version of the IDE prior to 1.0, the flush() method dumps all as-yet-unread data in the serial buffer. Nanoseconds after opening the serial port, do you really think that there is a possibility that there is unread data pending? If there really could be, why do you want to delete it?
If you are using 1.0 or later, the flush() method blocks until all buffered output data has been sent. You haven't sent anything, so the function does absolutely nothing.
Useless code is best deleted.
write(fd,pCom[0],8); // write to arduino which is /dev/ttyS0..
pCom[0] is one element of the array. It is not 8 bytes long. Why are you telling write() that it is? Don't you really want to send the whole array, or at least the first 8 bytes of the array?
The call to Serial.flush() makes no sense. If you are using a version of the IDE prior to 1.0, the flush() method dumps all as-yet-unread data in the serial buffer. Nanoseconds after opening the serial port, do you really think that there is a possibility that there is unread data pending? If there really could be, why do you want to delete it?
If you are using 1.0 or later, the flush() method blocks until all buffered output data has been sent. You haven't sent anything, so the function does absolutely nothing.
Ok sir understood thanks for pointing that out to me..
pCom[0] is one element of the array. It is not 8 bytes long. Why are you telling write() that it is? Don't you really want to send the whole array, or at least the first 8 bytes of the array?
Well that's what i thought that it will send 8 bytes of data to arduino.. if you so how can i send the first eight bytes of the array eg 0xFF,0x01,0x00,0x10,0x2F,0x2F,0x6F = which arduino outputs to serial then php read it as = ff0100102f2f06f