How to reliably use Serial port within the local network

The easiest way to reliably use Serial port within the local network is to use RS-232/422/485 NPort Device Server produced by Moxa company. I will shortly describe how to install NPort 5110 (1-port RS-232 serial device server) on Debian Wheezy.

Step 1

Connect device to the network, change default device IP address (192.168.127.254) and operation mode to the Real COM mode.

Step 2

Identify device model, open product web-page NPort 5110, then click Drivers and Software link and download NPort Real TTY Driver for Linux.

Step 3

Extract downloaded source code.

$ tar xfvz npreal2_1.18_Build_12020919.tgz

Carefully read manual text file.

$ less tmp/moxa/README.TXT

Change working directory.

$ cd tmp/moxa

Build and install software.

$ sudo ./mxinst

===============================================================================
Copyright (C) 2002-2012  Moxa Inc.
All Rights Reserved.

MOXA NPort Server Real TTY Driver V1.18 Installation.
System Imformation: Kernel 3.2.0-4-amd64; Machine x86_64.
===============================================================================

Tar files, please wait ... OK!
Building driver...

If you want to use secure communication with target,
you might choose [y] to enable the SSL function.
Note: This function support RealCOM with secure mode only.
Do you want to enable secure function? [y/N].

make -C /lib/modules/3.2.0-4-amd64/build SUBDIRS=/home/milosz/tmp/moxa modules
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-4-amd64'
  CC [M]  /home/milosz/tmp/moxa/npreal2.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/milosz/tmp/moxa/npreal2.mod.o
  LD [M]  /home/milosz/tmp/moxa/npreal2.ko
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-4-amd64'
cp -p npreal2.ko /lib/modules/3.2.0-4-amd64/kernel/drivers/char/
depmod -a
cc -c npreal2d.c
cc npreal2d.o -o npreal2d
strip	npreal2d
cc -c redund_main.c
cc -c redund.c
cc	redund_main.o redund.o -lpthread -o npreal2d_redund
strip	npreal2d_redund
cc -o mxaddsvr mxaddsvr.c
strip mxaddsvr
cc -o mxdelsvr mxdelsvr.c
strip mxdelsvr
cc -o mxcfmat mxcfmat.c
strip mxcfmat
cc -o mxloadsvr mxloadsvr.c
strip mxloadsvr
cc -o mxsetsec mxsetsec.c
strip mxsetsec
Check Driver...
Copying configurations files ... OK!
Copying driver files ... OK!
Load driver...
OK!

Loading TTY Driver...
update-rc.d: using dependency based boot sequencing
Complete.

===============================================================================
Installation process is completed.
The all driver files are installed on /usr/lib/npreal2/driver.
Now you can cd /usr/lib/npreal2/driver and run ./mxaddsvr to add tty port.
===============================================================================

You will find similar entry in dmesg output.

[ 1563.248831] MOXA Async/NPort server family Real TTY driver ttymajor 33 calloutmajor 38 verbose 1 (1.18 Build 12020919)

Step 4

To add first serial port on the 192.168.1.228 NPort device execute the following command.

$ sudo /usr/lib/npreal2/driver/mxaddsvr 192.168.1.228 1
Adding Server...

ttyr00, cur00
Added RealCom server: ip : 192.168.1.228

mknod -m 666 ttyr00 c 33 0
mknod -m 666 cur00 c 38 0
update-rc.d: using dependency based boot sequencing
Complete.

Now you can use /dev/ttyr00 device.

Potential problems

I have encountered problem with init script on Debian Wheezy but it can be quickly solved by executing /etc/init.d/npreals script from the /etc/rc.local shell script or by modifying mxloadsrv source code to create proper init script.

Notes

Configuration file is stored in the /usr/lib/npreal2/driver/npreal2d.cf text file.

$ cat /usr/lib/npreal2/driver/npreal2d.cf
#=========================================================#
#   This configuration file is created by Moxa NPort      #
#   Administrator Program automatically, please do not    #
#   modify this file by yourself.                         #
#=========================================================#
ttymajor=3
3htmclalloutmajor=38
#[Minor] [ServerIP]	[data]	[cmd]	[FIFO]	[SSL]	[ttyName] [coutName] [interface][mode][BackIP]
0	192.168.1.228	950	966	1	0	ttyr00	cur00	0	0	(null)

To remove server use mxdelsrv command.

$ sudo /usr/lib/npreal2/driver/mxdelsvr 192.168.1.228
Delete Server ...
rm -f /dev/ttyr00
rm -f /dev/cur00
update-rc.d: using dependency based boot sequencing
Deleted server: 192.168.1.228

update-rc.d: using dependency based boot sequencing
Complete.

To uninstall driver use mxuinst command.

$ sudo /usr/lib/npreal2/driver/mxuninst
Driver Removal ...
update-rc.d: using dependency based boot sequencing
Complete

It is worth to note that Moxa provides also wide range of different products for industrial networking and automation.

Important note - 2015/08/19

Please contact your local Moxa distributor for an updated driver.

You will receive current (some kind of beta version, not official) driver, but it will work on Debian Jessie kernel 3.16.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a system administrator working for a successful Polish company and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu