Has anyone tried to connect an Arduino to ignition scada through OPCDA ?
Arduino is connected through a serial port and I have Arduino OPC server already installed and functioning as well as output parameters can be read by external sources OPC client/explorer applications.
However, when I try to connect to the OPC server from the gateway (opc connections - opc da connection) it displays connecting and does not connect .
Is there any further configurations that I should go through?
Here is the code of the Arduino:
#include <OPC.h>
// declare opc object
OPCSerial aOPCSerial;
// declare pins that will be in use
int ledPin = 7;
int buttonPin = 2;
int analogPin = 0;
char ledState = 0;
// callback function
int callback1(const char *itemID, const opcOperation opcOP, const int value){
static int ledValue = ledState;
if (!strcmp(itemID,"led"))
{
// if a write
if (opcOP == opc_opwrite) {
/*ledValue = ledState;*/
if (ledValue)
digitalWrite(ledPin, HIGH);
else
digitalWrite(ledPin, LOW);
}
else
/*
* read the led status
*/
return ledValue;
}
if (!strcmp(itemID,"button"))
{
return digitalRead(buttonPin);
}
}
int callback2(const char *itemID, const opcOperation opcOP, const int value){
if (!strcmp(itemID,"analog0"))
{
return analogRead(analogPin);
}
}
void setup() {
Serial.begin(9600); // serial comms
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, OUTPUT);
aOPCSerial.setup(); // opc init
// declare items
aOPCSerial.addItem("led", opc_readwrite, opc_bool, callback1);
aOPCSerial.addItem("button", opc_read, opc_bool, callback1);
aOPCSerial.addItem("analog0",opc_read, opc_int, callback2);
}
void loop() {
// Read the analog value from A0
int analogValue = analogRead(analogPin);
// If the analog value is less than 500, turn on the pump
if (analogValue < 500) {
digitalWrite(buttonPin, HIGH); // turn on the pump
ledState = 1;
} else {
digitalWrite(buttonPin, LOW); // turn off the pump
ledState = 0;
}
// start processing of opc commands
aOPCSerial.processOPCCommands();
}