hello,
i have some trouble using serialWrite(), i write a 4 byte structure with the loop below, all works file if no value reaches 255. If a value is exact 255 one ore two more bytes received on pc side.
struct AnalogInput // 4 byte
{
byte protocol;
byte command;
byte u;
byte i;
};
void serialPrint(const unsigned char buf[], byte size)
{
for (int i = 0; i < size; i++)
serialWrite(buf[i]);
}
void send()
{
AnalogInput data;
data.protocol = protocoll;
data.command = cAnalogIn;
data.u = 255;
data.i = 255;
serialPrint((byte*)&data, sizeof(AnalogInput));
}
I checked the sizeof(AnalogInput) and the alignment (pack) all looks fine. The effect is independent of the baud rate.
If all members are less than 255 i receive exact 4 bytes on pc side, if i and u is 255 (as in the example above) i receive 6 bytes.
Does i have to initialize the device on the PC side (for binarie data) in other way than the code below?
if ((fd = open(device, O_RDWR | O_NOCTTY)) < 0)
{
perror(device);
return fail;
}
theEloquence = eloDebug;
// configure serial line
tcgetattr(fd, &oldtio);
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | PARMRK;
newtio.c_oflag = 0;
newtio.c_lflag = 0;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &newtio);
Regards
horchi