tags:

views:

49

answers:

2

Hi,

I am using C language and Linux as my programming platform. Right now I am learning some embedded programming. I am using a POS device for my practice session and my host is a Windows OS using a cygwin.

I created a simple application that will run in the target device that will read the data in the serial port and in the host side I created a simple application that will write the data in the serial port. Now my problem is when I am sending a data without 0x0a(LN) at the end of the buffer the target device will not receive that data. But I am not sure if that was sent or not. But when I put a 0x0a(LN) at the end of the buffer to send then the target device will receive that data.

Did I missed some configuration of my application? Or putting a 0x0a byte at the end of the tx buffer is the correct way.

Thanks

A: 

Sounds like it's doing line buffering. Do a flush after sending the data.

Ignacio Vazquez-Abrams
+2  A: 

It sounds like your serial port (actually the 'terminal device' as far as Linux is concerned) may be in line-buffered mode. When setting it up with tcsetattr, be sure to clear c_lflag (you don't want ICANON). You should also check out the input/output flags that affect translation between CRLF and NL since you probably don't want that behavior either. Default terminal settings are oriented towards user/application interaction, not data transmission.

R..
Also, if you're using stdio instead of low-level POSIX `write` make sure you disable buffering at the stdio level. `setbuf(f, NULL);` should do the trick.
R..