Hello,
For my personal project (windmill :
www.windmolensite.be) I'm trying to use an Arduino to read real-time data from the PLC controlling my windmill.
I figured out how the PLC 'hostlink' protocol works and did some simple tests using an RS232 serial cable and my laptop using a terminal program.
PC --> Serial Cable --> PLC
The terminal connection settings are 9600, 7 Data bits, Even Parity and 2 Stop bits.
When I send the command : @00TS123443* the PLC responds with the same string : @00TS123443* (This is for testing purpose)
https://www.dropbox.com/s/40a3wvip5coo480/PLC_from_PC.JPGNo I would like to get the same thing working with my Arduino.
Arduino --> WaveShare RS232 shield --> Serial Cable --> PLC (The shield has it's RX and TX pins connected to the Arduino pins 16 (TX2) and 17 (RX2), VCC and GND to 3v3 and GND)
But in this setup, it isn't working.
https://www.dropbox.com/s/ccvq22yf3hnt43h/PLC_from_PC_Arduino.JPGThe code, as you can see it basic :-)
/*
PLC
*/
int incomingByte = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize Serial1
Serial.begin(9600); //For debugging, towards PC
if (Serial) {
Serial.println("Connected to Computer!");
}
Serial2.begin(9600,SERIAL_7E2); //SERIAL_7E2 = 0x2C, see HardwareSerial.h
Serial.println("Waiting for Serial2...");
}
// the loop routine runs over and over again forever:
void loop() {
Serial2.println("@00TS123443*");
while (Serial2.available() > 0) {
incomingByte = Serial2.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
delay(1500);
}
If I connect the Arduino to a serial port on my PC, I can see the correct string being sent by the Arduino.
Arduino --> WaveShare RS232 shield --> Serial Cable --> Serial-to-USB adapter --> PC
https://www.dropbox.com/s/2ssoqbnpxuit077/PC_from_Arduino.JPGAny ideas where to look?
Regards,
Andy