Serial Port Handling in C#

Joined
Jul 15, 2012
Messages
1
Reaction score
0
In DOS, C, VB6 we could check if Transmitter Shift Register or Transmitter Holding Register empty or not before writing any data onto the serial port. This facility would certainly avoid making the attempt of writing while the port is not ready to accept data. similarly, we could check if valid data has arrived in the serial port receiver before we read data.

I am converting my VB6 based serial communication codes into C#. But, I don't find anything (I mean method) in C# that will allow me to check if TX-register or THR is ready to accept data.

Also, I would like to check that RX-register is ready with data before I attempt to read data from it.

Would appreciate to receive answer. (I am afraid these features are removed in C#!).

Regards,
 
Joined
Jun 12, 2012
Messages
53
Reaction score
0
There's no need to check these registers on modern computers. Here's good explanation and some other useful serial port stuff, including below:

Q: What control lines can I manually manipulate?
Control lines on an RS-232 serial port were introduced to provide flow control of serial data. Even though a modem or PC may be rated for a particular baud rate, it doesn’t always mean that the device can process the data that fast. For example, bits may flow in through a modem at 2400 bps (bits per second) but in the early days a PC couldn’t process the data fast enough, so it would toggle control lines to tell the modem that it was read for more data or to ‘pause’ send it data. Now since PCs are quite fast these lines are mostly ignored. They can be used as a simple way to toggle an LED or send or receive high or low states. RTS/CTS control flow is one such technique which is supported natively by the control via the Handshake property.

Lines marked ‘Output’ in the table can be set by the serial port to a high or low state (True or False) and the ‘Input’ lines can be read as high or low. You can use the
PinChanged
event to be notified when one of the input pins changes. The
Handshake
property can be set to use RTS/CTS (uses hardware control lines) or XON/XOFF (uses software) or both.

Control LineNameDB9 PinSerialPort PropertyI/ODTRData Terminal Ready4DtrEnableOutputRTSRequest to Send7RtsEnableOutputCTSClear to Send8CtsHoldingInputDSRData Set Ready6DsrHoldingInputCD (or DCD)Data Carrier Detect1CDHoldingInput
For detecting a Ring Indication, see the next question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top