tags:

views:

437

answers:

1

I'm asked to read from and write to a half-duplex serial connection using POSIX calls (more specifically, writing in C on Linux 2.6.x). I'm having slight troubles finding detailed information on that particular model (most pages concentrate on full-duplex) and as I am getting slight anomalies when reading, I wanted to check whether maybe I am doing something wrong here.

With a half-duplex serial connection, I can only read or write. This is not a problem, as there is no unsolicited incoming data on the line - the only time any packages are sent to me (for reading) is when I asked for them beforehand.

So what my code does is to write() to the port whenever something needs to be sent. Should this data result in a response (something I know beforehand), I simply read(). There are no special functions I am calling - but maybe I should? And is this approach correct? I.e. write when the line is free?

A: 

I would read the Linux kernel source documentation, there may be a text file about the serial driver; if not, you could read through the actual driver code to see what it does (it's not as scary as it sounds, I promise!)

Paul Betts