0% found this document useful (0 votes)
277 views

Simulator Testing On CentOS Setup

This document discusses setting up a virtual serial port simulator on CentOS 7 using tty0tty. Tty0tty creates virtual serial port pairs that allow two legacy serial applications to communicate as if through a direct cable connection. The document provides instructions for installing, configuring, and testing tty0tty by reading and writing registers using modbus poll to communicate between the simulator and a modbus client.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
277 views

Simulator Testing On CentOS Setup

This document discusses setting up a virtual serial port simulator on CentOS 7 using tty0tty. Tty0tty creates virtual serial port pairs that allow two legacy serial applications to communicate as if through a direct cable connection. The document provides instructions for installing, configuring, and testing tty0tty by reading and writing registers using modbus poll to communicate between the simulator and a modbus client.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Simulator testing setup on CENTOS 7 with Virtual Serial Ports

Virtual Serial Port using tty0tty in Linux


Before starting off with this tutorial, let’s get on with a little bit of background on serial
communication, null modems, and virtual ports.

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:

1. Download the tty0tty package from one of these sources:


1.1 http://sourceforge.net/projects/tty0tty/files/
1.2 clone the repo https://github.com/freemed/tty0tty
2. Extract it
2.1 tar xf tty0tty-1.2.tgz
3. Build the kernel module from provided source
3.1 cd tty0tty-1.2/module
3.2 make
4. Copy the new kernel module into the kernel modules directory
4.1 sudo cp tty0tty.ko /lib/modules/$(uname -
r)/kernel/drivers/misc/
5. Load the module -> To be repeated on every restart of system
5.1 sudo depmod
5.2 sudo modprobe tty0tty
5.3 You should see new serial port/libs in /dev/ (ls /dev/tnt*)
6. Give appropriate permissions to the new serial ports
6.1 sudo chmod 666 /dev/tnt*

You can now access the serial ports as /dev/tnt0 (1,2,3,4 etc)

Note that the consecutive ports are interconnected. For


example, /dev/tnt0 and /dev/tnt1 are connected as if using a direct cable.

Persisting across boot:

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.

Testing with modbus poll in Linux


1. Download modbus poll for linux from Free Modbus Master Simulator and Test Tool
(modbusdriver.com)

Download archive into a folder. Then unpack the tarball:

tar xzf modpoll.tgz


The tarball contains multiple binaries for different CPU architectures. Add the version
matching your system architecture to the path. Example for ARM platforms like
Raspberry Pi:

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:

modpoll -b 9600 -p none -m rtu -a 3 -r 500 -c 10 COM1


To retrieve once 5 floating point values starting from reference 100 with Modbus/TCP
from slave device with IP 10.0.0.100:

modpoll -t4:float -r 100 -c 5 -1 10.0.0.100


To write the value 1234 to register 1201 using Modbus/TCP and FC 16 (Write Multiple
Registers):

modpoll -r 1201 10.0.0.100 1234


To write the value 1234 to register 1201 using Modbus/TCP and FC 6 (Write Single
Register):

modpoll -r 1201 -c 1 10.0.0.100 1234

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy