-
Notifications
You must be signed in to change notification settings - Fork 0
/
opc_analog.ino
62 lines (49 loc) · 2.08 KB
/
opc_analog.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* 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 analog_status_input[16];
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_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();
myArduinoMEGA.addItem("_",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A0",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A1",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A2",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A3",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A4",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A5",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A5",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A6",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A7",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A8",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A9",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A10",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A11",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A12",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A13",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A14",opc_read, opc_int, readwrite_analog);
myArduinoMEGA.addItem("A15",opc_read, opc_int, readwrite_analog);
}
void loop() {
myArduinoMEGA.processOPCCommands();
}