The replace_io file can handle default values of type byte (frm="*s") now.

This commit is contained in:
2021-07-28 07:37:20 +02:00
parent a05770e4f8
commit 498d200e41
2 changed files with 20 additions and 2 deletions

View File

@@ -418,6 +418,19 @@ class RevPiModIO(object):
"defaultvalue '{1}' to boolean" "defaultvalue '{1}' to boolean"
"".format(io, creplaceio[io]["defaultvalue"]) "".format(io, creplaceio[io]["defaultvalue"])
) )
elif dict_replace["frm"].find("s") != 0:
buff = bytearray()
try:
dv_array = creplaceio[io].get("defaultvalue").split(" ")
for byte_int in dv_array:
buff.append(int(byte_int))
dict_replace["defaultvalue"] = bytes(buff)
except Exception as e:
raise ValueError(
"replace_io_file: could not convert '{0}' "
"defaultvalue to bytes | {1}"
"".format(io, e)
)
else: else:
try: try:
dict_replace["defaultvalue"] = \ dict_replace["defaultvalue"] = \
@@ -878,7 +891,12 @@ class RevPiModIO(object):
cp[io.name]["bit"] = str(io._bitaddress) cp[io.name]["bit"] = str(io._bitaddress)
if io._byteorder != "little": if io._byteorder != "little":
cp[io.name]["byteorder"] = io._byteorder cp[io.name]["byteorder"] = io._byteorder
if io.defaultvalue != 0: if type(io.defaultvalue) is bytes:
if any(io.defaultvalue):
# Convert each byte to an integer
cp[io.name]["defaultvalue"] = \
" ".join(map(str, io.defaultvalue))
elif io.defaultvalue != 0:
cp[io.name]["defaultvalue"] = str(io.defaultvalue) cp[io.name]["defaultvalue"] = str(io.defaultvalue)
if io.bmk != "": if io.bmk != "":
cp[io.name]["bmk"] = io.bmk cp[io.name]["bmk"] = io.bmk

View File

@@ -17,7 +17,7 @@ setup(
license="LGPLv3", license="LGPLv3",
name="revpimodio2", name="revpimodio2",
version="2.5.7", version="2.5.7b",
packages=["revpimodio2"], packages=["revpimodio2"],
python_requires="~=3.2", python_requires="~=3.2",