« Close

Datasheets and User Guides

App Notes

Software & Driver

 

4.3.12 - Asynchronous Serial Communication

The UE9 has a UART available that supports asynchronous serial communication. The UART connects to the PIN2/PIN20 (TX0/RX0) pins on the DB37 connector.

Communication is in the common 8/n/1 format. Similar to RS-232, except that the logic is normal CMOS/TTL. Connection to an RS-232 device will require a converter chip such as the MAX233, which inverts the logic and shifts the voltage levels.

This serial link is not an alternative to the USB connection. Rather, the host application will write/read data to/from the UE9 over USB, and the UE9 communicates with some other device using the serial protocol. Using this serial protocol is considered an advanced topic. A good knowledge of the protocol is recommended, and a logic analyzer or oscilloscope might be needed for troubleshooting. Also consider that a better way to do RS-232 (or RS-485 or RS-422) communication is with a standard USB<=>RS-232 adapter/converter/dongle, so the user should have a particular reason to not use that and use a UE9 instead.

There is one IOType used to write/read asynchronous data:

LJ_ioASYNCH_COMMUNICATION

The following are special channels used with the asynch IOType above:

LJ_chASYNCH_ENABLE  // Enables UART to begin buffering RX data.
LJ_chASYNCH_RX      // Value= returns pre-read buffer size. x1= array.
LJ_chASYNCH_TX      // Value= number to send (0-56), number in RX buffer. x1= array.
LJ_chASYNCH_FLUSH  // Flushes the RX buffer.  All data discarded. Value ignored.

When using LJ_chASYNCH_RX, the Value parameter returns the size of the Asynch buffer before the read. If the size is 32 bytes or less, that is how many bytes were read. If the size is more than 32 bytes, then the call read 32 this time and there are still bytes left in the buffer.

When using LJ_chASYNCH_TX, specify the number of bytes to send in the Value parameter. The Value parameter returns the size of the Asynch read buffer.

The following is a special channel, used with the get/put config IOTypes, to specify the baud rate for the asynchronous communication:

LJ_chASYNCH_BAUDFACTOR  //  Value= 2^16 – 3000000/bps

For example, use a BaudFactor of 65224 to get a baud rate of 9615 bps (compatible with 9600 bps).

Following is example pseudocode for asynchronous communication:

//Set data rate for 9600 bps communication.
ePut(lngHandle, LJ_ioPUT_CONFIG, LJ_chASYNCH_BAUDFACTOR, 65224, 0);

//Enable UART.
ePut(lngHandle, LJ_ioASYNCH_COMMUNICATION, LJ_chASYNCH_ENABLE, 1, 0);

//Write data.
eGetPtr(lngHandle, LJ_ioASYNCH_COMMUNICATION, LJ_chASYNCH_TX, &numBytes, array);

//Read data.  Always initialize array to 32 bytes.
eGetPtr(lngHandle, LJ_ioASYNCH_COMMUNICATION, LJ_chASYNCH_RX, &numBytes, array);

6 comments

hi labjack community,

Is it possible to send the serial data through one of the the digital i/o pins and receive the data at other digital i/o pin. Can you give me a sample code to achieve so? Thanks.

If you mean asynchronous, that is what is discussed in this section.  If you mean synchronous, see SPI or I2C.  For examples beyond the pseudocode, it depends on what language you are using but some are available.

I have two different devices that I would like to control using asynch serial communication. Can I communicate with both simultaneously with one Labjack?

On the UE9 the TX and RX lines are on specific pins, so to communicate with more than one RS232 device you will need some external circuitry, a multiplexor or the like.

The U3 and U6 can move the TX and RX pines. That would allow you to communicate with more than one RS232 device without the need for external circuitry.

Note that in both of the above situations you will need use additional DIO lines to tell the device that is not currently selected to not send data. This is normal clear to send / ready to receive functionality that is usually included in RS232 devices.

One could use the RS232 to serial adapter from Modern Device for some situations - I suppose.

http://shop.moderndevice.com/products/p4

Yes, that appears similar to the MAX233 converter chip.