Reading and writing individual bits on the serial port 
Author Message
 Reading and writing individual bits on the serial port

Is there any easy way of reading and writing individual bits on the
serial (COM2) port?  I know the address of the port is 2F8.  I have
used inport and outport do read and write bits to the parallel port,
but I can not figure out how to do the same with the serial port.

I have a simple device that I need to turn individual bits on and off
and to look at individual bits for input on the COM2 port.

Any help would be greatly appreciated!



Wed, 09 Nov 2005 10:45:57 GMT  
 Reading and writing individual bits on the serial port
UART-based serial data is always sent via a data frame that consists
of a start bit, 5-8 data bits, an optional parity or 9th data bit, and
1-2 stop bits.  The ability to transmit a single bit really doesn't
exist (it may be faked using break, but timing won't be accurate).

If you wish to transmit a single byte, you'll first need to
open/configure the port.  Since you're talking about inport and
outport, I'm assuming you're not using the Win32 API, NI-VISA, or
labview.  In that case you will need to manually configure the UART.
Standard PC UARTs (generally COM1 and COM2) use the 16550-based
register map (do a google search for National Semiconductor 16550).
Initialization would look something like the following:

Base Address = some known value (you mentioned 2F8)

Offset Value Comment
0x03   0x80  Enable Divisor Latch
0x00   ?     Low 8 bits of divisor (generally 115.2 / divisior =
baudrate)
0x01   ?     High 8 bits of divisor
0x03   0x03  Disable divisor latch, set to 8 data bits, no parity, 1
stop bit

Then you transmit data by writing to offset 0 and read data by reading
offset 0.  There are many other features of the UART (like FIFOs,
error status, interrupts, etc.) that you may need to configure, so
take a look at the 16550 datasheet.

That said, I don't recommend talking to the hardware directly, and in
fact on modern OSes you won't be able to (NT, 2k, XP).

Instead use one of the APIs (Win32, NI-VISA, etc.)  This way you
abstract away the need to know about the type of UART being used.



Wed, 09 Nov 2005 11:21:57 GMT  
 Reading and writing individual bits on the serial port
I think that Dennis Knutson have already answered your question some
post before. In general, you can control only some pins on the com
port connector (those that correspond to control lines). Anyway, If
you plan to use com ports just to do simple digital I/O on com port
connector then it seems to me that serial ports are not very suitable
solution for your application because of their serial nature of
communication (which assumes buffering, handshaking and so on) - they
are just not intended to be used in the same way as parallel ports.


Wed, 09 Nov 2005 11:31:58 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How do I read/write serial port?

2. writing/reading from serial port

3. Reading/writing to serial port w/ VISA in Labview

4. Read/Write to serial port?

5. READ/WRITE serial Port MF 3.4

6. Using TK to read/write to serial port, allowing stdout display and TK GUI control

7. Serial port read/write

8. read/write serial port -- again ...

9. API's 32 BITS SERIAL PORT?

10. Setting Stop Bits for Serial Port

11. 16 bits integer read/write in OCaml

12. VHDL code to read and write bits from a file in PC

 

 
Powered by phpBB® Forum Software