-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduPLC.ino
More file actions
83 lines (80 loc) · 1.75 KB
/
ArduPLC.ino
File metadata and controls
83 lines (80 loc) · 1.75 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// PlcRework.cpp : Diese Datei enthält die Funktion "main". Hier beginnt und endet die Ausführung des Programms.
//
#include "PlcIncludeAll.h"
#include "PlcSample.h"
PlcStdIO* io;
PlcMachine machine;
class Example : public PlcProcess
{
public:
enum commands { run , stop , list,last};
int btn1;
int stopwatchTempValue;
int measuredTime;
int clockRun;
int clockTick;
int clockResult;
void onRegisterIO(PlcIO* io)
{
io->addCommands(command, last, "run", "stop","list");
io->add(btn1, "btn1");
io->add(measuredTime, "measured time");
io->add(clockTick, "clock tick");
}
Example()
{
clockTick = 0; clockRun = 0; measuredTime = 0;
}
void onMessage(PlcIO* plcIO, PlcAdapter* adapter, int index)
{
if (adapter->isCommand() && adapter->origin == true)
{
switch (adapter->getIntValue())
{
case run:
clockRun = true;
this->println("clock start");
break;
case stop:
clockRun = false;
this->println("clock stop");
break;
case list:
syncInit();
break;
}
}
int u = 0;
}
void onTask()
{
/*PLC Node Calls e.g.clock, ... must not be used within if statemnts or loops.
Only linear sequences are permitted !!!!
forbidden example:
if (condition)
{
a = clock(1000);
b = clock(2000);
}
*/
stopwatchTempValue = stopwatch(btn1);
if (fall(btn1))
{
measuredTime = stopwatchTempValue;
clockRun = true;
}
clockResult= clock(measuredTime);
clockTick = clockRun & clockResult;
}
} example;
void setup() {
printStream.begin(9600);
io = new PlcStdIO(&printStream);
example.registerIO(io);
machine.registerProcess(&example);
PlcStream *st;
PlcBugStream* m;
}
void loop() {
machine.tick();
}