|
|
請問有人用過, Arduino OPC tools for makers 嗎? 附上: http://www.opcmakers.com/
通過他們發放的CODE 和 OPC程式, 成功使OPC SERVER 和 ARDUINO 通訊.
但是有些功能不知道能否做到,
在OPC SERVER中修改了的值,能否傳回ARDUINO 來當作PID 的SETPOINT呢?
如果可以, ARDUINO CODE 那邊要如何修改?
希望有大能解答...謝謝
附上測試用的CODE,
#include <OPC.h>
#include <OPCSerial.h>
#include <SPI.h>
#include <Ethernet.h>
OPCSerial aOPCSerial;
int DOPin = 13;
bool callback(const char *itemID, const opcOperation opcOP, const bool value){
static bool DOValue = false;
if (opcOP == opc_opwrite) {
DOValue = value;
if (DOValue)
digitalWrite(DOPin, HIGH);
else
digitalWrite(DOPin, LOW);
}
else
return DOValue;
}
float item_float_asc(const char *itemID, const opcOperation opcOP, const float value){
static float AO1Value = 0;
if (opcOP == opc_opwrite) {
AO1Value = value;
}
else
return AO1Value;
}
float AI(const char *itemID, const opcOperation opcOP, const float value){
static float AI1Value = 0;
if (opcOP == opc_opwrite) {
AI1Value = value;
}
else
return AI1Value;
}
float item_float_asc2(const char *itemID, const opcOperation opcOP, const float value){
static float Output = 0;
if (opcOP == opc_opwrite) {
Output = value;
}
else
return Output;
}
void setup() {
Serial.begin(9600);
pinMode(DOPin, OUTPUT);
aOPCSerial.setup();
aOPCSerial.addItem("DO1",opc_read, opc_bool, callback);
aOPCSerial.addItem("AO1",opc_read, opc_float, item_float_asc);
aOPCSerial.addItem("AI1",opc_read, opc_float, AI);
aOPCSerial.addItem("Output",opc_read, opc_float, item_float_asc2);
}
void loop() {
aOPCSerial.processOPCCommands();
}
|
|