Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
1 rating:
 1 out of 5     Rate this Document

Sending and Receiving One Character at a Time Using a Serial Port

Hardware: Serial

Problem:
I have a serial card and I’m getting data coming in, but until I hit some specific number of bytes I don’t see any of the bytes coming in. How can I setup my serial card to send in every byte it receives immediately?

Solution:
You want to send one byte of data at a time. On the receiving end, you want to make sure you get the byte back right when the UART receives it. You are looking for 1 byte triggering.

The trigger level determines how often an interrupt is generated to tell the driver that data is available in the UART receive buffer. The data bytes will collect in the FIFO until an interrupt occurs to tell the driver to read the information in the buffer.

In Windows Device Manager there are sliders to set up byte buffers for receiving and transmitting.

To get to these settings in Windows XP
  1. Go to Device Manager under Ports

  2. Right click on the COM port you want to set and select Properties

  3. Select the Port Settings tab

  4. Click Advanced button

  5. Change the setting using the sliders

Changing these settings will change when the serial card sends an interrupt to the operating system. The buffer is still the same size, however the interrupt flag will be generated earlier and more often. You can use this to your advantage if you are having difficulties with buffer overflow errors on your serial card at faster speeds. However changing the value to a smaller value does cause your system CPU to work harder to service the additional interrupts.

If you cannot change the buffer size on your card or you cannot set it to smaller than 8 bytes, you might be able to use the techniques listed below. This is more common on older style cards.

  1. If you are only sending 1 byte messages, you can disable the FIFOs, which will give you 1 byte triggering. Disabling the FIFOs can work (without overrun errors) even if you’re sending more than 1-byte messages, but the computer has to be able to respond within 1 character time to an interrupt to pull out a character from the UART if the character transmission is continuous. (So this is more likely to succeed with smaller baud rates and faster computers.)


  2. If you are not using parity, you can set the receiver and transmitter portions of the application to opposite types of parity. Set one for mark and another for space, or one for odd and another for even. This allows you to retain the buffer. The idea is that each incoming byte would be considered "bad". The UART would be checking for parity also, so it would interrupt, allowing the driver to read that byte of data. This is actually something that is untested, but theoretically should work.


Related Links:

Attachments:





Report Date: 10/02/2002
Last Updated: 04/21/2006
Document ID: 2Q18I8YF

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit