A time ago, I wrote about how you could only read GPS data from a USB GPS device from one COM port and how I managed to handle GPS data on different virtual COM ports so that the GPS data could be used in different applications.
One of these applications is one in Java that I develop myself. However, the RxTx driver I’m using is a little unstable, especially when the connection is lost and you try to re-establish the connection to the Serial Port. So I tried to find a solution and hub4com actually offers one as well. You can actually route the GPS data, read from a physical COM port, to a tcp port so that you can create a network connection to the machine and fetch the GPS data from there.
You can enable filters in hub4com and one of these filters is the telnet filter over a tcp driver. I modified the command so that it looks like this:
hub4com --baud=9600 --route=0:All \\.\COM6 --baud=9600 \\.\CNCA0 --baud=9600 \\.\CNCA1 --baud=9600 \\.\CNCA2 --create-filter=telnet --add-filters=0:telnet --use-driver=tcp *10110 *10110 *10110 *10110"
This now means the following:
read at speed 9600 baud,
route the first specified COM port to all the others
the first specified COM port, which is the one that we’ll be reading from
write to these virtual COM ports with speed 9600 (the –baud parameter on these three lines might be omitted since you have specified hub4com to read at that speed)
Create a telnet-filter so that hub4com can answer telnet-like
redirect the input from the first specified COM port (COM6 in our case) to the telnet session
--use-driver tcp *10110 *10110 *10110 *10110
this will use tcp for communication and will listen on port 10110. Four concurrent telnet sessions on port 10110 are possible. If you only specify one *10110, only one connection at the same time will be allowed.
This now allows me to create a tcp connection on port 10110 and read the NMEA data from there. Much more stable.
Now, to wrap this all up into a windows service, I run the following bat file (everything on one line) to install that service:
@RunAsSvc.exe --install --displayname "hub4com" --description "Routes the GPS data from COM6 to virtual COM14, COM15 and COM16 and allows 4 telnet connections to the raw NMEA data" --exe "C:\com0com\hub4com.exe" --params "--baud=9600 --route=0:All \\.\COM6 --baud=9600 \\.\CNCA0 --baud=9600 \\.\CNCA1 --baud=9600 \\.\CNCA2 --create-filter=telnet --add-filters=0:telnet --use-driver=tcp *10110 *10110 *10110 *10110" --workingdir "C:\com0com"
The service now launches on system startup and I can use multiple COM ports as well as 4 concurrent telnet sessions to the host on which the GPS is connected. telnet localhost is more stable to use in Java than RxTx (at the moment of writing)