author | Dino Kosic <44305363+kraskrom@users.noreply.github.com> |
Mon, 02 Dec 2024 11:33:19 +0100 | |
changeset 4056 | 4b2de1a0fbf9 |
parent 3784 | a5f58ca4629b |
permissions | -rw-r--r-- |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
3 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
6 |
# |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
7 |
# Copyright (c) 2016 Mario de Sousa (msousa@fe.up.pt) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
8 |
# |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
9 |
# This program is free software: you can redistribute it and/or modify |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
10 |
# it under the terms of the GNU General Public License as published by |
2019
92f02bb17c7e
Make Modbus extension license compatible with the rest of Beremiz IDE python code : GPLv2.
Edouard Tisserant
parents:
1919
diff
changeset
|
11 |
# the Free Software Foundation, either version 2 of the License, or |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
12 |
# (at your option) any later version. |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
13 |
# |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
14 |
# This program is distributed in the hope that it will be useful, |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
17 |
# GNU General Public License for more details. |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
18 |
# |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
19 |
# You should have received a copy of the GNU General Public License |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
20 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
21 |
# |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
22 |
# This code is made available on the understanding that it will not be |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
23 |
# used in safety-critical situations without a full and competent review. |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
24 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
25 |
|
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
26 |
import os |
2432
dbc065a2f7a5
python3 support: pylint, W1613 # (xrange-builtin) xrange built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2291
diff
changeset
|
27 |
|
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
28 |
from modbus.mb_utils import * |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
29 |
from ConfigTreeNode import ConfigTreeNode |
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
30 |
from PLCControler import LOCATION_CONFNODE, LOCATION_VAR_MEMORY |
2669
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
31 |
import util.paths as paths |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
32 |
|
2736
a81b72ef156c
Add ThirPartyPath call in util.path module, so that individual extensions don't have to each implement same logic to find dependencies
Edouard Tisserant
parents:
2724
diff
changeset
|
33 |
ModbusPath = paths.ThirdPartyPath("Modbus") |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
34 |
|
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
35 |
|
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
36 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
37 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
38 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
39 |
# C L I E N T R E Q U E S T # |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
40 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
41 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
42 |
# |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
43 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
44 |
|
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
45 |
class _RequestPlug(object): |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
46 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
47 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
48 |
<xsd:element name="ModbusRequest"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
49 |
<xsd:complexType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
50 |
<xsd:attribute name="Function" type="xsd:string" use="optional" default="01 - Read Coils"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
51 |
<xsd:attribute name="SlaveID" use="optional" default="1"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
52 |
<xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
53 |
<xsd:restriction base="xsd:integer"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
54 |
<xsd:minInclusive value="0"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
55 |
<xsd:maxInclusive value="255"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
56 |
</xsd:restriction> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
57 |
</xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
58 |
</xsd:attribute> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
59 |
<xsd:attribute name="Nr_of_Channels" use="optional" default="1"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
60 |
<xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
61 |
<xsd:restriction base="xsd:integer"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
62 |
<xsd:minInclusive value="1"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
63 |
<xsd:maxInclusive value="2000"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
64 |
</xsd:restriction> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
65 |
</xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
66 |
</xsd:attribute> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
67 |
<xsd:attribute name="Start_Address" use="optional" default="0"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
68 |
<xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
69 |
<xsd:restriction base="xsd:integer"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
70 |
<xsd:minInclusive value="0"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
71 |
<xsd:maxInclusive value="65535"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
72 |
</xsd:restriction> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
73 |
</xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
74 |
</xsd:attribute> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
75 |
<xsd:attribute name="Timeout_in_ms" use="optional" default="10"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
76 |
<xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
77 |
<xsd:restriction base="xsd:integer"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
78 |
<xsd:minInclusive value="1"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
79 |
<xsd:maxInclusive value="100000"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
80 |
</xsd:restriction> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
81 |
</xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
82 |
</xsd:attribute> |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
83 |
<xsd:attribute name="Write_on_change" type="xsd:boolean" use="optional" default="false"/> |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
84 |
</xsd:complexType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
85 |
</xsd:element> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
86 |
</xsd:schema> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
87 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
88 |
|
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
89 |
def GetParamsAttributes(self, path=None): |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
90 |
infos = ConfigTreeNode.GetParamsAttributes(self, path=path) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
91 |
for element in infos: |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
92 |
if element["name"] == "ModbusRequest": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
93 |
for child in element["children"]: |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
94 |
if child["name"] == "Function": |
3784 | 95 |
_list = list(modbus_function_dict.keys()) |
96 |
_list.sort() |
|
97 |
child["type"] = _list |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
98 |
return infos |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
99 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
100 |
def GetVariableLocationTree(self): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
101 |
current_location = self.GetCurrentLocation() |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
102 |
name = self.BaseParams.getName() |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
103 |
address = self.GetParamsAttributes()[0]["children"][3]["value"] |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
104 |
count = self.GetParamsAttributes()[0]["children"][2]["value"] |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
105 |
function = self.GetParamsAttributes()[0]["children"][0]["value"] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
106 |
# 'BOOL' or 'WORD' |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
107 |
datatype = modbus_function_dict[function][3] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
108 |
# 1 or 16 |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
109 |
datasize = modbus_function_dict[function][4] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
110 |
# 'Q' for coils and holding registers, 'I' for input discretes and input registers |
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
111 |
# datazone = modbus_function_dict[function][5] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
112 |
# 'X' for bits, 'W' for words |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
113 |
datatacc = modbus_function_dict[function][6] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
114 |
# 'Coil', 'Holding Register', 'Input Discrete' or 'Input Register' |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
115 |
dataname = modbus_function_dict[function][7] |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
116 |
# start off with a boolean entry |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
117 |
# This is a flag used to allow the user program to control when to |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
118 |
# execute the Modbus request. |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
119 |
# NOTE: If the Modbus request has a 'current_location' of |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
120 |
# %QX1.2.3 |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
121 |
# then the execution control flag will be |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
122 |
# %QX1.2.3.0.0 |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
123 |
# and all the Modbus registers/coils will be |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
124 |
# %QX1.2.3.0 |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
125 |
# %QX1.2.3.1 |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
126 |
# %QX1.2.3.2 |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
127 |
# .. |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
128 |
# %QX1.2.3.n |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
129 |
entries = [] |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
130 |
entries.append({ |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
131 |
"name": "Execute request flag", |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
132 |
"type": LOCATION_VAR_MEMORY, |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
133 |
"size": 1, # BOOL flag |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
134 |
"IEC_type": "BOOL", # BOOL flag |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
135 |
"var_name": "var_name", |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
136 |
"location": "X" + ".".join([str(i) for i in current_location]) + ".0.0", |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
137 |
"description": "Modbus request execution control flag", |
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
138 |
"children": []}) |
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
139 |
entries.append({ |
2714
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
140 |
"name": "Modbus Request Status flag", |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
141 |
"type": LOCATION_VAR_MEMORY, |
2714
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
142 |
"size": 8, # BYTE flag |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
143 |
"IEC_type": "BYTE", # BYTE flag |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
144 |
"var_name": "var_name", |
2714
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
145 |
"location": "B" + ".".join([str(i) for i in current_location]) + ".0.1", |
2717
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
146 |
"description": "Modbus request status flag (0 -> OK, 1 -> Network error, 2 -> Received invalid frame, 3 -> Timeout, 4 -> Received error frame)", |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
147 |
"children": []}) |
2714
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
148 |
entries.append({ |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
149 |
"name": "Modbus Error Code", |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
150 |
"type": LOCATION_VAR_MEMORY, |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
151 |
"size": 8, # BYTE flag |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
152 |
"IEC_type": "BYTE", # BYTE flag |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
153 |
"var_name": "var_name", |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
154 |
"location": "B" + ".".join([str(i) for i in current_location]) + ".0.2", |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
155 |
"description": "Modbus Error Code received in Modbus error frame", |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
156 |
"children": []}) |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
157 |
for offset in range(address, address + count): |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
158 |
entries.append({ |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
159 |
"name": dataname + " " + str(offset), |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
160 |
"type": LOCATION_VAR_MEMORY, |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
161 |
"size": datasize, |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
162 |
"IEC_type": datatype, |
2589
d94d4f396bbf
Nicer name than 'var_name' for variable auto-renaming in Modbus
Edouard Tisserant
parents:
2459
diff
changeset
|
163 |
"var_name": "MB_" + "".join([w[0] for w in dataname.split()]) + "_" + str(offset), |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
164 |
"location": datatacc + ".".join([str(i) for i in current_location]) + "." + str(offset), |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
165 |
"description": "description", |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
166 |
"children": []}) |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
167 |
return {"name": name, |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
168 |
"type": LOCATION_CONFNODE, |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
169 |
"location": ".".join([str(i) for i in current_location]) + ".x", |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
170 |
"children": entries} |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
171 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
172 |
def CTNGenerate_C(self, buildpath, locations): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
173 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
174 |
Generate C code |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
175 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
176 |
@param locations: List of complete variables locations \ |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
177 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
178 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
179 |
"DIR" : direction "Q","I" or "M" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
180 |
"SIZE" : size "X", "B", "W", "D", "L" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
181 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
182 |
}, ...] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
183 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
184 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
185 |
return [], "", False |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
186 |
|
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
187 |
|
2717
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
188 |
|
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
189 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
190 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
191 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
192 |
# S E R V E R M E M O R Y A R E A # |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
193 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
194 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
195 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
196 |
|
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
197 |
# dictionary implementing: |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
198 |
# key - string with the description we want in the request plugin GUI |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
199 |
# list - (modbus function number, request type, max count value) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
200 |
modbus_memtype_dict = { |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
201 |
"01 - Coils": ('1', 'rw_bits', 65536, "BOOL", 1, "Q", "X", "Coil"), |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
202 |
"02 - Input Discretes": ('2', 'ro_bits', 65536, "BOOL", 1, "I", "X", "Input Discrete"), |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
203 |
"03 - Holding Registers": ('3', 'rw_words', 65536, "WORD", 16, "Q", "W", "Holding Register"), |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
204 |
"04 - Input Registers": ('4', 'ro_words', 65536, "WORD", 16, "I", "W", "Input Register"), |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
205 |
} |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
206 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
207 |
|
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
208 |
class _MemoryAreaPlug(object): |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
209 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
210 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
211 |
<xsd:element name="MemoryArea"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
212 |
<xsd:complexType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
213 |
<xsd:attribute name="MemoryAreaType" type="xsd:string" use="optional" default="01 - Coils"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
214 |
<xsd:attribute name="Nr_of_Channels" use="optional" default="1"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
215 |
<xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
216 |
<xsd:restriction base="xsd:integer"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
217 |
<xsd:minInclusive value="1"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
218 |
<xsd:maxInclusive value="65536"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
219 |
</xsd:restriction> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
220 |
</xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
221 |
</xsd:attribute> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
222 |
<xsd:attribute name="Start_Address" use="optional" default="0"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
223 |
<xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
224 |
<xsd:restriction base="xsd:integer"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
225 |
<xsd:minInclusive value="0"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
226 |
<xsd:maxInclusive value="65535"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
227 |
</xsd:restriction> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
228 |
</xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
229 |
</xsd:attribute> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
230 |
</xsd:complexType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
231 |
</xsd:element> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
232 |
</xsd:schema> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
233 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
234 |
|
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
235 |
def GetParamsAttributes(self, path=None): |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
236 |
infos = ConfigTreeNode.GetParamsAttributes(self, path=path) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
237 |
for element in infos: |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
238 |
if element["name"] == "MemoryArea": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
239 |
for child in element["children"]: |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
240 |
if child["name"] == "MemoryAreaType": |
3784 | 241 |
_list = list(modbus_memtype_dict.keys()) |
242 |
_list.sort() |
|
243 |
child["type"] = _list |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
244 |
return infos |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
245 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
246 |
def GetVariableLocationTree(self): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
247 |
current_location = self.GetCurrentLocation() |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
248 |
name = self.BaseParams.getName() |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
249 |
address = self.GetParamsAttributes()[0]["children"][2]["value"] |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
250 |
count = self.GetParamsAttributes()[0]["children"][1]["value"] |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
251 |
function = self.GetParamsAttributes()[0]["children"][0]["value"] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
252 |
# 'BOOL' or 'WORD' |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
253 |
datatype = modbus_memtype_dict[function][3] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
254 |
# 1 or 16 |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
255 |
datasize = modbus_memtype_dict[function][4] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
256 |
# 'Q' for coils and holding registers, 'I' for input discretes and input registers |
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
257 |
# datazone = modbus_memtype_dict[function][5] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
258 |
# 'X' for bits, 'W' for words |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
259 |
datatacc = modbus_memtype_dict[function][6] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
260 |
# 'Coil', 'Holding Register', 'Input Discrete' or 'Input Register' |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
261 |
dataname = modbus_memtype_dict[function][7] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
262 |
entries = [] |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
263 |
for offset in range(address, address + count): |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
264 |
entries.append({ |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
265 |
"name": dataname + " " + str(offset), |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
266 |
"type": LOCATION_VAR_MEMORY, |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
267 |
"size": datasize, |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
268 |
"IEC_type": datatype, |
2589
d94d4f396bbf
Nicer name than 'var_name' for variable auto-renaming in Modbus
Edouard Tisserant
parents:
2459
diff
changeset
|
269 |
"var_name": "MB_" + "".join([w[0] for w in dataname.split()]) + "_" + str(offset), |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
270 |
"location": datatacc + ".".join([str(i) for i in current_location]) + "." + str(offset), |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
271 |
"description": "description", |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
272 |
"children": []}) |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
273 |
return {"name": name, |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
274 |
"type": LOCATION_CONFNODE, |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
275 |
"location": ".".join([str(i) for i in current_location]) + ".x", |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
276 |
"children": entries} |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
277 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
278 |
def CTNGenerate_C(self, buildpath, locations): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
279 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
280 |
Generate C code |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
281 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
282 |
@param locations: List of complete variables locations \ |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
283 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
284 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
285 |
"DIR" : direction "Q","I" or "M" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
286 |
"SIZE" : size "X", "B", "W", "D", "L" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
287 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
288 |
}, ...] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
289 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
290 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
291 |
return [], "", False |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
292 |
|
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
293 |
|
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
294 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
295 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
296 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
297 |
# T C P C L I E N T # |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
298 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
299 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
300 |
# |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
301 |
|
2677
556935640ec0
Modbus: more comments to remember some necessary changes.
Edouard Tisserant
parents:
2669
diff
changeset
|
302 |
# XXX TODO "Configuration_Name" should disapear in favor of CTN Name, which is already unique |
556935640ec0
Modbus: more comments to remember some necessary changes.
Edouard Tisserant
parents:
2669
diff
changeset
|
303 |
|
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
304 |
class _ModbusTCPclientPlug(object): |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
305 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
306 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
307 |
<xsd:element name="ModbusTCPclient"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
308 |
<xsd:complexType> |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
309 |
<xsd:attribute name="Configuration_Name" type="xsd:string" use="optional" default=""/> |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
310 |
<xsd:attribute name="Remote_IP_Address" type="xsd:string" use="optional" default="localhost"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
311 |
<xsd:attribute name="Remote_Port_Number" type="xsd:string" use="optional" default="502"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
312 |
<xsd:attribute name="Invocation_Rate_in_ms" use="optional" default="100"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
313 |
<xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
314 |
<xsd:restriction base="xsd:unsignedLong"> |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
315 |
<xsd:minInclusive value="0"/> |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
316 |
<xsd:maxInclusive value="2147483647"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
317 |
</xsd:restriction> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
318 |
</xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
319 |
</xsd:attribute> |
3733
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
320 |
<xsd:attribute name="Request_Delay_in_ms" use="optional" default="0"> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
321 |
<xsd:simpleType> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
322 |
<xsd:restriction base="xsd:integer"> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
323 |
<xsd:minInclusive value="0"/> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
324 |
<xsd:maxInclusive value="2147483647"/> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
325 |
</xsd:restriction> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
326 |
</xsd:simpleType> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
327 |
</xsd:attribute> |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
328 |
</xsd:complexType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
329 |
</xsd:element> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
330 |
</xsd:schema> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
331 |
""" |
3733
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
332 |
# NOTE: Max value of 2147483647 (i32_max) for Invocation_Rate_in_ms and Request_Delay_in_ms |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
333 |
# corresponds to aprox 25 days. |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
334 |
CTNChildrenTypes = [("ModbusRequest", _RequestPlug, "Request")] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
335 |
# TODO: Replace with CTNType !!! |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
336 |
PlugType = "ModbusTCPclient" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
337 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
338 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
339 |
def __init__(self): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
340 |
# NOTE: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
341 |
# The ModbusTCPclient attribute is added dynamically by ConfigTreeNode._AddParamsMembers() |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
342 |
# It will be an XML parser object created by |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
343 |
# GenerateParserFromXSDstring(self.XSD).CreateRoot() |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
344 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
345 |
# Set the default value for the "Configuration_Name" parameter |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
346 |
# The default value will need to be different for each instance of the |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
347 |
# _ModbusTCPclientPlug class, so we cannot hardcode the default value in the XSD above |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
348 |
# This value will be used by the web interface |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
349 |
# (i.e. the extension to the web server used to configure the Modbus parameters). |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
350 |
# (The web server is run/activated/started by Beremiz_service.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
351 |
# (The web server code is found in runtime/NevowServer.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
352 |
# (The Modbus extension to the web server is found in runtime/Modbus_config.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
353 |
loc_str = ".".join(map(str, self.GetCurrentLocation())) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
354 |
self.ModbusTCPclient.setConfiguration_Name("Modbus TCP Client " + loc_str) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
355 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
356 |
# Return the number of (modbus library) nodes this specific TCP client will need |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
357 |
# return type: (tcp nodes, rtu nodes, ascii nodes) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
358 |
def GetNodeCount(self): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
359 |
return (1, 0, 0) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
360 |
|
2662
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
361 |
def GetConfigName(self): |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
362 |
""" Return the node's Configuration_Name """ |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
363 |
return self.ModbusTCPclient.getConfiguration_Name() |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
364 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
365 |
def CTNGenerate_C(self, buildpath, locations): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
366 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
367 |
Generate C code |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
368 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
369 |
@param locations: List of complete variables locations \ |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
370 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
371 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
372 |
"DIR" : direction "Q","I" or "M" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
373 |
"SIZE" : size "X", "B", "W", "D", "L" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
374 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
375 |
}, ...] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
376 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
377 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
378 |
return [], "", False |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
379 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
380 |
|
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
381 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
382 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
383 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
384 |
# T C P S E R V E R # |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
385 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
386 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
387 |
# |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
388 |
|
2677
556935640ec0
Modbus: more comments to remember some necessary changes.
Edouard Tisserant
parents:
2669
diff
changeset
|
389 |
# XXX TODO "Configuration_Name" should disapear in favor of CTN Name, which is already unique |
556935640ec0
Modbus: more comments to remember some necessary changes.
Edouard Tisserant
parents:
2669
diff
changeset
|
390 |
|
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
391 |
class _ModbusTCPserverPlug(object): |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
392 |
# NOTE: the Port number is a 'string' and not an 'integer'! |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
393 |
# This is because the underlying modbus library accepts strings |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
394 |
# (e.g.: well known port names!) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
395 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
396 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
397 |
<xsd:element name="ModbusServerNode"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
398 |
<xsd:complexType> |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
399 |
<xsd:attribute name="Configuration_Name" type="xsd:string" use="optional" default=""/> |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
400 |
<xsd:attribute name="Local_IP_Address" type="xsd:string" use="optional" default="#ANY#"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
401 |
<xsd:attribute name="Local_Port_Number" type="xsd:string" use="optional" default="502"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
402 |
<xsd:attribute name="SlaveID" use="optional" default="0"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
403 |
<xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
404 |
<xsd:restriction base="xsd:integer"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
405 |
<xsd:minInclusive value="0"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
406 |
<xsd:maxInclusive value="255"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
407 |
</xsd:restriction> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
408 |
</xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
409 |
</xsd:attribute> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
410 |
</xsd:complexType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
411 |
</xsd:element> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
412 |
</xsd:schema> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
413 |
""" |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
414 |
CTNChildrenTypes = [("MemoryArea", _MemoryAreaPlug, "Memory Area")] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
415 |
# TODO: Replace with CTNType !!! |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
416 |
PlugType = "ModbusTCPserver" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
417 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
418 |
def __init__(self): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
419 |
# NOTE: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
420 |
# The ModbusServerNode attribute is added dynamically by ConfigTreeNode._AddParamsMembers() |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
421 |
# It will be an XML parser object created by |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
422 |
# GenerateParserFromXSDstring(self.XSD).CreateRoot() |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
423 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
424 |
# Set the default value for the "Configuration_Name" parameter |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
425 |
# The default value will need to be different for each instance of the |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
426 |
# _ModbusTCPclientPlug class, so we cannot hardcode the default value in the XSD above |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
427 |
# This value will be used by the web interface |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
428 |
# (i.e. the extension to the web server used to configure the Modbus parameters). |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
429 |
# (The web server is run/activated/started by Beremiz_service.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
430 |
# (The web server code is found in runtime/NevowServer.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
431 |
# (The Modbus extension to the web server is found in runtime/Modbus_config.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
432 |
loc_str = ".".join(map(str, self.GetCurrentLocation())) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
433 |
self.ModbusServerNode.setConfiguration_Name("Modbus TCP Server " + loc_str) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
434 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
435 |
# Return the number of (modbus library) nodes this specific TCP server will need |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
436 |
# return type: (tcp nodes, rtu nodes, ascii nodes) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
437 |
def GetNodeCount(self): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
438 |
return (1, 0, 0) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
439 |
|
2663
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
440 |
# Return a list with a single tuple conatining the (location, IP address, port number) |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
441 |
# location : location of this node in the configuration tree |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
442 |
# port number: IP port used by this Modbus/IP server |
2663
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
443 |
# IP address : IP address of the network interface on which the server will be listening |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
444 |
# ("", "*", or "#ANY#" => listening on all interfaces!) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
445 |
def GetIPServerPortNumbers(self): |
2663
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
446 |
port = self.ModbusServerNode.getLocal_Port_Number() |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
447 |
addr = self.ModbusServerNode.getLocal_IP_Address() |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
448 |
return [(self.GetCurrentLocation(), addr, port)] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
449 |
|
2662
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
450 |
def GetConfigName(self): |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
451 |
""" Return the node's Configuration_Name """ |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
452 |
return self.ModbusServerNode.getConfiguration_Name() |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
453 |
|
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
454 |
def GetVariableLocationTree(self): |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
455 |
current_location = self.GetCurrentLocation() |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
456 |
name = self.BaseParams.getName() |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
457 |
# start off with flags that count the number of Modbus requests/transactions |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
458 |
# handled by this Modbus server/slave. |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
459 |
# These flags are mapped onto located variables and therefore available to the user programs |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
460 |
# May be used to detect communication errors. |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
461 |
# execute the Modbus request. |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
462 |
# NOTE: If the Modbus slave has a 'current_location' of |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
463 |
# %QX1.2 |
2722
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
464 |
# then the "Modbus Read Request Counter" will be %MD1.2.0 |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
465 |
# then the "Modbus Write Request Counter" will be %MD1.2.1 |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
466 |
# then the "Modbus Read Request Flag" will be %MD1.2.2 |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
467 |
# then the "Modbus Write Request Flag" will be %MD1.2.3 |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
468 |
# |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
469 |
# Note that any MemoryArea contained under this server/slave |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
470 |
# will ocupy the locations of type |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
471 |
# %MX or %MW |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
472 |
# which will never clash with the %MD used here. |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
473 |
# Additionaly, any MemoryArea contained under this server/slave |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
474 |
# will ocupy locations with |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
475 |
# %M1.2.a.b (with a and b being numbers in range 0, 1, ...) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
476 |
# and therefore never ocupy the locations |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
477 |
# %M1.2.0 |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
478 |
# %M1.2.1 |
2722
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
479 |
# %M1.2.2 |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
480 |
# %M1.2.3 |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
481 |
# used by the following flags/counters. |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
482 |
entries = [] |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
483 |
entries.append({ |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
484 |
"name": "Modbus Read Request Counter", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
485 |
"type": LOCATION_VAR_MEMORY, |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
486 |
"size": 32, # UDINT flag |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
487 |
"IEC_type": "UDINT", # UDINT flag |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
488 |
"var_name": "var_name", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
489 |
"location": "D" + ".".join([str(i) for i in current_location]) + ".0", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
490 |
"description": "Modbus read request counter", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
491 |
"children": []}) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
492 |
entries.append({ |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
493 |
"name": "Modbus Write Request Counter", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
494 |
"type": LOCATION_VAR_MEMORY, |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
495 |
"size": 32, # UDINT flag |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
496 |
"IEC_type": "UDINT", # UDINT flag |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
497 |
"var_name": "var_name", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
498 |
"location": "D" + ".".join([str(i) for i in current_location]) + ".1", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
499 |
"description": "Modbus write request counter", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
500 |
"children": []}) |
2722
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
501 |
entries.append({ |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
502 |
"name": "Modbus Read Request Flag", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
503 |
"type": LOCATION_VAR_MEMORY, |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
504 |
"size": 1, # BOOL flag |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
505 |
"IEC_type": "BOOL", # BOOL flag |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
506 |
"var_name": "var_name", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
507 |
"location": "X" + ".".join([str(i) for i in current_location]) + ".2", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
508 |
"description": "Modbus read request flag", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
509 |
"children": []}) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
510 |
entries.append({ |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
511 |
"name": "Modbus write Request Flag", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
512 |
"type": LOCATION_VAR_MEMORY, |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
513 |
"size": 1, # BOOL flag |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
514 |
"IEC_type": "BOOL", # BOOL flag |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
515 |
"var_name": "var_name", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
516 |
"location": "X" + ".".join([str(i) for i in current_location]) + ".3", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
517 |
"description": "Modbus write request flag", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
518 |
"children": []}) |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
519 |
# recursively call all the Memory Areas under this Modbus server/save |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
520 |
# i.e., all the children objects which will be of class _MemoryAreaPlug |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
521 |
for child in self.IECSortedChildren(): |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
522 |
entries.append(child.GetVariableLocationTree()) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
523 |
|
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
524 |
return {"name": name, |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
525 |
"type": LOCATION_CONFNODE, |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
526 |
"location": ".".join([str(i) for i in current_location]) + ".x", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
527 |
"children": entries} |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
528 |
|
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
529 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
530 |
def CTNGenerate_C(self, buildpath, locations): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
531 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
532 |
Generate C code |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
533 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
534 |
@param locations: List of complete variables locations \ |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
535 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
536 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
537 |
"DIR" : direction "Q","I" or "M" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
538 |
"SIZE" : size "X", "B", "W", "D", "L" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
539 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
540 |
}, ...] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
541 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
542 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
543 |
return [], "", False |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
544 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
545 |
|
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
546 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
547 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
548 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
549 |
# R T U C L I E N T # |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
550 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
551 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
552 |
# |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
553 |
|
2677
556935640ec0
Modbus: more comments to remember some necessary changes.
Edouard Tisserant
parents:
2669
diff
changeset
|
554 |
# XXX TODO "Configuration_Name" should disapear in favor of CTN Name, which is already unique |
556935640ec0
Modbus: more comments to remember some necessary changes.
Edouard Tisserant
parents:
2669
diff
changeset
|
555 |
|
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
556 |
class _ModbusRTUclientPlug(object): |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
557 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
558 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
559 |
<xsd:element name="ModbusRTUclient"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
560 |
<xsd:complexType> |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
561 |
<xsd:attribute name="Configuration_Name" type="xsd:string" use="optional" default=""/> |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
562 |
<xsd:attribute name="Serial_Port" type="xsd:string" use="optional" default="/dev/ttyS0"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
563 |
<xsd:attribute name="Baud_Rate" type="xsd:string" use="optional" default="9600"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
564 |
<xsd:attribute name="Parity" type="xsd:string" use="optional" default="even"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
565 |
<xsd:attribute name="Stop_Bits" type="xsd:string" use="optional" default="1"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
566 |
<xsd:attribute name="Invocation_Rate_in_ms" use="optional" default="100"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
567 |
<xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
568 |
<xsd:restriction base="xsd:integer"> |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
569 |
<xsd:minInclusive value="0"/> |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
570 |
<xsd:maxInclusive value="2147483647"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
571 |
</xsd:restriction> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
572 |
</xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
573 |
</xsd:attribute> |
3733
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
574 |
<xsd:attribute name="Request_Delay_in_ms" use="optional" default="0"> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
575 |
<xsd:simpleType> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
576 |
<xsd:restriction base="xsd:integer"> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
577 |
<xsd:minInclusive value="0"/> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
578 |
<xsd:maxInclusive value="2147483647"/> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
579 |
</xsd:restriction> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
580 |
</xsd:simpleType> |
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
581 |
</xsd:attribute> |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
582 |
</xsd:complexType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
583 |
</xsd:element> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
584 |
</xsd:schema> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
585 |
""" |
3733
d1acf20e8e7c
Modbus plugin: add optional delay between two consecutive modbus requests sent by master/client
Mario de Sousa <msousa@fe.up.pt>
parents:
2736
diff
changeset
|
586 |
# NOTE: Max value of 2147483647 (i32_max) for Invocation_Rate_in_ms and Request_Delay_in_ms |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
587 |
# corresponds to aprox 25 days. |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
588 |
CTNChildrenTypes = [("ModbusRequest", _RequestPlug, "Request")] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
589 |
# TODO: Replace with CTNType !!! |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
590 |
PlugType = "ModbusRTUclient" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
591 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
592 |
def __init__(self): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
593 |
# NOTE: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
594 |
# The ModbusRTUclient attribute is added dynamically by ConfigTreeNode._AddParamsMembers() |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
595 |
# It will be an XML parser object created by |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
596 |
# GenerateParserFromXSDstring(self.XSD).CreateRoot() |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
597 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
598 |
# Set the default value for the "Configuration_Name" parameter |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
599 |
# The default value will need to be different for each instance of the |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
600 |
# _ModbusTCPclientPlug class, so we cannot hardcode the default value in the XSD above |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
601 |
# This value will be used by the web interface |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
602 |
# (i.e. the extension to the web server used to configure the Modbus parameters). |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
603 |
# (The web server is run/activated/started by Beremiz_service.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
604 |
# (The web server code is found in runtime/NevowServer.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
605 |
# (The Modbus extension to the web server is found in runtime/Modbus_config.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
606 |
loc_str = ".".join(map(str, self.GetCurrentLocation())) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
607 |
self.ModbusRTUclient.setConfiguration_Name("Modbus RTU Client " + loc_str) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
608 |
|
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
609 |
def GetParamsAttributes(self, path=None): |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
610 |
infos = ConfigTreeNode.GetParamsAttributes(self, path=path) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
611 |
for element in infos: |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
612 |
if element["name"] == "ModbusRTUclient": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
613 |
for child in element["children"]: |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
614 |
if child["name"] == "Baud_Rate": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
615 |
child["type"] = modbus_serial_baudrate_list |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
616 |
if child["name"] == "Stop_Bits": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
617 |
child["type"] = modbus_serial_stopbits_list |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
618 |
if child["name"] == "Parity": |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3733
diff
changeset
|
619 |
child["type"] = list(modbus_serial_parity_dict.keys()) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
620 |
return infos |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
621 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
622 |
# Return the number of (modbus library) nodes this specific RTU client will need |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
623 |
# return type: (tcp nodes, rtu nodes, ascii nodes) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
624 |
def GetNodeCount(self): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
625 |
return (0, 1, 0) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
626 |
|
2662
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
627 |
def GetConfigName(self): |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
628 |
""" Return the node's Configuration_Name """ |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
629 |
return self.ModbusRTUclient.getConfiguration_Name() |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
630 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
631 |
def CTNGenerate_C(self, buildpath, locations): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
632 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
633 |
Generate C code |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
634 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
635 |
@param locations: List of complete variables locations \ |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
636 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
637 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
638 |
"DIR" : direction "Q","I" or "M" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
639 |
"SIZE" : size "X", "B", "W", "D", "L" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
640 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
641 |
}, ...] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
642 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
643 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
644 |
return [], "", False |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
645 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
646 |
|
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
647 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
648 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
649 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
650 |
# R T U S L A V E # |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
651 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
652 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
653 |
# |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
654 |
|
2677
556935640ec0
Modbus: more comments to remember some necessary changes.
Edouard Tisserant
parents:
2669
diff
changeset
|
655 |
# XXX TODO "Configuration_Name" should disapear in favor of CTN Name, which is already unique |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
656 |
|
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
657 |
class _ModbusRTUslavePlug(object): |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
658 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
659 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
660 |
<xsd:element name="ModbusRTUslave"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
661 |
<xsd:complexType> |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
662 |
<xsd:attribute name="Configuration_Name" type="xsd:string" use="optional" default=""/> |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
663 |
<xsd:attribute name="Serial_Port" type="xsd:string" use="optional" default="/dev/ttyS0"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
664 |
<xsd:attribute name="Baud_Rate" type="xsd:string" use="optional" default="9600"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
665 |
<xsd:attribute name="Parity" type="xsd:string" use="optional" default="even"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
666 |
<xsd:attribute name="Stop_Bits" type="xsd:string" use="optional" default="1"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
667 |
<xsd:attribute name="SlaveID" use="optional" default="1"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
668 |
<xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
669 |
<xsd:restriction base="xsd:integer"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
670 |
<xsd:minInclusive value="1"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
671 |
<xsd:maxInclusive value="255"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
672 |
</xsd:restriction> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
673 |
</xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
674 |
</xsd:attribute> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
675 |
</xsd:complexType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
676 |
</xsd:element> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
677 |
</xsd:schema> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
678 |
""" |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
679 |
CTNChildrenTypes = [("MemoryArea", _MemoryAreaPlug, "Memory Area")] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
680 |
# TODO: Replace with CTNType !!! |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
681 |
PlugType = "ModbusRTUslave" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
682 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
683 |
def __init__(self): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
684 |
# NOTE: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
685 |
# The ModbusRTUslave attribute is added dynamically by ConfigTreeNode._AddParamsMembers() |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
686 |
# It will be an XML parser object created by |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
687 |
# GenerateParserFromXSDstring(self.XSD).CreateRoot() |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
688 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
689 |
# Set the default value for the "Configuration_Name" parameter |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
690 |
# The default value will need to be different for each instance of the |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
691 |
# _ModbusTCPclientPlug class, so we cannot hardcode the default value in the XSD above |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
692 |
# This value will be used by the web interface |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
693 |
# (i.e. the extension to the web server used to configure the Modbus parameters). |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
694 |
# (The web server is run/activated/started by Beremiz_service.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
695 |
# (The web server code is found in runtime/NevowServer.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
696 |
# (The Modbus extension to the web server is found in runtime/Modbus_config.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
697 |
loc_str = ".".join(map(str, self.GetCurrentLocation())) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
698 |
self.ModbusRTUslave.setConfiguration_Name("Modbus RTU Slave " + loc_str) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
2648
diff
changeset
|
699 |
|
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
700 |
def GetParamsAttributes(self, path=None): |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
701 |
infos = ConfigTreeNode.GetParamsAttributes(self, path=path) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
702 |
for element in infos: |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
703 |
if element["name"] == "ModbusRTUslave": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
704 |
for child in element["children"]: |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
705 |
if child["name"] == "Baud_Rate": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
706 |
child["type"] = modbus_serial_baudrate_list |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
707 |
if child["name"] == "Stop_Bits": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
708 |
child["type"] = modbus_serial_stopbits_list |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
709 |
if child["name"] == "Parity": |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3733
diff
changeset
|
710 |
child["type"] = list(modbus_serial_parity_dict.keys()) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
711 |
return infos |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
712 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
713 |
# Return the number of (modbus library) nodes this specific RTU slave will need |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
714 |
# return type: (tcp nodes, rtu nodes, ascii nodes) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
715 |
def GetNodeCount(self): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
716 |
return (0, 1, 0) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
717 |
|
2662
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
718 |
def GetConfigName(self): |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
719 |
""" Return the node's Configuration_Name """ |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
720 |
return self.ModbusRTUslave.getConfiguration_Name() |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
721 |
|
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
722 |
def GetVariableLocationTree(self): |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
723 |
current_location = self.GetCurrentLocation() |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
724 |
name = self.BaseParams.getName() |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
725 |
# start off with flags that count the number of Modbus requests/transactions |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
726 |
# handled by this Modbus server/slave. |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
727 |
# These flags are mapped onto located variables and therefore available to the user programs |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
728 |
# May be used to detect communication errors. |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
729 |
# execute the Modbus request. |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
730 |
# NOTE: If the Modbus slave has a 'current_location' of |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
731 |
# %QX1.2 |
2722
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
732 |
# then the "Modbus Read Request Counter" will be %MD1.2.0 |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
733 |
# then the "Modbus Write Request Counter" will be %MD1.2.1 |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
734 |
# then the "Modbus Read Request Flag" will be %MD1.2.2 |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
735 |
# then the "Modbus Write Request Flag" will be %MD1.2.3 |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
736 |
# |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
737 |
# Note that any MemoryArea contained under this server/slave |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
738 |
# will ocupy the locations of type |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
739 |
# %MX or %MW |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
740 |
# which will never clash with the %MD used here. |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
741 |
# Additionaly, any MemoryArea contained under this server/slave |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
742 |
# will ocupy locations with |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
743 |
# %M1.2.a.b (with a and b being numbers in range 0, 1, ...) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
744 |
# and therefore never ocupy the locations |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
745 |
# %M1.2.0 |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
746 |
# %M1.2.1 |
2722
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
747 |
# %M1.2.2 |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
748 |
# %M1.2.3 |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
749 |
# used by the following flags/counters. |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
750 |
entries = [] |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
751 |
entries.append({ |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
752 |
"name": "Modbus Read Request Counter", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
753 |
"type": LOCATION_VAR_MEMORY, |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
754 |
"size": 32, # UDINT flag |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
755 |
"IEC_type": "UDINT", # UDINT flag |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
756 |
"var_name": "var_name", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
757 |
"location": "D" + ".".join([str(i) for i in current_location]) + ".0", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
758 |
"description": "Modbus read request counter", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
759 |
"children": []}) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
760 |
entries.append({ |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
761 |
"name": "Modbus Write Request Counter", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
762 |
"type": LOCATION_VAR_MEMORY, |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
763 |
"size": 32, # UDINT flag |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
764 |
"IEC_type": "UDINT", # UDINT flag |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
765 |
"var_name": "var_name", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
766 |
"location": "D" + ".".join([str(i) for i in current_location]) + ".1", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
767 |
"description": "Modbus write request counter", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
768 |
"children": []}) |
2722
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
769 |
entries.append({ |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
770 |
"name": "Modbus Read Request Flag", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
771 |
"type": LOCATION_VAR_MEMORY, |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
772 |
"size": 1, # BOOL flag |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
773 |
"IEC_type": "BOOL", # BOOL flag |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
774 |
"var_name": "var_name", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
775 |
"location": "X" + ".".join([str(i) for i in current_location]) + ".2", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
776 |
"description": "Modbus read request flag", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
777 |
"children": []}) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
778 |
entries.append({ |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
779 |
"name": "Modbus write Request Flag", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
780 |
"type": LOCATION_VAR_MEMORY, |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
781 |
"size": 1, # BOOL flag |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
782 |
"IEC_type": "BOOL", # BOOL flag |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
783 |
"var_name": "var_name", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
784 |
"location": "X" + ".".join([str(i) for i in current_location]) + ".3", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
785 |
"description": "Modbus write request flag", |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
786 |
"children": []}) |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
787 |
# recursively call all the Memory Areas under this Modbus server/save |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
788 |
# i.e., all the children objects which will be of class _MemoryAreaPlug |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
789 |
for child in self.IECSortedChildren(): |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
790 |
entries.append(child.GetVariableLocationTree()) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
791 |
|
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
792 |
return {"name": name, |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
793 |
"type": LOCATION_CONFNODE, |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
794 |
"location": ".".join([str(i) for i in current_location]) + ".x", |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
795 |
"children": entries} |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
796 |
|
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
797 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
798 |
def CTNGenerate_C(self, buildpath, locations): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
799 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
800 |
Generate C code |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
801 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
802 |
@param locations: List of complete variables locations \ |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
803 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
804 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
805 |
"DIR" : direction "Q","I" or "M" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
806 |
"SIZE" : size "X", "B", "W", "D", "L" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
807 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
808 |
}, ...] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
809 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
810 |
""" |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
811 |
return [], "", False |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
812 |
|
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
813 |
|
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
814 |
def _lt_to_str(loctuple): |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
815 |
return '.'.join(map(str, loctuple)) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
816 |
|
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
817 |
|
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
818 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
819 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
820 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
821 |
# R O O T C L A S S # |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
822 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
823 |
# |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
824 |
# |
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
825 |
class RootClass(object): |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
826 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
827 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
828 |
<xsd:element name="ModbusRoot"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
829 |
<xsd:complexType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
830 |
<xsd:attribute name="MaxRemoteTCPclients" use="optional" default="10"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
831 |
<xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
832 |
<xsd:restriction base="xsd:integer"> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
833 |
<xsd:minInclusive value="0"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
834 |
<xsd:maxInclusive value="65535"/> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
835 |
</xsd:restriction> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
836 |
</xsd:simpleType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
837 |
</xsd:attribute> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
838 |
</xsd:complexType> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
839 |
</xsd:element> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
840 |
</xsd:schema> |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
841 |
""" |
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
842 |
CTNChildrenTypes = [("ModbusTCPclient", _ModbusTCPclientPlug, "Modbus TCP Client"), |
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
843 |
("ModbusTCPserver", _ModbusTCPserverPlug, "Modbus TCP Server"), |
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
844 |
("ModbusRTUclient", _ModbusRTUclientPlug, "Modbus RTU Client"), |
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
845 |
("ModbusRTUslave", _ModbusRTUslavePlug, "Modbus RTU Slave")] |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
846 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
847 |
# Return the number of (modbus library) nodes this specific instance of the modbus plugin will need |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
848 |
# return type: (tcp nodes, rtu nodes, ascii nodes) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
849 |
def GetNodeCount(self): |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
850 |
max_remote_tcpclient = self.GetParamsAttributes()[ |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
851 |
0]["children"][0]["value"] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
852 |
total_node_count = (max_remote_tcpclient, 0, 0) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
853 |
for child in self.IECSortedChildren(): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
854 |
# ask each child how many nodes it needs, and add them all up. |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
855 |
total_node_count = tuple( |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
856 |
x1 + x2 for x1, x2 in zip(total_node_count, child.GetNodeCount())) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
857 |
return total_node_count |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
858 |
|
2662
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
859 |
# Return a list with tuples of the (location, port numbers) used by all the Modbus/IP servers |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
860 |
def GetIPServerPortNumbers(self): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
861 |
IPServer_port_numbers = [] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
862 |
for child in self.IECSortedChildren(): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
863 |
if child.CTNType == "ModbusTCPserver": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
864 |
IPServer_port_numbers.extend(child.GetIPServerPortNumbers()) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
865 |
return IPServer_port_numbers |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
866 |
|
2662
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
867 |
# Return a list with tuples of the (location, configuration_name) used by all the Modbus nodes (tcp/rtu, clients/servers) |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
868 |
def GetConfigNames(self): |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
869 |
Node_Configuration_Names = [] |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
870 |
for child in self.IECSortedChildren(): |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
871 |
Node_Configuration_Names.extend([(child.GetCurrentLocation(), child.GetConfigName())]) |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
872 |
return Node_Configuration_Names |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
873 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
874 |
def CTNGenerate_C(self, buildpath, locations): |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
875 |
# print "#############" |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
876 |
# print self.__class__ |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
877 |
# print type(self) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
878 |
# print "self.CTNType >>>" |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
879 |
# print self.CTNType |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
880 |
# print "type(self.CTNType) >>>" |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
881 |
# print type(self.CTNType) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
882 |
# print "#############" |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
883 |
|
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
884 |
loc_dict = {"locstr": "_".join(map(str, self.GetCurrentLocation()))} |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
885 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
886 |
# Determine the number of (modbus library) nodes ALL instances of the modbus plugin will need |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
887 |
# total_node_count: (tcp nodes, rtu nodes, ascii nodes) |
2663
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
888 |
# |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
889 |
# Also get a list with tuples of (location, IP address, port number) used by all the Modbus/IP server nodes |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
890 |
# This list is later used to search for duplicates in port numbers! |
2663
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
891 |
# IPServer_port_numbers = [(location, IP address, port number), ...] |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
892 |
# location : tuple similar to (0, 3, 1) representing the location in the configuration tree "0.3.1.x" |
2662
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
893 |
# IPserver_port_number: a number (i.e. port number used by the Modbus/IP server) |
2663
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
894 |
# IP address : IP address of the network interface on which the server will be listening |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
895 |
# ("", "*", or "#ANY#" => listening on all interfaces!) |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
896 |
# |
2662
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
897 |
# Also get a list with tuples of (location, Configuration_Name) used by all the Modbus nodes |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
898 |
# This list is later used to search for duplicates in Configuration Names! |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
899 |
# Node_Configuration_Names = [(location, Configuration_Name), ...] |
2663
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
900 |
# location : tuple similar to (0, 3, 1) representing the location in the configuration tree "0.3.1.x" |
2662
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
901 |
# Configuration_Name: the "Configuration_Name" string |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
902 |
total_node_count = (0, 0, 0) |
2662
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
903 |
IPServer_port_numbers = [] |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
904 |
Node_Configuration_Names = [] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
905 |
for CTNInstance in self.GetCTRoot().IterChildren(): |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
906 |
if CTNInstance.CTNType == "modbus": |
2662
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
907 |
# ask each modbus plugin instance how many nodes it needs, and add them all up. |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
908 |
total_node_count = tuple(x1 + x2 for x1, x2 in zip(total_node_count, CTNInstance.GetNodeCount())) |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
909 |
IPServer_port_numbers. extend(CTNInstance.GetIPServerPortNumbers()) |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
910 |
Node_Configuration_Names.extend(CTNInstance.GetConfigNames ()) |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
911 |
|
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
912 |
# Search for use of duplicate Configuration_Names by Modbus nodes |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
913 |
# Configuration Names are used by the web server running on the PLC |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
914 |
# (more precisely, run by Beremiz_service.py) to identify and allow |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
915 |
# changing the Modbus parameters after the program has been downloaded |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
916 |
# to the PLC (but before it is started) |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
917 |
# With clashes in the configuration names, the Modbus nodes will not be |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
918 |
# distinguasheble on the web interface! |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
919 |
for i in range(0, len(Node_Configuration_Names) - 1): |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
920 |
for j in range(i + 1, len(Node_Configuration_Names)): |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
921 |
if Node_Configuration_Names[i][1] == Node_Configuration_Names[j][1]: |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
922 |
error_message = _("Error: Modbus plugin nodes %{a1}.x and %{a2}.x use the same Configuration_Name \"{a3}\".\n").format( |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
923 |
a1=_lt_to_str(Node_Configuration_Names[i][0]), |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
924 |
a2=_lt_to_str(Node_Configuration_Names[j][0]), |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
925 |
a3=Node_Configuration_Names[j][1]) |
654583c4af83
Modbus plugin: check for duplicate "Configuration_Name"
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
926 |
self.FatalError(error_message) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
927 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
928 |
# Search for use of duplicate port numbers by Modbus/IP servers |
2663
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
929 |
# Note: We only consider duplicate port numbers if using the same network interface! |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
930 |
i = 0 |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
931 |
for loc1, addr1, port1 in IPServer_port_numbers[:-1]: |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
932 |
i = i + 1 |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
933 |
for loc2, addr2, port2 in IPServer_port_numbers[i:]: |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
934 |
if (port1 == port2) and ( |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
935 |
(addr1 == addr2) # on the same network interface |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
936 |
or (addr1 == "") or (addr1 == "*") or (addr1 == "#ANY#") # or one (or both) of the servers |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
937 |
or (addr2 == "") or (addr2 == "*") or (addr2 == "#ANY#") # use all available network interfaces |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
938 |
): |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
939 |
error_message = _("Error: Modbus plugin nodes %{a1}.x and %{a2}.x use same port number \"{a3}\" " + |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
940 |
"on the same (or overlapping) network interfaces \"{a4}\" and \"{a5}\".\n").format( |
54f5b8e5c8d2
Modbus plugin: fix algorithm detecting Modbus TCP servers using the same IP port on the same network interface
Mario de Sousa <msousa@fe.up.pt>
parents:
2662
diff
changeset
|
941 |
a1=_lt_to_str(loc1), a2=_lt_to_str(loc2), a3=port1, a4=addr1, a5=addr2) |
2648
e4ab768170f9
modbus_plugin: generate nicer error message, instead of a traceback
Mario de Sousa <msousa@fe.up.pt>
parents:
2647
diff
changeset
|
942 |
self.FatalError(error_message) |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
943 |
|
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
944 |
# Determine the current location in Beremiz's project configuration |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
945 |
# tree |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
946 |
current_location = self.GetCurrentLocation() |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
947 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
948 |
# define a unique name for the generated C and h files |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
949 |
prefix = "_".join(map(str, current_location)) |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
950 |
Gen_MB_c_path = os.path.join(buildpath, "MB_%s.c" % prefix) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
951 |
Gen_MB_h_path = os.path.join(buildpath, "MB_%s.h" % prefix) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
952 |
c_filename = os.path.join(os.path.split(__file__)[0], "mb_runtime.c") |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
953 |
h_filename = os.path.join(os.path.split(__file__)[0], "mb_runtime.h") |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
954 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
955 |
tcpclient_reqs_count = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
956 |
rtuclient_reqs_count = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
957 |
ascclient_reqs_count = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
958 |
tcpclient_node_count = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
959 |
rtuclient_node_count = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
960 |
ascclient_node_count = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
961 |
tcpserver_node_count = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
962 |
rtuserver_node_count = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
963 |
ascserver_node_count = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
964 |
nodeid = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
965 |
client_nodeid = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
966 |
client_requestid = 0 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
967 |
server_id = 0 |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
968 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
969 |
server_node_list = [] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
970 |
client_node_list = [] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
971 |
client_request_list = [] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
972 |
server_memarea_list = [] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
973 |
loc_vars = [] |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
974 |
loc_vars_list = [] # list of variables already declared in C code! |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
975 |
for child in self.IECSortedChildren(): |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
976 |
# print "<<<<<<<<<<<<<" |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
977 |
# print "child (self.IECSortedChildren())----->" |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
978 |
# print child.__class__ |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
979 |
# print ">>>>>>>>>>>>>" |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
980 |
# |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
981 |
if child.PlugType == "ModbusTCPserver": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
982 |
tcpserver_node_count += 1 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
983 |
new_node = GetTCPServerNodePrinted(self, child) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
984 |
if new_node is None: |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
985 |
return [], "", False |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
986 |
server_node_list.append(new_node) |
2722
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
987 |
# We currently add 4 flags/counters to each Modbus server/slave |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
988 |
# |
2722
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
989 |
# We add the Modbus read/write counter/flag to each Modbus slave/server |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
990 |
# to allow the user program to determine if the slave is being actively |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
991 |
# read from or written by by a remote Modbus client. |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
992 |
for iecvar in child.GetLocations(): |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
993 |
#print "child" + repr(iecvar) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
994 |
if (len(iecvar["LOC"]) == 3) and (str(iecvar["NAME"]) not in loc_vars_list): |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
995 |
# Add if it is a "Modbus Read Request Counter" (mapped onto %MDa.b.0), so last number is a '0' |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
996 |
if iecvar["LOC"][2] == 0: |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
997 |
loc_vars.append("u32 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.flag_read_req_counter;" % (server_id)) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
998 |
loc_vars_list.append(str(iecvar["NAME"])) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
999 |
# Add if it is a "Modbus Write Request Counter" (mapped onto %MDa.b.1), so last number is a '1' |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1000 |
if iecvar["LOC"][2] == 1: |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1001 |
loc_vars.append("u32 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.flag_write_req_counter;" % (server_id)) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1002 |
loc_vars_list.append(str(iecvar["NAME"])) |
2722
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1003 |
# Add if it is a "Modbus Read Request Flag" (mapped onto %MDa.b.2), so last number is a '2' |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1004 |
if iecvar["LOC"][2] == 2: |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1005 |
loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.flag_read_req_flag;" % (server_id)) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1006 |
loc_vars_list.append(str(iecvar["NAME"])) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1007 |
# Add if it is a "Modbus Write Request Counter" (mapped onto %MDa.b.3), so last number is a '3' |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1008 |
if iecvar["LOC"][2] == 3: |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1009 |
loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.flag_write_req_flag;" % (server_id)) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1010 |
loc_vars_list.append(str(iecvar["NAME"])) |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1011 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1012 |
for subchild in child.IECSortedChildren(): |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1013 |
new_memarea = GetTCPServerMemAreaPrinted(self, subchild, nodeid) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1014 |
if new_memarea is None: |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1015 |
return [], "", False |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1016 |
server_memarea_list.append(new_memarea) |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1017 |
function = subchild.GetParamsAttributes()[0]["children"][0]["value"] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1018 |
# 'ro_bits', 'rw_bits', 'ro_words' or 'rw_words' |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1019 |
memarea = modbus_memtype_dict[function][1] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1020 |
for iecvar in subchild.GetLocations(): |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1021 |
if len(iecvar["LOC"]) == 4: |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1022 |
#print "subchild" + repr(iecvar) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1023 |
absloute_address = iecvar["LOC"][3] |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1024 |
start_address = int(GetCTVal(subchild, 2)) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1025 |
relative_addr = absloute_address - start_address |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1026 |
# test if relative address in request specified range |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3733
diff
changeset
|
1027 |
if relative_addr in range(int(GetCTVal(subchild, 1))): |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1028 |
if str(iecvar["NAME"]) not in loc_vars_list: |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1029 |
loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.%s[%d];" % ( |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1030 |
server_id, memarea, absloute_address)) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1031 |
loc_vars_list.append(str(iecvar["NAME"])) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1032 |
server_id += 1 |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1033 |
# |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1034 |
if child.PlugType == "ModbusRTUslave": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1035 |
rtuserver_node_count += 1 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1036 |
new_node = GetRTUSlaveNodePrinted(self, child) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1037 |
if new_node is None: |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1038 |
return [], "", False |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1039 |
server_node_list.append(new_node) |
2722
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1040 |
# We currently add 4 flags/counters to each Modbus server/slave |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1041 |
# |
2722
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1042 |
# We add the Modbus read/write counter/flag to each Modbus slave/server |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1043 |
# to allow the user program to determine if the slave is being actively |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1044 |
# read from or written by by a remote Modbus client. |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1045 |
for iecvar in child.GetLocations(): |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1046 |
#print "child" + repr(iecvar) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1047 |
if (len(iecvar["LOC"]) == 3) and (str(iecvar["NAME"]) not in loc_vars_list): |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1048 |
# Add if it is a "Modbus Read Request Counter" (mapped onto %MDa.b.0), so last number is a '0' |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1049 |
if iecvar["LOC"][2] == 0: |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1050 |
loc_vars.append("u32 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.flag_read_req_counter;" % (server_id)) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1051 |
loc_vars_list.append(str(iecvar["NAME"])) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1052 |
# Add if it is a "Modbus Write Request Counter" (mapped onto %MDa.b.1), so last number is a '1' |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1053 |
if iecvar["LOC"][2] == 1: |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1054 |
loc_vars.append("u32 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.flag_write_req_counter;" % (server_id)) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1055 |
loc_vars_list.append(str(iecvar["NAME"])) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1056 |
# Add if it is a "Modbus Read Request Flag" (mapped onto %MDa.b.2), so last number is a '2' |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1057 |
if iecvar["LOC"][2] == 2: |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1058 |
loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.flag_read_req_flag;" % (server_id)) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1059 |
loc_vars_list.append(str(iecvar["NAME"])) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1060 |
# Add if it is a "Modbus Write Request Counter" (mapped onto %MDa.b.3), so last number is a '3' |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1061 |
if iecvar["LOC"][2] == 3: |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1062 |
loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.flag_write_req_flag;" % (server_id)) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1063 |
loc_vars_list.append(str(iecvar["NAME"])) |
5d72a52b8f9c
modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents:
2721
diff
changeset
|
1064 |
|
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1065 |
for subchild in child.IECSortedChildren(): |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1066 |
new_memarea = GetTCPServerMemAreaPrinted( |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1067 |
self, subchild, nodeid) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1068 |
if new_memarea is None: |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1069 |
return [], "", False |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1070 |
server_memarea_list.append(new_memarea) |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1071 |
function = subchild.GetParamsAttributes()[0]["children"][0]["value"] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1072 |
# 'ro_bits', 'rw_bits', 'ro_words' or 'rw_words' |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1073 |
memarea = modbus_memtype_dict[function][1] |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1074 |
for iecvar in subchild.GetLocations(): |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1075 |
if len(iecvar["LOC"]) == 4: |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1076 |
# print repr(iecvar) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1077 |
absloute_address = iecvar["LOC"][3] |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1078 |
start_address = int(GetCTVal(subchild, 2)) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1079 |
relative_addr = absloute_address - start_address |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1080 |
# test if relative address in request specified range |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3733
diff
changeset
|
1081 |
if relative_addr in range(int(GetCTVal(subchild, 1))): |
2721
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1082 |
if str(iecvar["NAME"]) not in loc_vars_list: |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1083 |
loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.%s[%d];" % ( |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1084 |
server_id, memarea, absloute_address)) |
367eb26972b1
modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents:
2717
diff
changeset
|
1085 |
loc_vars_list.append(str(iecvar["NAME"])) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1086 |
server_id += 1 |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1087 |
# |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1088 |
if child.PlugType == "ModbusTCPclient": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1089 |
tcpclient_reqs_count += len(child.IECSortedChildren()) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1090 |
new_node = GetTCPClientNodePrinted(self, child) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1091 |
if new_node is None: |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1092 |
return [], "", False |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1093 |
client_node_list.append(new_node) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1094 |
for subchild in child.IECSortedChildren(): |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1095 |
new_req = GetClientRequestPrinted( |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1096 |
self, subchild, client_nodeid) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1097 |
if new_req is None: |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1098 |
return [], "", False |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1099 |
client_request_list.append(new_req) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1100 |
for iecvar in subchild.GetLocations(): |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1101 |
# absloute address - start address |
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
1102 |
relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3)) |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1103 |
# test if the located variable |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1104 |
# (a) has relative address in request specified range |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1105 |
# AND is NOT |
2717
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1106 |
# (b) is a flag added by this modbus plugin. |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1107 |
# We currently add 3 flags: An execution control flag |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1108 |
# and another two status flags. |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1109 |
# We add the "Execution Control Flag" to each client request (one flag per request) |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1110 |
# to allow the user program to control when to execute the request (if not executed periodically) |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1111 |
# While all Modbus registers/coils are mapped onto a location |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1112 |
# with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1113 |
# onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1114 |
# two numbers are always '0.0', and the first two identify the request. |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1115 |
# In the following if, we check for this condition by checking |
2717
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1116 |
# if there are at least 4 or more number in the location's address. |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3733
diff
changeset
|
1117 |
if ( relative_addr in range(int(GetCTVal(subchild, 2))) # condition (a) explained above |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1118 |
and len(iecvar["LOC"]) < 5): # condition (b) explained above |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1119 |
if str(iecvar["NAME"]) not in loc_vars_list: |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1120 |
loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1121 |
loc_vars_list.append(str(iecvar["NAME"])) |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1122 |
# Now add the located variable in case it is a flag (condition (b) above |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1123 |
if len(iecvar["LOC"]) >= 5: # condition (b) explained above |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1124 |
if str(iecvar["NAME"]) not in loc_vars_list: |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1125 |
# Add if it is a Execution Request Flag (mapped onto %QXa.b.c.0.0), so last number is a '0' |
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1126 |
if iecvar["LOC"][4] == 0: |
2715
1215a6b741d5
Modbus plugin: fix bug - map BOOL flag onto C u8 (was incorrectly mapped onto u16)
Mario de Sousa <msousa@fe.up.pt>
parents:
2714
diff
changeset
|
1127 |
loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1128 |
loc_vars_list.append(str(iecvar["NAME"])) |
2714
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1129 |
# Add if it is a "Modbus Request Status flag" (mapped onto %QWa.b.c.0.1), so last number is a '1' |
2717
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1130 |
# -> will store the result of the last executed MB transaction |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1131 |
# 1 -> error accessing IP network, or serial interface |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1132 |
# 2 -> reply received from server was an invalid frame |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1133 |
# 3 -> server did not reply before timeout expired |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1134 |
# 4 -> server returned a valid Modbus error frame |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1135 |
# -> will be reset (set to 0) once this MB transaction has completed sucesfully |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1136 |
if iecvar["LOC"][4] == 1: |
2714
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1137 |
loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid)) |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1138 |
loc_vars_list.append(str(iecvar["NAME"])) |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1139 |
# Add if it is a "Modbus Error code" (mapped onto %QWa.b.c.0.2), so last number is a '2' |
2717
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1140 |
# -> if "Modbus Request Status flag" is 4, this flag will store the MB error code returned by the MB server in a MB error frame |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1141 |
# -> will be reset (set to 0) once this MB transaction has completed succesfully |
2714
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1142 |
if iecvar["LOC"][4] == 2: |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1143 |
loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid)) |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1144 |
loc_vars_list.append(str(iecvar["NAME"])) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1145 |
client_requestid += 1 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1146 |
tcpclient_node_count += 1 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1147 |
client_nodeid += 1 |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1148 |
# |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1149 |
if child.PlugType == "ModbusRTUclient": |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1150 |
rtuclient_reqs_count += len(child.IECSortedChildren()) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1151 |
new_node = GetRTUClientNodePrinted(self, child) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1152 |
if new_node is None: |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1153 |
return [], "", False |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1154 |
client_node_list.append(new_node) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1155 |
for subchild in child.IECSortedChildren(): |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1156 |
new_req = GetClientRequestPrinted( |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1157 |
self, subchild, client_nodeid) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1158 |
if new_req is None: |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1159 |
return [], "", False |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1160 |
client_request_list.append(new_req) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1161 |
for iecvar in subchild.GetLocations(): |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1162 |
# absloute address - start address |
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1918
diff
changeset
|
1163 |
relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3)) |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1164 |
# test if the located variable |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1165 |
# (a) has relative address in request specified range |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1166 |
# AND is NOT |
2717
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1167 |
# (b) is a flag added by this modbus plugin. |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1168 |
# We currently add 3 flags: An execution control flag |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1169 |
# and another two status flags. |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1170 |
# We add the "Execution Control Flag" to each client request (one flag per request) |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1171 |
# to allow the user program to control when to execute the request (if not executed periodically) |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1172 |
# While all Modbus registers/coils are mapped onto a location |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1173 |
# with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1174 |
# onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1175 |
# two numbers are always '0.0', and the first two identify the request. |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1176 |
# In the following if, we check for this condition by checking |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1177 |
# if there are at least 4 or more number in the location's address. |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3733
diff
changeset
|
1178 |
if ( relative_addr in range(int(GetCTVal(subchild, 2))) # condition (a) explained above |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1179 |
and len(iecvar["LOC"]) < 5): # condition (b) explained above |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1180 |
if str(iecvar["NAME"]) not in loc_vars_list: |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1181 |
loc_vars.append( |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1182 |
"u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1183 |
loc_vars_list.append(str(iecvar["NAME"])) |
2647
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1184 |
# Now add the located variable in case it is a flag (condition (b) above |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1185 |
if len(iecvar["LOC"]) >= 5: # condition (b) explained above |
990004083eb8
Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents:
2589
diff
changeset
|
1186 |
if str(iecvar["NAME"]) not in loc_vars_list: |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1187 |
# Add if it is a Execution Request Flag (mapped onto %QXa.b.c.0.0), so last number is a '0' |
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1188 |
if iecvar["LOC"][4] == 0: |
2715
1215a6b741d5
Modbus plugin: fix bug - map BOOL flag onto C u8 (was incorrectly mapped onto u16)
Mario de Sousa <msousa@fe.up.pt>
parents:
2714
diff
changeset
|
1189 |
loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1190 |
loc_vars_list.append(str(iecvar["NAME"])) |
2714
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1191 |
# Add if it is a "Modbus Request Status flag" (mapped onto %QWa.b.c.0.1), so last number is a '1' |
2717
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1192 |
# -> will store the result of the last executed MB transaction |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1193 |
# 1 -> error accessing IP network, or serial interface |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1194 |
# 2 -> reply received from server was an invalid frame |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1195 |
# 3 -> server did not reply before timeout expired |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1196 |
# 4 -> server returned a valid Modbus error frame |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1197 |
# -> will be reset (set to 0) once this MB transaction has completed sucesfully |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1198 |
if iecvar["LOC"][4] == 1: |
2714
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1199 |
loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid)) |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1200 |
loc_vars_list.append(str(iecvar["NAME"])) |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1201 |
# Add if it is a "Modbus Error code" (mapped onto %QWa.b.c.0.2), so last number is a '2' |
2717
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1202 |
# -> if "Modbus Request Status flag" is 4, this flag will store the MB error code returned by the MB server in a MB error frame |
b3b6991f1cb6
modbus plugin: add/fix comments
Mario de Sousa <msousa@fe.up.pt>
parents:
2715
diff
changeset
|
1203 |
# -> will be reset (set to 0) once this MB transaction has completed succesfully |
2714
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1204 |
if iecvar["LOC"][4] == 2: |
0b636dc947a2
Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents:
2713
diff
changeset
|
1205 |
loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid)) |
2713
680ea4684209
Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents:
2663
diff
changeset
|
1206 |
loc_vars_list.append(str(iecvar["NAME"])) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1207 |
client_requestid += 1 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1208 |
rtuclient_node_count += 1 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1209 |
client_nodeid += 1 |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1210 |
nodeid += 1 |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1211 |
|
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1212 |
loc_dict["loc_vars"] = "\n".join(loc_vars) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1213 |
loc_dict["server_nodes_params"] = ",\n\n".join(server_node_list) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1214 |
loc_dict["client_nodes_params"] = ",\n\n".join(client_node_list) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1215 |
loc_dict["client_req_params"] = ",\n\n".join(client_request_list) |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1216 |
loc_dict["tcpclient_reqs_count"] = str(tcpclient_reqs_count) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1217 |
loc_dict["tcpclient_node_count"] = str(tcpclient_node_count) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1218 |
loc_dict["tcpserver_node_count"] = str(tcpserver_node_count) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1219 |
loc_dict["rtuclient_reqs_count"] = str(rtuclient_reqs_count) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1220 |
loc_dict["rtuclient_node_count"] = str(rtuclient_node_count) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1221 |
loc_dict["rtuserver_node_count"] = str(rtuserver_node_count) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1222 |
loc_dict["ascclient_reqs_count"] = str(ascclient_reqs_count) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1223 |
loc_dict["ascclient_node_count"] = str(ascclient_node_count) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1224 |
loc_dict["ascserver_node_count"] = str(ascserver_node_count) |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1225 |
loc_dict["total_tcpnode_count"] = str(total_node_count[0]) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1226 |
loc_dict["total_rtunode_count"] = str(total_node_count[1]) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1227 |
loc_dict["total_ascnode_count"] = str(total_node_count[2]) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1228 |
loc_dict["max_remote_tcpclient"] = int( |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1229 |
self.GetParamsAttributes()[0]["children"][0]["value"]) |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1230 |
|
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1231 |
# get template file content into a string, format it with dict |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1232 |
# and write it to proper .h file |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1233 |
mb_main = open(h_filename).read() % loc_dict |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1234 |
f = open(Gen_MB_h_path, 'w') |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1235 |
f.write(mb_main) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1236 |
f.close() |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1237 |
# same thing as above, but now to .c file |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1238 |
mb_main = open(c_filename).read() % loc_dict |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1239 |
f = open(Gen_MB_c_path, 'w') |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1240 |
f.write(mb_main) |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1241 |
f.close() |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1242 |
|
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1243 |
LDFLAGS = [] |
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1244 |
LDFLAGS.append(" \"-L" + ModbusPath + "\"") |
2333
81abf93b4684
Path may contain spaces... sequel of d1359cb
Edouard Tisserant
parents:
2291
diff
changeset
|
1245 |
LDFLAGS.append(" \"" + os.path.join(ModbusPath, "libmb.a") + "\"") |
1909
bb883e063175
Add support for Modbus (TCP and RTU) working as master & slave
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1246 |
LDFLAGS.append(" \"-Wl,-rpath," + ModbusPath + "\"") |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1247 |
# LDFLAGS.append("\"" + os.path.join(ModbusPath, "mb_slave_and_master.o") + "\"") |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1248 |
# LDFLAGS.append("\"" + os.path.join(ModbusPath, "mb_slave.o") + "\"") |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1249 |
# LDFLAGS.append("\"" + os.path.join(ModbusPath, "mb_master.o") + "\"") |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1250 |
# LDFLAGS.append("\"" + os.path.join(ModbusPath, "mb_tcp.o") + "\"") |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1251 |
# LDFLAGS.append("\"" + os.path.join(ModbusPath, "mb_rtu.o") + "\"") |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1252 |
# LDFLAGS.append("\"" + os.path.join(ModbusPath, "mb_ascii.o") + "\"") |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1253 |
# LDFLAGS.append("\"" + os.path.join(ModbusPath, "sin_util.o") + "\"") |
1913
338e2f51b685
modbus extension code cleanup, from smarteh's patch
Edouard Tisserant
parents:
1909
diff
changeset
|
1254 |
# Target is ARM with linux and not win on x86 so winsock2 (ws2_32) library is useless !!! |
1918
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1255 |
# if os.name == 'nt': # other possible values: 'posix' 'os2' 'ce' 'java' 'riscos' |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1256 |
# LDFLAGS.append(" -lws2_32 ") # on windows we need to load winsock |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1257 |
# library! |
e7b6478b4ebc
PEP8 conformity for modbus. Most of it done by autopep8, plus some easy refactoring.
Edouard Tisserant
parents:
1913
diff
changeset
|
1258 |
|
2669
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1259 |
websettingfile = open(paths.AbsNeighbourFile(__file__, "web_settings.py"), 'r') |
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1260 |
websettingcode = websettingfile.read() |
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1261 |
websettingfile.close() |
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1262 |
|
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1263 |
location_str = "_".join(map(str, self.GetCurrentLocation())) |
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1264 |
websettingcode = websettingcode % locals() |
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1265 |
|
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1266 |
runtimefile_path = os.path.join(buildpath, "runtime_modbus_websettings.py") |
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1267 |
runtimefile = open(runtimefile_path, 'w') |
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1268 |
runtimefile.write(websettingcode) |
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1269 |
runtimefile.close() |
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1270 |
|
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1271 |
return ([(Gen_MB_c_path, ' -I"' + ModbusPath + '"')], LDFLAGS, True, |
2703
32ffdb32b14e
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2677
diff
changeset
|
1272 |
("runtime_%s_modbus_websettings.py" % location_str, open(runtimefile_path, "rb")), |
2669
be233279d179
BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents:
2663
diff
changeset
|
1273 |
) |