Go Down

Topic: Arduino Mega 2560 via RS232 to Omron PLC (Read 2 times) previous topic - next topic

angeraer

#10
Feb 23, 2013, 01:50 pm Last Edit: Feb 23, 2013, 01:54 pm by angeraer Reason: 1
Hey Pylon,

Thanks for the input. Took me a while to test again, but I've succeeded to get the Arduino to read out the PLC! It was all a matter of cabling (see attachement).

I'm able to read/set the configuration of the PLC.

Code: [Select]

/*
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...");
 Serial2.println("@00RD0100000354*");
}

// the loop routine runs over and over again forever:
void loop() {

 while (Serial2.available() > 0) {
   incomingByte = Serial2.read();
   Serial.print("I received: ");
   Serial.write(incomingByte);
   Serial.println(".");
  }
  delay(2000);  
}


If I run it, it gives me the expexted result :

Code: [Select]

Connected to Computer!
Waiting for Serial2...
I received: @.
I received: 0.
I received: 0.
I received: R.
I received: D.
I received: 0.
I received: 0.
I received: 9.
I received: 8.
I received: 7.
I received: 6.
I received: 1.
I received: 2.
I received: 3.
I received: 4.
I received: 8.
I received: 0.
I received: 0.
I received: 0.
I received: 5.
I received: A.
I received: *.
I received:
.


Thanks a lot for the assistance!

Andy



Go Up