author | Edouard Tisserant |
Thu, 27 Aug 2020 09:59:35 +0200 | |
branch | svghmi |
changeset 3042 | ed43facc7137 |
parent 3038 | 92101729f7b7 |
child 3046 | d1bb0c09e412 |
permissions | -rw-r--r-- |
2983
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
1 |
<?xml version='1.0' encoding='utf-8'?> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
2 |
<PyFile xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
3 |
<variables> |
3034
793ce2117258
SVGHMI: JsonTable now makes meaningfull JSON request : all arguments and variables are passed in.
Edouard Tisserant
parents:
3031
diff
changeset
|
4 |
<variable name="AlarmNotify" type="HMI_INT"/> |
3036
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
5 |
<variable name="SendAlarm" type="HMI_BOOL" onchange="TriggerAlarm"/> |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
6 |
<variable name="AlarmText" type="HMI_STRING" initial="'POS'"/> |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
7 |
<variable name="AlarmStatus" type="HMI_STRING" initial="'alarm'"/> |
2983
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
8 |
</variables> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
9 |
<globals> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
10 |
<xhtml:p><![CDATA[ |
2994
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
11 |
from twisted.web.resource import Resource |
3036
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
12 |
import json, time, random |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
13 |
|
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
14 |
Alarms = [] |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
15 |
|
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
16 |
def TriggerAlarm(changed_var_name): |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
17 |
global Alarms |
3038
92101729f7b7
SVGHMI: Alarm test not using Button widget anymore, too many problems. Use Input widget instead to increment value on each click and execute python code on change.
Edouard Tisserant
parents:
3036
diff
changeset
|
18 |
Alarms.append((time.time(), PLCGlobals.AlarmText, PLCGlobals.AlarmStatus)) |
92101729f7b7
SVGHMI: Alarm test not using Button widget anymore, too many problems. Use Input widget instead to increment value on each click and execute python code on change.
Edouard Tisserant
parents:
3036
diff
changeset
|
19 |
PLCGlobals.AlarmNotify = random.randint(0, 4294967296) |
2994
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
20 |
|
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
21 |
class AlarmJsonResource(Resource): |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
22 |
def render_GET(self, request): |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
23 |
return '' |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
24 |
|
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
25 |
def render_POST(self, request): |
3036
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
26 |
newstr = request.content.getvalue() |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
27 |
newdata = json.loads(newstr) |
2994
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
28 |
print newdata |
3036
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
29 |
vars = newdata[u'vars'] |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
30 |
args = newdata[u'args'] |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
31 |
visible = newdata[u'visible'] |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
32 |
svars = (vars + [0,0])[:3] |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
33 |
range_feedback = svars[1] |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
34 |
slider_position = svars[2] |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
35 |
answer = self.renderTable(range_feedback, slider_position, visible, *(args+svars[3:])) |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
36 |
janswer = json.dumps(answer) |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
37 |
print janswer |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
38 |
return janswer |
2994
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
39 |
|
3036
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
40 |
def renderTable(self, old_range, old_position, visible, *options): |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
41 |
new_range = len(Alarms) |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
42 |
delta = new_range - visible |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
43 |
new_position = 0 if delta <= 0 else delta if old_position > delta else old_position |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
44 |
new_visible = new_range if delta <= 0 else visible |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
45 |
|
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
46 |
visible_alarms = [] |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
47 |
for ts, text, status in Alarms[new_position:new_position + new_visible]: |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
48 |
visible_alarms.append({ |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
49 |
"time": time.ctime(ts), |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
50 |
"text": text, # TODO translate text |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
51 |
"status": status |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
52 |
}) |
2983
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
53 |
|
3036
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
54 |
return new_range, new_position, visible_alarms |
4930455428df
SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents:
3034
diff
changeset
|
55 |
|
2983
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
56 |
|
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
57 |
]]></xhtml:p> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
58 |
</globals> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
59 |
<init> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
60 |
<xhtml:p><![CDATA[ |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
61 |
]]></xhtml:p> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
62 |
</init> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
63 |
<cleanup> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
64 |
<xhtml:p><![CDATA[ |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
65 |
]]></xhtml:p> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
66 |
</cleanup> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
67 |
<start> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
68 |
<xhtml:p><![CDATA[ |
2994
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
69 |
|
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
70 |
svghmi_root.putChild("alarms", AlarmJsonResource()) |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
71 |
|
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2983
diff
changeset
|
72 |
|
2983
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
73 |
]]></xhtml:p> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
74 |
</start> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
75 |
<stop> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
76 |
<xhtml:p><![CDATA[ |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
77 |
]]></xhtml:p> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
78 |
</stop> |
43198edb6ac0
SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff
changeset
|
79 |
</PyFile> |