The ACE with 2 serial ports can be used as a serial gateway. However, that can work between 1 USB port (Slave Modbus) and 1 ASCII serial port.
If you want for example to convert a serial message from an equipment which include data to another serial equipment with the same data.
This can be used with different speeds and parities parameters.
For this operation you must have an ACE PLC with 2 RS232 or RS485 port.
You must link each serial port to your devices.
|RX to TX
TX to RX
GND to GND
Add GatewaySerialSub program to your ACE with vBuilder.
This program is for ACE 7096x version. Check the version in the “Setup Hardware”. Change it if needed.
You must also configure the serial port as “Custom type” and all other parameters depending of your equipments configurations.
How does the program work ?
The program is a subroutine called “SerialA1toA2”.
In the main program, we call this subroutine at each program cycle.
“NbMess.Processed” (in the main program) and “NbMessagReceived” (in the subroutine) is the number of messages processed. This is just for information.
In our case here, the length of the received message is 14. The length of the message sent is 42. You must adjust these values for your application according to the length of your messages.
The tags “ReceivedArray” and “SendArray” are arrays of size respectively 14 and 42.
The values in the array tags must be in decimal. See https://en.wikipedia.org/wiki/ASCII
In the subroutine, you have different state :
- State 0: We open and listen to the serial port A1.
- State 1: We check if any message arrives. If nothing arrives after “MyTimer“, we reopen the serial port (State 0).
- State 2: The message from A1 port is already in “ReceivedArray”. We create the new message and send it to the A2 serial port.
In this example bellow, the new message sent (“SendArray”) contains fixe values and values from the “ReceivedArray”.
- State 3: Once the message is sent to the A2 serial port, we increment the number of messages received and we return to listen (State 0)
In this image bellow, we can see the value “+1234567” form “ReceivedArray” copied to “SendArray”