Reading serial data from a RS232/RS485 sensor

How to connect a RS232 or RS485 sensor to a Gantner controller's serial port

Hardware Overview

While the Q.station and Q.monixx can communicate over Modbus RTU, there are sensors that communicate only over RS232/RS485.

A Q.monixx has 6x RS485 ports, and the USB ports can be used for RS232.

A Q.station has 2x USB ports for RS232.

If a sensor communicates over only RS485, a RS485-to-RS232 (USB) adapter is needed to connect to the Q.station.

To configure communication, the test.con software is needed. This is available on a "T" version Q.station (e.g. Q.station XT) and in all versions of the Q.monixx.

Software Configuration

In the controller settings in GI.bench, make sure Pac kernel mode is activated.

Create a setpoint virtual variable under the controller. This is where we will push the value from the sensor to

You can give the channel units under the Scaling section. Manually type in the units.

test.con

In test.con, we will need the Serial Communication library of function blocks to configure the communication. More detailed info here: https://testcon.info/rs232-communication-on-q-station.html

While it says RS232 for the port name/receive/transmit function blocks, it can be used for RS485 as well.

We will need to know

  • Port the sensor is connected to
  • Baudrate of sensor
  • Query command format
  • Response format

Open port

Use the Port open function block. Assign parameters for the port and baudrate. Connect a switch (bit/byte) format to the enable/disable pin.

Q.station/Q.monixx USB ports

USB #1: 100

USB #2: 200

Q.monixx RS485 ports

RS485 #1: 1

....

RS485 #6: 6

Write command to port

Use the RS232-transmit function block. Assign parameters for Port, Start of Transmission (SOT), End of Transmission (EOT), and data command. Connect a switch to enable/disable the command.

In this example, a command of #*PRESS?<CR><LF> is needed to get the pressure values from this pressure transducer sensor. The #, <CR>, and <LF> parameters are entered using their respective ASCII symbols.

# (SOT): 35

CR (carriage return): 13

LF (line feed): 10

The command needs to be in the DYNTEXT format. Use the Converter function block under the Dynamic Texts library.

Command: *PRESS?

Read data from port

Use the RS232-receive function block. Assign parameters for Port, SOT, and EOT. Connect a switch to enable/disable the reading.

For this example, the sensor response comes in the format +n.nnnnnnnE+nn <CR><LF>

+ (SOT): 43

CR (carriage return): 13

LF (line feed): 10

The output is in the DYNTEXT format. Use the converter function block again to convert to desired format e.g. FLOAT. Assign this to a setpoint virtual variable created in the controller. The format should match the format of the setpoint variable.