views:

4749

answers:

7

Thank you in advance. I need to get data from the serial port of a linux system and convert it to TCP/IP to send to a server. Is this difficult to do? I have some basic programming experience but not much experience with Linux. Are there any open source applications that do this?

Again thank you for any help.

A: 

You might find this usefull for the TCP / IP-part and the serial ports you might get a lot of help here. Keep in mind, everything in linux is "a file" so you could probably "cat" the serialport.

Filip Ekberg
A: 

You might find Perl or Python useful to get data from the serial port. To send data to the server, the solution could be easy if the server is (lets say) a HTTP app or even a popular database. The solution would be not so easy if it is some custom/proprietary TCP application.

Bash
+9  A: 

You don't need to write a program to do this in Linux. Just pipe the serial port through netcat.

netcat www.example.com port < /dev/ttyS0

Just replace the address and port information. Also, you may be using a different serial port (i.e. change the /dev/ttyS0 part). You can use the stty or setserial commands to change the parameters of the serial port (baud rate, parity, stop bits, etc.).

Judge Maygarden
Typo: change "< cat /dev/ttyS0" to just "< /dev/ttyS0".Function: Might put it in a shell script while : do netcat ... doneIf there is danger of the file I/O ending, e.g. if it's a modem, loses carrier, etc.
Liudvikas Bukys
You might also want to look at socat
Douglas Leeder
I changed the snippet per Liudvikas. I didn't get a chance to check it last night because of the 3 week old baby at the house!
Judge Maygarden
This should work as written. I added links on ways to setup the serial port parameters too.
Judge Maygarden
A: 

I think your question isn't quite clear. There are several answers here on how to catch the data coming into a linux's serial port, but perhaps your problem is the other way around? If you need to catch the data coming out of a linux's serial port and send it to a server, there are several little hardware gizmos that can do this, starting with the simple serial print server such as this [lantronix gizmo][1]

No, I'm not affiliated with Lantronix in any way.

[1]: http://www.lantronix.com/device-networking/external-device-servers/mss100.html "

Shannon Nelson
+2  A: 

Stumbled upon this question via google search for a very similar one (using the serial port on a server from a linux client over TCP/IP), so, even though this is not an answer to exact original question, some of the code might be useful to the original poster, I think:

  • Making a linux box with a serial port listen on the TCP port to share the modem: ser2net
  • Using this "shared" modem from another linux workstation: remtty
Andrew Y
I got here the same way; +1 for providing a link to ser2net, it looks like what I was looking for.
Dennis
A: 

I had the same problem. I'm no t quite sure about open source applications, but I have tested command line Serial over Ethernet for Linux and... it works for me.

Also thanks to Judge Maygarden for the instructions

Garsia
A: 

You can create a Serial-Over-Lan (SOL) connection by using socat. It can be used to 'froward' a ttyS to another machine so it appears as a local one or you can access it via a TCP/IP port.

Indie