Turn your serial equipment into Internet-connected devices, with a converter that transform data between Serial and TCP.


Introduction

If you look closely, you can see that there are tons of serial devices over there in the real world, not to mention that most of industrial devices still use serial interfaces. Even in the era of IoT, serial devices are here to stay. Serial communication is simple, cost-efficient, reliable, and is life-saving if you need to get the console access to the device.

The good news I am trying to sell here is, with the help of PHPoC board, we can easily make serial devices become Internet-connected, so that in case of need, we can connect and access them from wherever we want.

In this project, I will show you how I made a Serial to TCP converter (to be more specific, RS232 to TCP) by using a PHPoC Black and a PHPoC RS232 Smart Expansion Board. The working scenario is quite simple: any TCP data bypass Ethernet connection is transformed to serial data, forward to RS232 interface, and vice versa.


System Architecture

System Architecture

Application scheme

Application scheme
Hardware setup

In this project, I use one PHPoC Black board and one PHPoC RS232 Smart Expansion board (PES-2406).

The first thing we need is to add RS232 interface to PHPoC board. Just stack a PES-2406 board on top of a PHPoC Black. Done!

A PHPoC Black supports Ethernet connectivity, so an Ethernet cable is enough. In case of PHPoC Blue, it can be used as a Wi-Fi to RS232 converter. In fact, it can be Wi-Fi or Ethernet to RS232/RS422/RS485 depending on your choice of hardware components.

Each RS232 Smart Expansion Board has an RS-232 port. The expansion board is addressed by ID, which can set by manually setting DIP switches. As you can see in the photo below and also in the source code, I set the ID as 2.

With a little more effort, you can even make a Serial Ethernet gateway, since a PHPoC Black can carry up to 14 smart expansion boards and support up to 5 TCP connections simultaneously.

PHPoC Black + RS232 Smart Expansion Board

PHPoC Black + RS232 Smart Expansion Board
Working flow

In my project, I made the PHPoC board a TCP server, so that my board can listen to the connections from TCP clients via Ethernet.

There isn't much to say about configuring serial connection. Just setup the serial parameters, and it is almost done.

The working flow is straightforward. PHPoC reads the incoming data from serial, then forward it to the connected TCP client. On the other hand, it reads the incoming data from TCP client and forward to serial interface. And we just need to make sure this happens in a loop.

The photo below is a simple demonstration:

Serial TCP Converter's demonstration




You can get the full source code here

Cheers