-
AuthorPosts
-
09/04/2017 at 10:18 am #46853
Micun
MemberHello
first of all i want to congratulate on this project !
Im trying to connect my arduino MEGA 2560 board with Wonderware InTouch. Im using OPC Arduino 1.9 version, OPC library is 1.7, IDE is 1.8.2 .
I had problem with compailing sketch MEGA for OPC. When i try to upload it on board there is some error message: OPCItemType was not declared in this scope.
Code which i tried to upload is :code code:/*
* A generic sketch for use with the Arduino OPC or Visual OPC Builder from www.st4makers.com
*/
#include <OPC.h>
#include <Bridge.h>
#include <Ethernet.h>
#include <SPI.h>OPCSerial myArduinoMEGA;
opcAccessRights digital_status_input[54], analog_status_input[16];
bool readwrite_digital(const char *itemID, const opcOperation opcOP, const bool value)
{
byte port;OPCItemType aOPCItem = myArduinoMEGA.getOPCItem(itemID);
port = atoi(&itemID[1]);
if (opcOP == opc_opwrite) {
if ((aOPCItem.opcAccessRight == opc_write) || (aOPCItem.opcAccessRight == opc_readwrite)) {if (digital_status_input[port] != opc_write) {
pinMode(port, OUTPUT);
digital_status_input[port] = opc_write;
}digitalWrite(port,value);
}
}if (opcOP == opc_opread) {
if ((aOPCItem.opcAccessRight == opc_read) || (aOPCItem.opcAccessRight == opc_readwrite)) {if (digital_status_input[port] != opc_read) {
pinMode(port, INPUT);
digital_status_input[port] = opc_read;
}return digitalRead(port);
}
}
}int readwrite_analog(const char *itemID, const opcOperation opcOP, const int value)
{
byte port;OPCItemType aOPCItem = myArduinoMEGA.getOPCItem(itemID);
port = atoi(&itemID[1]);
if (opcOP == opc_opwrite) {
if ((aOPCItem.opcAccessRight == opc_write) || (aOPCItem.opcAccessRight == opc_readwrite)) {if (analog_status_input[port] != opc_write) {
pinMode(port, OUTPUT);
analog_status_input[port] = opc_write;
}analogWrite(port,value);
}
}if (opcOP == opc_opread) {
if ((aOPCItem.opcAccessRight == opc_read) || (aOPCItem.opcAccessRight == opc_readwrite)) {if (analog_status_input[port] != opc_read) {
pinMode(port, INPUT);
analog_status_input[port] = opc_read;
}return analogRead(port);
}
}}
void setup() {
Serial.begin(9600);myArduinoMEGA.setup();
for (byte k=0;k<54;k++) digital_status_input[k] = opc_undefined;
for (byte k=0;k<16;k++) analog_status_input[k] = opc_undefined;myArduinoMEGA.setup();
myArduinoMEGA.addItem("D2",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D3",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D4",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D5",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D5",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D6",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D7",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D8",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D9",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D10",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D11",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D12",opc_readwrite, opc_bool, readwrite_digital);//builtin led
myArduinoMEGA.addItem("D13",opc_write, opc_bool, readwrite_digital);myArduinoMEGA.addItem("D22",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D23",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D24",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D25",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D26",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D27",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D28",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D29",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D30",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D31",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D32",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D33",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D34",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D35",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D36",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D37",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D38",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D39",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D40",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D41",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D42",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D43",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D44",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D45",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D46",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D47",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D48",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D49",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D50",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D51",opc_readwrite, opc_bool, readwrite_digital); myArduinoMEGA.addItem("D52",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D53",opc_readwrite, opc_bool, readwrite_digital);myArduinoMEGA.addItem("A0",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A1",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A2",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A3",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A4",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A5",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A5",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A6",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A7",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A8",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A9",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A10",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A11",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A12",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A13",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A14",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A15",opc_readwrite, opc_int, readwrite_analog);
}void loop() {
myArduinoMEGA.processOPCCommands();
}Printscreen with error attached.
20/06/2017 at 7:48 pm #47555i.martinez
KeymasterHello
did you solved the issue? If not let me know
All the best
ilde20/06/2017 at 8:49 pm #47556Micun
MemberHello,
no, i didnt resolve it. I only had success with UnoLED sketch, after upload it on mega2560, i was able to control LED on mega from Wonderware app. But this above, shows error like i explane.
Best Regards,
Nikola27/06/2017 at 7:28 pm #47557Micun
MemberHello,
i resolve the problem by updating two files: OPC.h and OPC.cpp (i download it from your folder on https://github.com/SoftwareTools4Makers/OPC).
So, i download MEGA sketch from that folder too, and upload it on arduino well.
I succesfully add items on my SCADA app, i use Wonderware InTouch, but i have problem with Digital I/O.
Button going in ON and OFF position byself every few second. Only digital I/O D13, where is LED integrated works fine, but others digital I/O going in ON and then after few seconds in OFF position byself.
I dont know why, maybe is some problem in sketch, i will try to find out what happens..
Best regards,
Nikola04/07/2017 at 5:33 pm #47560i.martinez
KeymasterYes, sure the problem is in the sketch. I havent time to test it in deep. If you detect any issue, please let me know
all the best
ilde05/08/2017 at 11:23 am #47563Micun
MemberHello again,
i dont want to open new topic, i think this one have some same issues:
do you have maybe sketch for MEGA 2560 OPC through Ethernet?
I connected W5100 shield on my MEGA 2560 board, and im trying to connect it with opc but i have problem.
When i use sketch from library (EthernetShieldR3, EthernetShieldLED…) i cant reach opcItems (look at attached file). I use latest update of everything. I can ping ip of shield, but nothing of items.Best regards,
Nikola05/08/2017 at 3:12 pm #47564Micun
MemberIt was my fault. I made constantly mistake with IP address. I was write IP address which i found in Control Panel — Network manager … In details of Local Area Network, there was set one IP addresse (10.0.0.12), and i always put that IP in arduino sketch and that didnt work. After i written address 10.0.0.13 , everything was fine.
Maybe if there is somebody like me who is not good in this communications, this answer will help. 🙂Best regards,
Nikola06/08/2017 at 4:25 pm #47565Micun
MemberIf someone use ethernet shield on arduino Mega 2560, here is modified generic sketch for use with Mega and Arduino OPC server. Find it below:
code code:/*
* A generic sketch for use with the Arduino OPC or Visual OPC Builder from www.st4makers.com
*/
#include <OPC.h>
#include <Bridge.h>
#include <Ethernet.h>
#include <SPI.h>/*
* Declaring the OPC object
*/
OPCEthernet myArduinoMEGA;/*
* MAC address from Ethernet shield sticker under board
*/
byte mac[] = { 0xE8, 0x9A, 0x8F, 0xD9, 0xE7, 0x46 };/*
* Set your network configuration
*/
IPAddress ip(10, 0, 0, 13);
IPAddress gateway(10,0,0,1);
IPAddress dns_server(10,0,0,1);
IPAddress subnet(255,255,255,0);/*
* Server listen port
*/
const int listen_port = 80;opcOperation digital_status_input[54], analog_status_input[16];
bool readwrite_digital(const char *itemID, const opcOperation opcOP, const bool value)
{
byte port;port = atoi(&itemID[1]);
if (opcOP == opc_opwrite) {
if (digital_status_input[port] == opc_opread) {
digital_status_input[port] = opc_opwrite;
pinMode(port,OUTPUT);
}digitalWrite(port,value);
}
else
{
if (digital_status_input[port] == opc_opwrite) {
digital_status_input[port] = opc_opread;
// pinMode(port,INPUT);
}return digitalRead(port);
}}
int readwrite_analog(const char *itemID, const opcOperation opcOP, const int value) {
byte port;port = atoi(&itemID[1]);
if (opcOP == opc_opwrite) {
if (analog_status_input[port] == opc_opread) {
analog_status_input[port] = opc_opwrite;
pinMode(port,OUTPUT);
}analogWrite(port,value);
}
else
{
if (analog_status_input[port] == opc_opwrite) {
analog_status_input[port] = opc_opread;
//pinMode(port,INPUT);
}return analogRead(port);
}}
void setup() {
byte k;for (k=0;k<53;k++) digital_status_input[k] = opc_opread;
for (k=0;k<15;k++) analog_status_input[k] = opc_opread;/*
* OPC Object initialization
*/
myArduinoMEGA.setup(listen_port,mac,ip);myArduinoMEGA.addItem("D0",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D1",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D2",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D3",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D4",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D5",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D5",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D6",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D7",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D8",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D9",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D10",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D11",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D12",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D13",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D14",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D15",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D16",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D17",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D18",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D19",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D20",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D21",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D22",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D23",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D24",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D25",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D26",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D27",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D28",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D29",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D30",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D31",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D32",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D33",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D34",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D35",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D36",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D37",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D38",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D39",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D40",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D41",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D42",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D43",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D44",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D45",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D46",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D47",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D48",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D49",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D50",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D51",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D52",opc_readwrite, opc_bool, readwrite_digital);
myArduinoMEGA.addItem("D53",opc_readwrite, opc_bool, readwrite_digital);myArduinoMEGA.addItem("A0",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A1",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A2",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A3",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A4",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A5",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A6",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A7",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A8",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A9",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A10",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A11",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A12",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A13",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A14",opc_readwrite, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A15",opc_readwrite, opc_int, readwrite_analog);
}void loop() {
myArduinoMEGA.processOPCCommands();
}Best regards,
Nikola09/08/2017 at 6:05 pm #47566i.martinez
KeymasterThank you
I will take a look and incorporate it in the examples library if you dont mind
all the best and thanks
ilde17/08/2017 at 5:46 pm #47572Micun
MemberYes, ofcourse.
Im going to test communication between arduino and SCADA and reliability of arduino as well. I will try to improve it and if i find out something, i will share here.
Best regards,
Nikola -
AuthorPosts
- You must be logged in to reply to this topic.