Serial Port Demo
In this demo we demonstrate how to connect an application on a Linux host with a MIO04 COM port. We use a cable to loop the RS232 transmit pin to the receive pin so that all characters sent to the COM port are echoed back.
Access MIO04 COM port from ModuCop
Preparation steps:
- Configure the network and device ID for the MIO04 as described in the quick-start guide
- Connect a PC, the ModuCop, and the MIO04 to the same network (for example via Ethernet switch or Wi-Fi access point)
- From the PC, log in to the ModuCop via SSH
Check whether MIO04 COM ports are recognized on ModuCop
The ModuCop Linux image automatically detects COM ports of io4edge devices.
For each detected COM port, a Linux device /dev/tty<device-ID>-com<port> is created. For example, if your MIO04 device ID is MIO04-1, you will find the following TTY devices:
root@moducop-cpu01:~# ls -l /dev/ttyMIO04-1*
crw-rw---- 1 root dialout 199, 3 Jul 28 13:33 /dev/ttyMIO04-1-com1
crw-rw---- 1 root dialout 199, 4 Jul 28 13:33 /dev/ttyMIO04-1-com2
Function test
Create a hardware loop between the RS232 transmit and receive pins of the COM1 RS232 interface. Connect pin 2 and pin 3 of the COM port D-sub connector:
Start the minicom terminal program on ModuCop:
root@moducop-cpu01:~# minicom -D /dev/ttyMIO04-1-com1 -b 115200
Because we do not have hardware flow control lines, we must tell minicom not to use hardware flow control:
- Press
CTRL-Afollowed byO(O like Omega) - Select
Serial Port Setup - Press
F
Hardware flow control should now be off:
F - Hardware Flow Control : No
Press ESC twice to return to the main minicom screen. Type a few characters and you should see them echoed back because of the hardware loop.
Welcome to minicom 2.7.1
OPTIONS: I18n
Compiled on Apr 18 2017, 09:55:23.
Port /dev/ttyMIO04-1-com1, 13:45:27
Press CTRL-A Z for help on special keys
dddddddddddd..ffffdddddddddddddddd
To leave minicom, press CTRL-A, then X.
Access MIO04 COM port from any Linux host
To access the MIO04 COM ports from any Linux host, use ttynvt to create a virtual TTY device on the host that forwards traffic to the MIO04 over the network.
ttynvt installation
Requirements on linux host:
* kernel must support FUSE (FUSE_FS=y)
* libpthread and libfuse must be installed in the root filesystem.
* git, autoconf, make, gcc installed
Build:
$ git clone https://gitlab.com/ci4rail/ttynvt.git
$ cd ttynvt
$ autoreconf -vif
$ ./configure
$ make
Start ttynvt
In a first terminal, start a temporary instance of ttynvt.
# From the folder where you built ttynvt
$ sudo src/ttynvt -f -E -M 384 -m 1 -S <ip-address-of-your-device>:10000 -n ttyNVT0
This command creates a new device /dev/ttyNVT0:
$ ls -l /dev/ttyNVT0
crw-rw---- 1 root dialout 384, 1 Jul 28 16:05 /dev/ttyNVT0
Function test
Create a hardware loop between the RS232 transmit and receive pins of the COM1 RS232 interface. Connect pin 2 and pin 3 of the COM port D-sub connector:
In a second terminal, start the picocom terminal program and verify that characters are echoed back by the hardware loop.
$ picocom /dev/ttyNVT0 -b 115200
...
Terminal ready
dddddddddddd..ffffdddddddddddddddd
To leave picocom, press CTRL-A, then CTRL-X.