Virtual Serial Port (Linksys WRT or other)

1 reply [Last post]
Michael Watterson's picture
Michael Watterson
Offline
Joined: 21 Sep 2009
Posts:

This enables a remote Serial port on any Linux Device, and OpenWRT specifically to Windows or Linux via LAN or Internet.

Static IP is generally required.

Features:
* 75 baud to 115kbps
* No Hardware handshake
* 8bit data.
* Raw: All control characters ignored and transparently passed.

The connection to the remote serial port is via TCP/IP on Port 2004
On a WRT54G3G The TCP/IP connection may be by one of:
* LAN 192.168.?.* subnet (may be changed)
* ethernet WAN (Cable, DSL, Metro, Satellite, Wireless, Fibre or other ethernet Modem)
* PCMCIA Modem or USB modem via PCMCIA adaptor to WAN (GSM-EDGE/3G-HSPA)
Only one predefined IP may connect on the WAN. The Client IP address is preprogrammed as a Firewall rule using the LAN only accessible Web based Administration Interface.

Use Firewall Rules to limit connection via IP source for added Security

Clients:
A client can be any of:
* Similar Serial Device Client
* TCP/IP socket programming on Linux, OS X or Windows
* Virtual Com port Driver on Windows or Linux
The Linksys Serial Device Client is physically identical to the server, but a different software configuration. Using the Web Interface on the LAN the local Serial port is redirected to the actual IP address of the Serial Device Server. Any network connection may be used (PCMCIA modem, LAN or WAN ethernet). No firewall rules are required.
Local Serial Port:
* 75 baud to 115kbps
* No Hardware handshake
* 8bit data.
* Raw: All control characters ignored and transparently passed.

The TCP/IP connection may be by one off:
* LAN 192.168.?.* subnet (may be changed)
* ethernet WAN (Cable, DSL, Metro, Satellite, Wireless, Fibre or other ethernet Modem)
* PCMCIA Modem (Currently Digiweb Flash-OFDM Mobile Internet) WAN
Other features:
Both the Server and Client are fully functional Routers with VLAN, LAN, WAN, NAT and statefull inspection firewall. They can be used simultaneously for Internet access.


Settings you need to configure

All can be changed except WAN IPs, which are according to MAC address of PCMCIA Modem Datacard.

Serial Port Server = Battery powered unit:
LAN ---.---.---.---
WAN ---.---.---.---
login: root pass: ********
hostname : '???????????
Firewall is set to only accept connection from ---.---.---.--- on port 2004 TCP for serial port
Serial: 1200, 8, n, 1, no handshake

Serial Port Client = Unit with aerial and no battery:
LAN ---.---.---.---
WAN ---.---.---.---
login: root pass: *********
hostname : '?????????
set to connect only to ---.---.---.--- for serial port
Serial: 1200, 8, n, 1, no handshake

The "Server" can't send any data until the "client" connects by sending data. Which ever end of the link initiates communication should thus be the Client. The "Server" listens for a TCP connection on Port 2004 and the "Client" creates a connection outgoing on Port 2004 so needs no firewall rules on the actual Linksys router as by default all outgoing connections are permitted.

If the WAN network connection is lost, the "Client" will drop its connection. Once a minute the outgoing TCP port is checked and if the connection has been dropped it is restarted. If the "Server" is not running, the "Client " thus retries every minute. This timeout can be changed.

The server end uses the linux "ser2net" program. Any client must be compatible.

The client end on the linksys uses "nc" with pipe from local serial port and redirection to local serial port.

Options for Office end without Linksys Serial port:
1) Client version
Linux Server / Desktop:
various options including "nc" command.

Windows Virtual Com port:
http://www.hw-group.com/products/hw_vsp/index_en.html

Or simply open a TCP winsock to the required IP address and port when using Turbopascal, Delphi,VB, C++, Java, C# or Modula-2

2) Server version
Linux Server / Desktop
Install ser2net Available via source forge
http://ser2net.sourceforge.net/
Windows:
It's in theory possible to build ser2net for Windows. Some of the Windows Serial Device Servers do Work with "nc" Linux client in Linksys. I'll test the ones I have (which I used to share GPS from Laptop to internet on XP).

