Saturday, December 08, 2007

Linux Virtual Serial Port

When programming with Serial Ports, is often useful to have 2 Virtual Serial Ports communicating each other for debugging, without the need of a Null Modem serial cable connected to phisical serial ports of the same Pc, or connected to a second Pc.
What you need is VSPD!
Download the RPM or tar.gz packet from http://www.tibbo.com/vspdl.php
Install it following the instructions, then you should find the vspd.conf file in /usr/local/vspd/etc/ folder.
Open it and edit as follow (modify the IP 192.168.1.3 with your IP address):

<!-- **** VIRTUAL SERIAL PORT DRIVER FOR LINUX (VSPDL) CONFIGURATION FILE **** -->
<!-- Copyright (C) 2003-2004, Tibbo Technology Inc. -->
<vspdconfig>

<root dir="/usr/local/vspd"/>

<devprefix value="/dev/vspd"/>

<bind host="192.168.1.3"/>

<timeout exec="10000" priority="10"/>

<log type="file" level="EMR" path="var/vspd.log"/>
<log type="file" level="ALR" path="var/vspd.log"/>
<log type="file" level="CRT" path="var/vspd.log"/>
<log type="file" level="ERR" path="var/vspd.log"/>
<log type="file" level="WRN" path="var/vspd.log"/>
<log type="file" level="NTC" path="var/vspd.log"/>
<log type="file" level="INF" path="var/vspd.log"/>
<log type="file" level="DBG" path="var/vspd.log"/>

<vsp num="0">

<bind host="" port="3500"/>

<connection rmode="server/client" proto="tcp" conmode="ondata" timeout="5" onthefly="outofband"/>

<destination ip="192.168.1.3" port="3501" cport="65535"/>

<packets maxlen="255" maxdelay="0" starton="any"/>

<log type="file" level="EMR" path="var/dev.0.log"/>
<log type="file" level="ALR" path="var/dev.0.log"/>
<log type="file" level="CRT" path="var/dev.0.log"/>
<log type="file" level="ERR" path="var/dev.0.log"/>
<log type="file" level="WRN" path="var/dev.0.log"/>
<log type="file" level="NTC" path="var/dev.0.log"/>
<log type="file" level="INF" path="var/dev.0.log"/>

</vsp>

<vsp num="1">

<bind host="192.168.1.3" port="3501"/>

<connection rmode="server/client" proto="tcp" conmode="ondata" timeout="5" onthefly="outofband"/>

<destination ip="192.168.1.3" port="3500" cport="65535"/>

<packets maxlen="255" maxdelay="0" starton="any"/>


<log type="file" level="EMR" path="var/dev.1.log"/>
<log type="file" level="ALR" path="var/dev.1.log"/>
<log type="file" level="CRT" path="var/dev.1.log"/>
<log type="file" level="ERR" path="var/dev.1.log"/>
<log type="file" level="WRN" path="var/dev.1.log"/>
<log type="file" level="NTC" path="var/dev.1.log"/>
<log type="file" level="INF" path="var/dev.1.log"/>

</vsp>

</vspdconfig>

Now you can start the service with
#/etc/rc.d/init.d/vspd start
or, if the service was already running:
#/etc/rc.d/init.d/vspd reloadconf

To test the communication I used minicom on two different consoles, setting first to the port /dev/vsps0, and second to /dev/vsps1