Serial Sockets
I mentioned last time that serial ports, while on the wane, are still around in one form or another, especially in the embedded world. Although official support in Java for the serial port is anemic, there is good third-party support and so if you want to use Java, you can use the serial port.
Where Java shines, of course, is network programming. Not only that, most languages have good support for networking thanks to the Internet fad (I'm kidding — even I don't think it's a fad). It might be nice if you could treat a serial port like a network socket. Then you could use a wide range of tools to access it. Besides that, if you could run a server that managed the socket, you could place the server and the serial port in one place and then access it from anywhere on the network.
Sounds like a good idea? It is such a good idea that there are several implementations of it and an RFC (RFC 2217). If you use Linux, there is a program called sredird that you can either build or get from most distributions. If you read the RFC, the protocol is essentially Telnet with extensions, so it is easy enough to access the port remotely. Barring that, Kermit has support for working as a client if you like.
There are plenty of other options. For example, ser2net and serialoverip are both on SourceForge. If you want a client in Java, check out jvser.
Another option is to use socat, which is a bit like a Swiss Army knife and will work as both client and server. For example, I have a 3D printer that has a virtual serial port connected to a remote computer. On that computer I run (all one line):
socat tcp-l:54321,fork,reuseaddr open:/dev/ttyACM0,raw,nonblock,waitlock=/tmp/acm0.locak,echo=0,b115200,crnl
This opens a TCP socket on 54321 and connects it to the serial port at /dev/ttyACM0 at 115,200 baud.
Assuming the remote machine is at address remote_computer
, on my desktop computer I run:
sudo socat pty,link=/dev/ttyUSB99,echo=0,raw,crnl tcp:remote_computer:54321
This produces a virtual ttyUSB99 port and most software will treat it like a serial port. Of course, you can easily replace that with your own socket manipulation code, if you prefer.
If you are a Windows user, you might be more interested in com0com, which includes com2tcp that performs a similar function. The hub4com even supposedly supports RFC2217, although I haven't tried it.
With the preponderance of cheap Linux boards like the Raspberry Pi, standing up a little serial server to put a serial device on the network isn't a big deal. It is one more reason serial ports aren't dead quite yet.