On line 440
elif type(plc_datatype) is tuple:
bytecount = bytes_from_dict(
values=var[i], structure_def=plc_datatype
)
values=var[i] should be values=var. When var is a dict, doing getitem on the for-loop index is not meaningful, it is not a list.
Also, do not reuse variables and overwrite values, makes debugging a pain.