Any of this stuff will work to connect Windows GPS apps that think a local serial GPS is connected to a remote GPS on a Linksys Router (OEM module internally rather than external on serial port is 1/2 the price of a Bluetooth or Serial external packaged GPS. The GPS can be a Client (better, as it only sends) or a Server.

You need stty and ser2net installed
Each serial port has a "file" associated with it in the /dev directory. It isn't really a file but it seems like one. For example, /dev/ttyS0 (or /dev/tts/0 for the Device File System). Other serial ports are /dev/ttyS1, /dev/ttyS2, etc. But ports on the USB bus, multiport cards, etc. have different names.

root@dwlink1:~# cat /proc/tty/driver/serial
serinfo:1.0 driver:5.05c revision:2001-07-08
0: uart:16550A port:B8000300 irq:3 baud:115740 tx:277 rx:0 RTS|CTS|DTR|DSR|CD
1: uart:16550A port:B8000400 irq:0 tx:0 rx:0 CTS|DSR|CD
root@dwlink1:~#

//to Install stty
cd /bin
wget http://tobe.mine.nu/software/openwrt/stty.tgz
tar zxf stty.tgz
rm stty.tgz
chmod 775 stty
ln -s /lib/libc.so.0 /lib/libgcc_s.so.1

Install ser2net from package list.

Master/Server UNIT
file /etc/init.d/S95
#!/bin/sh
# place your own startup commands here
#
# REMEMBER: You *MUST* place an '&' after launching programs you
# that are to continue running in the background.
#
# i.e.
# BAD: upnpd
# GOOD: upnpd &
#
# Failure to do this will result in the startup process halting
# on this file and the diagnostic light remaining on (at least
# for WRT54G(s) models).
#
stty -F /dev/tts/0 speed 1200 raw -echo
ser2net -u

Change the 1200 to 300

IN file: /etc/ser2net.conf

2004:raw:600:/dev/tts/0:1200 NONE 1STOPBIT 8DATABITS -XONXOFF LOCAL -RTSCTS
3004:telnet:600:/dev/tts/0:1200 NONE 1STOPBIT 8DATABITS -XONXOFF LOCAL -RTSCTS
Change the 1200 to 300

IN file: /etc/inittab
::sysinit:/etc/init.d/rcS
#tts/0::askfirst:/bin/ash --login
stty -F /dev/tts/0 speed 1200 raw -echo

Change the 1200 to 300

On the Slave/client
file /etc/init.d/S95
#!/bin/sh
# place your own startup commands here
#
# REMEMBER: You *MUST* place an '&' after launching programs you
# that are to continue running in the background.
#
# i.e.
# BAD: upnpd
# GOOD: upnpd &
#
# Failure to do this will result in the startup process halting
# on this file and the diagnostic light remaining on (at least
# for WRT54G(s) models).
#
stty -F /dev/tts/0 speed 1200 raw -echo
crond

Change the 1200 to 300

file: /etc/inittab
::sysinit:/etc/init.d/rcS
#tts/0::askfirst:/bin/ash --login
stty -F /dev/tts/0 speed 1200 raw -echo

Change the 1200 to 300

Installing HW VSP3
HW VSP 3 is freeware; you can download it free of charge HERE. The software is available in a single-port and multi-port version (development is in the final stage now). Installation is straightforward, except for Windows Vista, where it is necessary to allow the installer to elevate its privileges.
Installation procedure:
* Run the 'HW VSP Setup 3.0.23 single.exe' installation program.
* Step 1: The welcome screen is displayed. Click 'Next' to proceed to the next step of the installation, or click 'Back' to return to the previous step.
* Step 2: The basic product information is displayed.
* Step 3: Select the location where to install the driver.
* Select installation type ' Client-Server / Standalone or Custom.
* Step 4: Choose a name for the folder to create in the Start menu.
* Step 5: Select whether you want to create a shortcut on the Desktop.
* Step 6: The entered data are displayed for verification.
* Step 7: Confirm the installation.
If the installation is successful, the following window appears. If you check the 'Launch HW_VSP' box, the program is started after completing the installation. It is not necessary to restart the computer after the installation. You can start HW VSP by clicking the 'VSP' icon (icon with a red arrow).
Note: When installing HW VSP in Client/Server mode or using it in the Server mode on Windows XP SP2/Vista/2003 Server, it is necessary to manually configure the firewall to enable the appropriate communication ports or the entire service (by default Program Files\HW group\HW VSP3s\HW_VSP3s_srv.exe for the single-port version and Program Files\HW group\HW VSP3\HW_VSP3_srv.exe for the multi-port version). Firewall dialog control is currently under development.
Configuring the connected device
Before connecting to the VSP, it is necessary to configure the remote device according to its manual. If you use one of our devices, make sure to check the following parameters.
Most important parameters:
* IP address of the remote device
* IP port
* Gateway
* Mask
* TCP/IP mode - TCP Server / Passive mode
* Network Virtual Terminal (NVT) - On (only for recommended HWg devices)
* Serial port parameters

UDP Search
Run HW VSP and switch to 'UDP Search' tab. After clicking Search modules, the Modules MAC List displays a list of devices found in the local network segment.
Click Use this IP to set the IP address and the incoming port number of the selected device as the current device address for HW VSP to work with.

Virtual Serial Port
The main tab displays basic information about establishing the connection and its progress. Here you can create or delete a virtual serial port using the 'Create COM' and 'Delete COM' buttons respectively.
Click 'Show Log' to display the program log that can simplify troubleshooting.
* VSP frame
List of serial port settings.
* LAN frame
Displays Ethernet connection status.
* Counters frame
Volume of the data transferred and requests queued.
* IP Address
IP address of the remote serial port. The value can be taken automatically from the UDP tab.

* Port
Incoming port of the remote serial port device. Your PC opens the TCP/IP connection and sends data to this port.

* Port Name
Number of the Virtual Serial Port being created ' select a port number from COM2 to COM20.

* External NVT Commands Port
HW VSP opens the specified TCP port on your PC, where it receives NVT control commands for controlling I/O pins and passes them over the connection to the remote device.
For example, a proprietary utility processes barcode data and your program (e.g. the HWg SDK example) controls I/O pins through VSP and the specified port ' see the Block diagram.

If you need to create more virtual serial ports on a single PC, you can use the multi-port version of HW VSP.

Settings
The 'Settings' tab allows you to set up all functions supported by the virtual serial port.
Caution: These settings apply to the HW VSP utility only. They do NOT influence the remote device. Remote device properties are set according to its manual (e.g. via the Hercules utility in case of HW group products).
* Strict Baudrate Emulation
Limits the application-to-VSP and TCP-to-VSP transfer rate according to the baudrate of the open serial port.
* Log files enabled
Logs all communication to a .log file.
* TCP Server Mode
Activates VSP as a TCP/IP server. The driver then behaves as a TCP Client/Server device - this means that the first side to receive any data switches to Client mode and establishes the connection. In the TCP server mode, IP address is automatically preset to 0.0.0.0 and TCP port is set to current COM port number + 3000 (e.g. COM3 = TCP port 3003). The port can be changed. Pay attention to the firewall settings!
* Purge Buffers when Port is Opened
Clears transmit and receive buffers upon opening the port. This ensures that no leftover data from a previous session are sent or received. However, this also deletes any data received before the port is opened (e.g. during PC startup).
* Create VSP Port at HW VSP startup
If this box is checked, all virtual ports are recreated when HW VSP is started.
* Connect to device even if VSP Port is closed
If this box is checked, the connection is established immediately after the virtual port is created, even if no application is using the port. As a result, data sent when the port was open but unused will be lost. The device sends data even if you don?t 'listen' for them.
* Use NOP to Keep Connection
+ Renew automatically
Expects a testing NOP to check for module presence. If a module was unreachable and is rediscovered (starts to respond again), the connection is reestablished either immediately (?Renew automatically' checked), or as soon as VSP sends new data to the TCP socket (?Renew automatically' unchecked).
* NVT
Click 'NVT Enable' to enable RFC2217 support and detection of our remote ports. Remember to activate NVT support on the corresponding device as well. After activating NVT commands, it is possible to activate the following parameters in the same way:
*
* Remote port setup ' Sends control characters to the remote port through the VSP in your PC. For example, if your terminal program (e.g. Hyperterminal) changes the baudrate to 19200 Bd and NVT is active, the VSP driver sends a NVT command (according to the RFC 2217 standard) to the remote TCP/IP serial port and changes its baudrate as well.
* Keep Connection ' Your TCP device closes the TCP/IP connection after 50 seconds of inactivity. This function allows to keep the connection to the remote device alive (transmits 2 bytes every 5 seconds).
o Reconnect
Re-establishes the connection of the client interface to the service, e.g. when the connection is lost, or establishes the connection of the client interface to the remote service (that can run on a server).
o Save Settings to INI file
Saves current configuration in the INI file.
o Report VSP Setting
Displays current configuration of the remote device (if it has TCP Setup enabled on a standard port ' 99)

gerryk
Offline
Joined: 22 Oct 2009
Posts:

Slick! I can see many uses for this.

User login