Skip to Content

RS232 is a standard for serial communication that has been widely used for connecting computers and peripheral devices. This point-to-point communication standard operates through a defined set of electrical characteristics and signal functions, allowing the transmission of data one bit at a time along a single data line. 

While its simplicity and reliability have made it a longstanding choice in many applications, RS-232 is typically limited to short distances and low speeds. In addition, it is designed to allow the transmission of data between a DTE (data terminal equipment) and a DCE (data communication equipment), which means it only support communication between 2 devices at a time.

The Arduino based Industrial Shields PLCs feature RS232 communication, leveraging an RS232 transceiver (the MAX232) and a serial port of the Arduino in the PLC. As such, the RS232 usage is really similar to the one of common Serial TTL ports.

Hardware

RS232 uses unbalanced (single-ended) signaling: data is transmitted in the form of voltage levels over a single wire relative to a common ground. Therefore, it uses 2 cables to achieve full-duplex communication, TX and RX, and it requires a common ground between the devices.

The connections between devices are:


Depending on the PLC, the steps needed to configure the RS232 are different. Follow the procedure according to your PLC model:

Remember to properly power the PLC with a 12-24V power supply.


Software

The industrialshields boards package includes an RS232 library to make programming easier. This library is used as the Arduino Serial library, with methods such as available(),​ read(), write(), etc.

The following example establishes a RS232 communication and allows the user to read or send messages from the terminal of the PC:

#include <RS232.h>

void setup() {
  // Begin Serial port
  Serial.begin(9600);
  // Begin RS232 port
  RS232.begin(38400);
}

void loop() {
  //Send one byte for the serial, receive this byte by rs485
  if (Serial.available()){
    read_from_serial();
  }
  if (RS232.available()){
    read_from_rs232();
  }
}

static void read_from_serial(void){
  char tx = Serial.read(); //Read byte
  if (tx != '\n') Serial.println(tx); //Print the byte 
  RS232.write(tx); //Transmit by rs485
}

static void read_from_rs232(void){
  char rx = RS232.read(); //Receive the same byte
  if (rx != '\n') {
    Serial.println(rx); //Print the byte
  } 
}
API Reference

Description:

Initializes the communication with specified baud rate and serial configuration. Must be called before any other communication functions.

Syntax:

RS232.begin(baudrate, config);

Parameters:

  • RS232: The RS232 object.
  • baudrate: The baud rate for the communication.
  • config: The serial configuration (data bits, parity, and stop bits). Default is SERIAL_8N1 (8 data bits, no parity, 1 stop bit).

Returns:

Nothing.

Description:

Checks if there are any bytes available to read from the RS232 buffer.

Syntax:

RS232.available();

Parameters:

  • RS232: The RS232 object.

Returns:

Returns the number of bytes available to read.

Description:

Reads a byte from the RS232 buffer.

Syntax:

RS232.read();

Parameters:

  • RS232: The RS232 object.

Returns:

Returns the byte read from the RS232 buffer, or -1 if no data is available.

Description:

Writes a byte or a buffer of bytes to the RS232 bus.

Syntax:

RS232.write(value);
RS232.write(buff, len);

Parameters:

  • RS232: The RS232 object.
  • value: The byte to be transmitted over RS232.
  • buff: A pointer to the buffer of bytes to be transmitted.
  • len: The number of bytes to transmit from the buffer.​

Returns:

Returns the number of bytes written.

Rating
0 0

There are no comments for now.

to be the first to leave a comment.