It's sunday again so time to work on my robot project again...
I have a problem that I can't seem to figure out :
I have a serial communication through Bluetooth between my Raspberry Pi and my PC with Putty.
I use the following code to send text from my RPi to Putty :
Code:
int serial::writeSerialPort(char const *string)
{
/*
write a string to the serial connection
*/
int result = write(fd, string, strlen(string)) ;
tcflush(fd, TCOFLUSH);
return result ;
}
The strange thing now is that sometimes the text is being send to Putty and that works a while.
Then suddenly it stops working, after a while it starts working again (all in the same session).
When I set a breakpoint and debug my code the text is always being outputted right after the write() function (before the tcflush() ).
This of course makes it hard to find out why I have this "bug".
Anyone that can point me in the right direction?
edit :
I changed my code to
Code:
ssize_t serial::writeSerialPort(char const *string)
{
/*
write a string to the serial connection
*/
ssize_t result = write(fd, string, strlen(string)) ;
tcflush(fd, TCOFLUSH);
if (result != strlen(string))
printf("Failed to write to serial port!\n") ;
else
printf("Wrote to serial port!\n") ;
return result ;
}
and it seems that the write function always return a value that is equal to strlen(string) so I'm sure that the write() worked!