Hello everybody,
Currently in Vietnam for an intership I'm trying to communicate with a PLC from Ditel and my Arduino nano. here is the datasheet of the PLC : ftp://ftp.cmdl.noaa.gov/aerosol/ugr/etc/Ditel_PID_SZ48-SZ49_Modbus.pdf
I have to use an Half-duplex RS485 modbus protocol, so I'm using a MAX485 in order to adjust the voltage level of my frame.
I'm trying to send the frame on page 33 of the datasheet.
// Pin 2 of tharduino connected to pins RE&DE of MAX485
#include
SoftwareSerial mySerial(10, 11); //RX, TX
#define switchPin 2
#define rxPin 10
#define txPin 11
byte req[]= {0x02, 0x04, 0x00, 0x00, 0x00, 0x01, 0x31, 0xCA}; // Frame to send in order to read the PV value of the PLC
byte RS485Byte = 0;
void setup() {
// Communication at 9600 b/s
Serial.begin(9600);
// pin tx to send data
pinMode(txPin, OUTPUT);
// pin rx to receive data
pinMode(rxPin, INPUT);
pinMode(switchPin, OUTPUT);
mySerial.begin(9600);
digitalWrite(switchPin, HIGH); // Pin 2 High level in order to send data
mySerial.write(req, sizeof(req));
mySerial.flush();
digitalWrite(switchPin, LOW);// Pin 2 Low level in order to receive data
}
void loop() {
if( mySerial.available()>0)
{
RS485Byte = mySerial.read();
Serial.print("incoming Bytes : "); Serial.println(byte(RS485Byte), HEX);
}
}
And the anwser I have on the monitor is incoming Bytes : 0.
I was wondering if I have to use the Modbus master library to send data or if anything was wrong in my code ...
( sorry for my bad english..)
Thanks for your help !
Have a nice day