Simulator Testing On CentOS Setup
Simulator Testing On CentOS Setup
A serial port (COM port) is an asynchronous port on the computer used to connect a serial device
and capable of transmitting data one bit at a time or serially. Most serial ports on computers
conform to the RS-232C or RS-422 standards. A serial port is a physical interface for
communicating digital data between a DTE (Data Terminal Equipment) -usually your computer
and a DCE (Data Communication Equipment) – your modem or another serial device. A standard
RS-232 cable is used to connect a DCE device to a DTC device via their serial ports.
You can’t always expect to pair up DTE and DCE equipment. The devices can be configured as
either DTE or DCE. The DTE interface can be used by both your PC and the attached serial device.
However, the DTE interface is designed to work with a DCE device. If you want to connect two DTE
devices together, a special type of serial cable is required called a “null modem” cable. A null
modem cable makes the other end of the PC or device’s DTE interface look like a DCE interface.
Null modems cables are commonly used for data transfer between computers or two software
packages running on the same computer. For example, if you are using a single computer with two
serial ports, you can assign the first serial port to one software and the second serial port to the
other software. Connecting a physical null modem cable between the serial ports would then allow
the two programs to communicate with each other. Although this works just fine, the null modem
cable makes the computer more susceptible to RFI because of the physical cable looped between
two serial ports.
A virtual serial port allows you to emulate a physical serial port and thus removes the necessity
of bulky cable and physical communication interfaces. Such virtual ports allow your software
1|Page
Simulator testing setup on CENTOS 7 with Virtual Serial Ports
packages to communicate using the computer’s internal memory. A special type of software that
combines two virtual serial ports together and allows data to pass between them is known as
a null modem emulator.
Let’s move on to our topic now. The Linux null modem emulator (tty0tty) is a kernel-module virtual
serial port driver for Linux. This creates virtual tty ports pairs and you can use any pair to
establish communication between two legacy serial applications.
Installing tty0tty:
You can now access the serial ports as /dev/tnt0 (1,2,3,4 etc)
Edit the file /etc/modules (Debian) or /etc/modules.conf and add the following line:
tty0tty
Note that this method will not make the module persist over kernel updates so if you ever update
your kernel, make sure you build tty0tty again and repeat the process.
2|Page
Simulator testing setup on CENTOS 7 with Virtual Serial Ports
export PATH=$PWD/modpoll/linux_arm-eabihf:$PATH
Then run modpoll:
modpoll -h
Usage
Usage: modpoll [OPTIONS] SERIALPORT|HOST [WRITEVALUES...]
Arguments:
SERIALPORT Serial port when using Modbus ASCII or Modbus RTU protocol
COM1, COM2 ... on Windows
/dev/ttyS0, /dev/ttyS1 ... on Linux
HOST Host name or dotted IP address when using MODBUS/TCP protocol
General options:
-m ascii Modbus ASCII protocol
-m rtu Modbus RTU protocol (default if SERIALPORT contains /, \\ or
COM)
-m tcp MODBUS/TCP protocol (default otherwise)
-m udp MODBUS UDP
-m enc Encapsulated Modbus RTU over TCP
-a # Slave address (1-255 for serial, 0-255 for TCP, 1 is
default)\n
-r # Start reference (1-65536, 1 is default)
-c # Number of values to read (1-125, 1 is default), optional for
writ
ing (use -c 1 to force FC5 or FC6)
-t 0 Discrete output (coil) data type
-t 1 Discrete input data type
-t 3 16-bit input register data type
-t 3:hex 16-bit input register data type with hex display
-t 3:int 32-bit integer data type in input register table
-t 3:mod 32-bit module 10000 data type in input register table
-t 3:float 32-bit float data type in input register table
-t 4 16-bit output (holding) register data type (default)
-t 4:hex 16-bit output (holding) register data type with hex display
-t 4:int 32-bit integer data type in output (holding) register table
-t 4:mod 32-bit module 10000 type in output (holding) register table
-t 4:float 32-bit float data type in output (holding) register table
-i Slave operates on big-endian 32-bit integers
-f Slave operates on big-endian 32-bit floats
-e Use Daniel/Enron single register 32-bit mode
-0 First reference is 0 (PDU addressing) instead 1
-1 Poll only once only, otherwise every poll rate interval
-l Poll rate in ms, (1000 is default)
-o # Time-out in seconds (0.01 - 10.0, 1.0 s is default)
Options for MODBUS/TCP, UDP and RTU over TCP:
-p # IP protocol port number (502 is default)
Options for Modbus ASCII and Modbus RTU:
-b # Baudrate (e.g. 9600, 19200, ...) (19200 is default)
-d # Databits (7 or 8 for ASCII protocol, 8 for RTU)
-s # Stopbits (1 or 2, 1 is default)
-p none No parity
-p even Even parity (default)
-p odd Odd parity
-4 # RS-485 mode, RTS on while transmitting and another # ms after
Usage Examples
To get help on usage run the following command:
3|Page
Simulator testing setup on CENTOS 7 with Virtual Serial Ports
modpoll -h
To retrieve continuously 10 Modbus holding registers starting from reference 500 of
slave ID number 5 with Modbus RTU at 9600 baud, no parity on COM1 run:
Test Screenshots
1. At Simulator end set the values and start the serial port
4|Page
Simulator testing setup on CENTOS 7 with Virtual Serial Ports
2. Open the console and enter the command
1.23E+3 = 0x4499 17561 (higher byte first) and 0xc000 49152 = rolls over to -16384
5|Page