Serial I/O Problem: Reading/Writing the same Port

Serial I/O Problem: Reading/Writing the same Port

Post by Brad Per » Sat, 13 Jun 1992 00:43:36



I am trying to do Serial I/O in C through the RS-232 port on an
HP 425t running HP-UX 8.0.  I need to both read from and write
to this port.  I have set up two file descriptors (read, write).  
For each byte that is written to this port, an identical byte is to
be returned on the read channel.  There is a dumb terminal (VT220)
connected to this port; when a sent character (sent using write())
is displayed on the terminal, a person hits that same key to simulate
the echo back to the workstation.  This character is displayed on
the VT220 (which I assume means that it has been sent out on the
serial line), but a read() of size 1 does not terminate on
the workstation.  Many many keys can be pressed and the read() does
not terminate until a <CR> is hit.  Successive read() calls pick
up all the extra characters that were sent after the initial keystroke
and before the <CR> (i.e. *each* read() did not require its own <CR>
in order to see the character, just the first one).

I have read and re-read the man pages for open(), termio(), ioctl(), ...
and now need to ask for help.

I thought that read() did not buffer its input;  I have two questions:

  (1) Is it possible that the dumb terminal is not sending the
character until the <CR>?  I always thought the definition of dumb
was that it did no thinking for you.  
  (2) Is it that the terminal line needs to be configured in such a way
to force the read() to terminate after each character is sent?  And if so,
please don't tell me to read the termio() man page one more time!

Please comment on this method for testing the Serial I/O -- I will
be very grateful for any suggestions.  

Thanks,


 
 
 

Serial I/O Problem: Reading/Writing the same Port

Post by Michael Salm » Sat, 13 Jun 1992 03:34:01


[...]
|> I thought that read() did not buffer its input;  I have two questions:
|>
|>   (1) Is it possible that the dumb terminal is not sending the
|> character until the <CR>?  I always thought the definition of dumb
|> was that it did no thinking for you.  

Read doesn't buffer its input nor is it likely that the terminal is holding
characters, the most likely cause is that the terminal line is in cooked mode. If
you must have every character switch to raw mode.

|>   (2) Is it that the terminal line needs to be configured in such a way
|> to force the read() to terminate after each character is sent?  And if so,
|> please don't tell me to read the termio() man page one more time!

That unfortunately is probably what you should do, along with the man page for
ioctl. It is a fairly simple process of reading the terminal ports characteristics,
changing them to what you want and then writing them back. The tricky part is
deciding what you want.

--

Michael Salmon

#include        <standard.disclaimer>
#include        <witty.saying>
#include        <fancy.pseudo.graphics>

Ericsson Telecom AB
Stockholm

 
 
 

1. Serial port for read/write problem

Hi,

I am having trouble opening a serial port for read/write operations.
Basically, I don't seem to be able to do both operations on the same
port (sequentially, of course).
The serial HOWTO's are not much help as they only deal with reading, and
any documentation I've been able to find I find isconfussingly
complicated and not affective any way. Surely, there must be a more
simple and neat way of doing such simple operations. Any ideas welcome.

Jaime

2. Linux is not multiprocessor capable??

3. Reading and writing to serial ports

4. Mosaic

5. serial port read/write error

6. RH 7.3 ipchains routing, timing out...

7. read/write to serial port

8. localtime(), localtime_r()

9. read/write serial port

10. Setting serial port: read() and write()

11. How do you read/write serial port registers directly?

12. read/write serial port

13. Reading and writing to a serial port