lpcmanager

Fix so PLC code can use IEC60870 variables
iec60870
8 weeks ago, Dino Kosic
9d54aa733b96
Fix so PLC code can use IEC60870 variables
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Helpers for IEC 60870-5-104 Beremiz plugin (CS104 server runtime generation)."""
from __future__ import absolute_import
try:
from six.moves import xrange
except ImportError:
xrange = range
def GetCTVal(child, index):
"""Return attribute value from first XSD element by child index order."""
return child.GetParamsAttributes()[0]["children"][index]["value"]
def GetCTValByName(child, elem_name, attr_name):
"""Fetch attribute value by element name and attribute name."""
for element in child.GetParamsAttributes():
if element["name"] != elem_name:
continue
for ch in element["children"]:
if ch["name"] == attr_name:
return ch["value"]
raise KeyError((elem_name, attr_name))
def iec_iec_type_to_bind_kind(iec_type):
"""Maps PLC located variable IEC type to iec60870_bind_kind (see iec60870_runtime.c)."""
m = {
"BOOL": 0,
"BYTE": 1,
"INT": 2,
"WORD": 3,
"REAL": 4,
"UDINT": 5,
}
return m.get(iec_type, 0)