Main Site Documentation

Project - SerialBridge - TCP to RS232 bridge


I just posted SerialBridge - TCP to RS232 bridge on Codeshare. Feel free to discuss and make suggestions here.


Very cool !!! Thank you for sharing. Think this is very useful, have to try as soon as possible.


Nice one!


yes, very useful for sure.


To use just the improved LineReceived Method for reading lines from the serial port, you can just use the serialPort_ReadLineThread Method in SugaredSerial.cs. Just start up the thread:

serialPort_readLineThread = new Thread(() => serialPort_ReadLineThread(serialPort));

and define a method to process the lines:

private void serialPort_LineReceived(Serial sender, string line)


@ eolson - This is very cool.

This reminded me of a system I worked on in the early 90’s. We used serial coms tunneled over TCP/IP for connecting to serial devices over the WAN (Microwave links etc. I got a funny story about the line of site microwave links). It is so cool that the technology that wowed us years ago can now be built in our garages.


And we need it so we can control stuff with our phones!


I just came across this code. I have a quick question about it.

As 4.2 currently does not support PPP, could your code be used to connect the internal TCP/IP stack to a GPRS modem where I would use the AT commands to make a TCP/IP connection to a server?

Eg, I talk to the modem initially to make the dial up connection to a server using the IP address and port of my server. Once I get back the connection was completed, I pass of the serial port to your code. Now in theory, I then use normal TCP/IP packets to talk to the server.

Will this idea work or will I have to consider modifying you code to achieve this? I have only just downloaded it and not had a chance to look at the code as yet! :slight_smile:


@ Dave McLaughlin - I see you are still struggling with cellular module… :wall:


If I understand your problem correctly, you would need to add code to generate the packets.
You want to communicate tcp protocols over serial?

This code is really about communicating with serial-like protocols over either serial or tcp.
It adds three features that would otherwise complicate serial communication
1) send data and wait for response with timeout
2) enforce a minimum delay between messages (prevent buffer overrun)
3) thread-safe environment for multiple senders & multiple receivers with same device
plus it provides the same API for communication over tcp (sugaredTcp is a tcp client)

I use this to communicate with audio equipment. Some use rs232, some use tcp, and some can use either. These devices may communicate directory or indirectly with each other.

ex 1) Pioneer receiver is rs232 or tcp - So I communicate using the sugaredPort class - I just instance wither a sugaredSerial or a sugaredTcp, depending on how I hook it up. (works the same)

ex 2) iPhone (tcp) wants to communicate with a NuVo amp (rs232). The messages are the same. I instance the sugaredSerial/sugaredPort to talk to the NuVo and instance a tcpBridge (tcp server). Now messages are relayed between the rs232 and tcp port. e.g. iPhone app can now control the amp!

ex3) Pioneer (tcp/serial) communicates with the Nuvo amp (rs232) using completely different commands. I instance a sugaredPort for each and then write custom code to translate the conversation between them. (e.g. nuvo zone 17 volume=50% => pioneer main volume=-20db)


As it happens Niels, I need the fix for this damn RSR232 overruns before I can get into it properly. Because of that I can’t run the serial port fast enough to do TCP/IP. 19200 is not reliable and 9600 is too slow.

I’ve just ordered some G400 modules (thanks to GHI discount) to try and get this working on my current hardware.