Multiple serial ports communicating through one

Hi,

So my problem is I have an old PLC that is at full capacity with only a single RS232 channel. Is it possible to use the plc to send/receive from its one channel to an arduino with multiple serial channels if i were to use Ch-1 on the arduino as a "middle man" which would perform the following tasks.

  • Receive string from the PLC on Ch-1 which would have a destination character at the beginning which would need to be removed then forwarded to the corrosponding channel.

  • Receive string from a device on Ch-2/3/4 add a channel ID character to the start of the string and then send it out from Ch-1 to the PLC.

I am aware there will be certain issues that arise regarding instances that happen at the same time and for this its not really an issue if data was missed as i can program around that. If it helps the devices would be a label scanner, a printer and a laser engraver.

Please forgive me for any incorrect terminology or stupid assumptions. I have very little arduino knowledge so i'd just like someone to confirm this is possible before giving myself an unnecessary headache.

Thanks.

sounds like a translator, should be easy

each serial port on an Arduino Mega would buffer any input so there should be little chance of losing any

1 Like

Yes, that is certainly possible. You will need a board with multiple UARTs and the Mega would be one of the candidates. Note that a Mega communicates with a PC via USB which is connected to the first UART (your CH-1). If you connect anything to that UART (pins 0 and 1) it will interfere with uploads; so you will have to disconnect during upload.

You can test by sending data from the PC (just don't connect the PLC to the first UART).

Notes

  1. Arduino's don't use RS232; you'll need a converter (in case you were not aware of it).
  2. There is a 64 byte buffer for each UART implemented in the core (might even be bigger for the Mega, can't look now).
1 Like

Yes the mega is what i thought would probably need with the 232 shields. The next battle will be getting my head around the program :upside_down_face:
Thanks Guys.

maybe something like this

char buf [90];

byte id;

void
checkSerial (
    HardwareSerial &serial )
{
    if (serial.available ())  {
        int n = serial.readBytesUntil ('\n', & buf [1], sizeof(buf)-2);
        buf [n] = '\0';

        buf [0] = id;
        Serial.write (buf, n+1);
    }
}

void loop ()
{
    if (Serial.available ())  {
        int n = Serial.readBytesUntil ('\n', buf, sizeof(buf)-1);
        buf [n] = '\0';

        id = buf [0];

        Serial1.write (& buf [1], n-1);
        Serial2.write (& buf [1], n-1);
        Serial3.write (& buf [1], n-1);
    }

    checkSerial (Serial1);
    checkSerial (Serial2);
    checkSerial (Serial3);
}


void setup() {
    int bps = 9600;
    Serial.begin  (bps);    
    Serial1.begin (bps);    
    Serial2.begin (bps);    
    Serial3.begin (bps);    
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.