If anyone has any ideas on this I’d appreciated it.
What I am seeing is that when there is a long break between the open and the write or between 2 writes to the com port. the first 2-3 BYTES are garbled
in the below the binary message I am sending is
0x03 0x04 0x00 0xDE 0x00 0x64 0x90 0x39
but what I sometimes get on the other side is something like this
0x40 0xEF 0x80 0x64 0x90 0x39
It’s not always the same values. but then the second write sends the correct data. Note its missing BYTES, that the last few bytes are correct and the write command returns that it sent the correct number of bytes.
0x03 0x04 0x00 0xDE 0x00 0x64 0x90 0x39
is there a sleep mode for the com port which I then have to wake up before sending a message?
I’ve tried with and with out tcflush
fd_comport = open (PortName, ComParams.mode);
if(fd_comport<=0)
{
return;
}
else
{
/* set the baud rate */
tcgetattr(fd_comport, &tios);
cfsetospeed(&tios, SIO_115200_BAUD);
/* set other parameters */
tios.c_cflag = CREAD | CS8;
tios.c_iflag = 0;
result = tcsetattr( fd_comport, TCSANOW, &tios );
if (result < 0) {
printf ("ioctl(Set attributes) failure: errno[%d]
", getErrno());
return;
}
if ( cfgetospeed(&tios) != SIO_115200_BAUD ) {
printf ("ioctl(Baud set) errno[%d]
", getErrno());
return;
}
if ( tios.c_cflag != CREAD | CS8)
{
printf ("ioctl(Flag settings) failure errno[%d]
", getErrno());
return;
}
}
[stop in debugger, or delay in the seconds range]
tcflush(fd_comport, TCIOFLUSH);
write (fd_comport , SendCmnd, SendLen);
write (fd_comport , SendCmnd, SendLen);// test resend