I am trying to communicate PLC with arduino through rs232 as well rs 485. But, I am not able to read and write data. I can observe the data in PLC through ladder logic but not in arduino. I am trying to implement the Modbus ASCII here but reading and writing both is not happening.
#include <EmSevenSegment.h>
#include<SoftwareSerial.h>
EmSevenSegment disp(4, 'C', 4, 3, 2);
SoftwareSerial debuggingSerial(0, 1); //RX,TX
[![enter image description here][1]][1]String readlineString = "";
String integerString = "";
String decimalString = "";
String outputString = "";
char startChar = 0x01;
char endChar = 0x01;
//char weight[10];
void setup() {
Serial.begin(9600);
debuggingSerial.begin(9600);
}
void loop() {
Serial.print("!!!!!!!!!!11111111111\n");
delay(1000);
if (debuggingSerial.available())
{
Serial.print("!!!!!!!!!!2222222222\n");
readlineString = debuggingSerial.readString();
Serial.print(readlineString);
}
if (readlineString.length() > 0)
{
Serial.print("!!!!!!!!!!333333333333\n");
integerString = readlineString.substring(10, 12);
decimalString = readlineString.substring(13, 15);
int number = (integerString + decimalString).toInt(); // 6789; //Number to be displayed
disp.print(number); // Print the number
Serial.print(readlineString);
readlineString = "";
}
}
Please find the image of rs232 connection:
