Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/modbus-optimizer' into f…
Browse files Browse the repository at this point in the history
…eature/modbus-optimizer

# Conflicts:
#	plc4py/plc4py/protocols/modbus/readwrite/DataItem.py
#	plc4py/plc4py/protocols/modbus/readwrite/ModbusDataType.py
#	plc4py/plc4py/protocols/simulated/readwrite/DataItem.py
  • Loading branch information
chrisdutz committed Sep 5, 2024
2 parents f17ae22 + c190229 commit 424b2f1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ${type.name}:
<#if discriminatorType.isEnumTypeReference()>
${helper.getLanguageTypeNameForTypeReference(discriminatorType)}.${helper.toParseExpression(dataIoTypeDefinition.switchField.orElseThrow(), discriminatorType, discriminatorValueTerm, parserArguments)}
<#else>
${helper.camelCaseToSnakeCase(helper.toParseExpression(dataIoTypeDefinition.switchField.orElseThrow(), discriminatorType, discriminatorValueTerm, parserArguments))}
${helper.toParseExpression(dataIoTypeDefinition.switchField.orElseThrow(), discriminatorType, discriminatorValueTerm, parserArguments)}
</#if>
<#sep> and </#sep>
</#list>
Expand Down Expand Up @@ -131,7 +131,7 @@ class ${type.name}:
)
</@compress>

<#-- A terminated array keeps on reading data as long as the termination expression evaluates to false -->
<#-- A terminated array keeps on reading data as long as the termination expression evaluates to False -->
<#elseif arrayField.isTerminatedArrayField()>
# Terminated array
${arrayField.name}: ${helper.getNonPrimitiveLanguageTypeNameForField(arrayField)} = new LinkedList<>()
Expand Down Expand Up @@ -377,8 +377,8 @@ class ${type.name}:
for val in values.get_list():
<#if elementTypeReference.isByteBased()>
<@emitImport import="from typing import List" />
value: list[byte] = val.get_raw()
write_buffer.write_byte_array("", value)
value: ${helper.getLanguageTypeNameForField(arrayField)} = val.get_raw()
write_buffer.write_byte_array("", value)
<#else>
value: ${helper.getLanguageTypeNameForTypeReference(elementTypeReference)} = val.get_${helper.camelCaseToSnakeCase(helper.getLanguageTypeNameForTypeReference(elementTypeReference)?cap_first)}()
${helper.getWriteBufferWriteMethodCall(elementTypeReference.asSimpleTypeReference().orElseThrow(), "(" + arrayField.name + ")", arrayField)}
Expand All @@ -387,7 +387,7 @@ class ${type.name}:

<#if case.name == "BOOL">
while write_buffer.getPos() < len(write_buffer.get_data()):
write_buffer.write_bit(false)
write_buffer.write_bit(False)
</#if>
<#break>
<#case "const">
Expand Down
16 changes: 8 additions & 8 deletions plc4py/plc4py/protocols/modbus/readwrite/DataItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def static_parse(
if (
data_type == ModbusDataType.BOOL
and number_of_values == int(1)
and big_endian == true
and big_endian == True
): # BOOL

# Reserved Field (Compartmentalized so the "reserved" variable can't leak)
Expand All @@ -79,7 +79,7 @@ def static_parse(
if (
data_type == ModbusDataType.BOOL
and number_of_values == int(1)
and big_endian == false
and big_endian == False
): # BOOL

# Reserved Field (Compartmentalized so the "reserved" variable can't leak)
Expand Down Expand Up @@ -120,7 +120,7 @@ def static_parse(
if (
data_type == ModbusDataType.BYTE
and number_of_values == int(1)
and big_endian == true
and big_endian == True
): # BYTE

# Reserved Field (Compartmentalized so the "reserved" variable can't leak)
Expand All @@ -141,7 +141,7 @@ def static_parse(
if (
data_type == ModbusDataType.BYTE
and number_of_values == int(1)
and big_endian == false
and big_endian == False
): # BYTE

# Simple Field (value)
Expand Down Expand Up @@ -189,7 +189,7 @@ def static_parse(
if (
data_type == ModbusDataType.SINT
and number_of_values == int(1)
and big_endian == true
and big_endian == True
): # SINT

# Reserved Field (Compartmentalized so the "reserved" variable can't leak)
Expand All @@ -210,7 +210,7 @@ def static_parse(
if (
data_type == ModbusDataType.SINT
and number_of_values == int(1)
and big_endian == false
and big_endian == False
): # SINT

# Simple Field (value)
Expand Down Expand Up @@ -287,7 +287,7 @@ def static_parse(
if (
data_type == ModbusDataType.USINT
and number_of_values == int(1)
and big_endian == true
and big_endian == True
): # USINT

# Reserved Field (Compartmentalized so the "reserved" variable can't leak)
Expand All @@ -308,7 +308,7 @@ def static_parse(
if (
data_type == ModbusDataType.USINT
and number_of_values == int(1)
and big_endian == false
and big_endian == False
): # USINT

# Simple Field (value)
Expand Down
72 changes: 36 additions & 36 deletions plc4py/plc4py/protocols/simulated/readwrite/DataItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
class DataItem:
@staticmethod
def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int):
if data_type == "_bool" and number_of_values == int(1): # BOOL
if data_type == "BOOL" and number_of_values == int(1): # BOOL

# Simple Field (value)
value: bool = read_buffer.read_bit("")

return PlcBOOL(value)
if data_type == "_bool": # List
if data_type == "BOOL": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -63,13 +63,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
value.append(PlcBOOL(bool(read_buffer.read_bit(""))))

return PlcList(value)
if data_type == "_byte" and number_of_values == int(1): # BYTE
if data_type == "BYTE" and number_of_values == int(1): # BYTE

# Simple Field (value)
value: int = read_buffer.read_unsigned_short(8, logical_name="")

return PlcBYTE(value)
if data_type == "_byte": # List
if data_type == "BYTE": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -80,13 +80,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_word" and number_of_values == int(1): # WORD
if data_type == "WORD" and number_of_values == int(1): # WORD

# Simple Field (value)
value: int = read_buffer.read_unsigned_int(16, logical_name="")

return PlcWORD(value)
if data_type == "_word": # List
if data_type == "WORD": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -97,13 +97,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_dword" and number_of_values == int(1): # DWORD
if data_type == "DWORD" and number_of_values == int(1): # DWORD

# Simple Field (value)
value: int = read_buffer.read_unsigned_long(32, logical_name="")

return PlcDWORD(value)
if data_type == "_dword": # List
if data_type == "DWORD": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -114,13 +114,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_lword" and number_of_values == int(1): # LWORD
if data_type == "LWORD" and number_of_values == int(1): # LWORD

# Simple Field (value)
value: int = read_buffer.read_unsigned_long(64, logical_name="")

return PlcLWORD(value)
if data_type == "_lword": # List
if data_type == "LWORD": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -131,13 +131,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_sint" and number_of_values == int(1): # SINT
if data_type == "SINT" and number_of_values == int(1): # SINT

# Simple Field (value)
value: int = read_buffer.read_signed_byte(8, logical_name="")

return PlcSINT(value)
if data_type == "_sint": # List
if data_type == "SINT": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -148,13 +148,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_int" and number_of_values == int(1): # INT
if data_type == "INT" and number_of_values == int(1): # INT

# Simple Field (value)
value: int = read_buffer.read_short(16, logical_name="")

return PlcINT(value)
if data_type == "_int": # List
if data_type == "INT": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -163,13 +163,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
value.append(PlcINT(int(read_buffer.read_short(16, logical_name=""))))

return PlcList(value)
if data_type == "_dint" and number_of_values == int(1): # DINT
if data_type == "DINT" and number_of_values == int(1): # DINT

# Simple Field (value)
value: int = read_buffer.read_int(32, logical_name="")

return PlcDINT(value)
if data_type == "_dint": # List
if data_type == "DINT": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -178,13 +178,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
value.append(PlcDINT(int(read_buffer.read_int(32, logical_name=""))))

return PlcList(value)
if data_type == "_lint" and number_of_values == int(1): # LINT
if data_type == "LINT" and number_of_values == int(1): # LINT

# Simple Field (value)
value: int = read_buffer.read_long(64, logical_name="")

return PlcLINT(value)
if data_type == "_lint": # List
if data_type == "LINT": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -193,13 +193,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
value.append(PlcLINT(int(read_buffer.read_long(64, logical_name=""))))

return PlcList(value)
if data_type == "_usint" and number_of_values == int(1): # USINT
if data_type == "USINT" and number_of_values == int(1): # USINT

# Simple Field (value)
value: int = read_buffer.read_unsigned_short(8, logical_name="")

return PlcUSINT(value)
if data_type == "_usint": # List
if data_type == "USINT": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -210,13 +210,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_uint" and number_of_values == int(1): # UINT
if data_type == "UINT" and number_of_values == int(1): # UINT

# Simple Field (value)
value: int = read_buffer.read_unsigned_int(16, logical_name="")

return PlcUINT(value)
if data_type == "_uint": # List
if data_type == "UINT": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -227,13 +227,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_udint" and number_of_values == int(1): # UDINT
if data_type == "UDINT" and number_of_values == int(1): # UDINT

# Simple Field (value)
value: int = read_buffer.read_unsigned_long(32, logical_name="")

return PlcUDINT(value)
if data_type == "_udint": # List
if data_type == "UDINT": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -244,13 +244,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_ulint" and number_of_values == int(1): # ULINT
if data_type == "ULINT" and number_of_values == int(1): # ULINT

# Simple Field (value)
value: int = read_buffer.read_unsigned_long(64, logical_name="")

return PlcULINT(value)
if data_type == "_ulint": # List
if data_type == "ULINT": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -261,13 +261,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_real" and number_of_values == int(1): # REAL
if data_type == "REAL" and number_of_values == int(1): # REAL

# Simple Field (value)
value: float = read_buffer.read_float(32, logical_name="")

return PlcREAL(value)
if data_type == "_real": # List
if data_type == "REAL": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -278,13 +278,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_lreal" and number_of_values == int(1): # LREAL
if data_type == "LREAL" and number_of_values == int(1): # LREAL

# Simple Field (value)
value: float = read_buffer.read_double(64, logical_name="")

return PlcLREAL(value)
if data_type == "_lreal": # List
if data_type == "LREAL": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -295,13 +295,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_char" and number_of_values == int(1): # CHAR
if data_type == "CHAR" and number_of_values == int(1): # CHAR

# Simple Field (value)
value: str = read_buffer.read_str(8, logical_name="", encoding="")

return PlcCHAR(value)
if data_type == "_char": # List
if data_type == "CHAR": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -314,13 +314,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_wchar" and number_of_values == int(1): # WCHAR
if data_type == "WCHAR" and number_of_values == int(1): # WCHAR

# Simple Field (value)
value: str = read_buffer.read_str(16, logical_name="", encoding="")

return PlcWCHAR(value)
if data_type == "_wchar": # List
if data_type == "WCHAR": # List
# Array field (value)
# Count array
item_count: int = int(number_of_values)
Expand All @@ -333,13 +333,13 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int)
)

return PlcList(value)
if data_type == "_string": # STRING
if data_type == "STRING": # STRING

# Simple Field (value)
value: str = read_buffer.read_str(255, logical_name="", encoding="")

return PlcSTRING(value)
if data_type == "_wstring": # STRING
if data_type == "WSTRING": # STRING

# Simple Field (value)
value: str = read_buffer.read_str(255, logical_name="", encoding="")
Expand Down

0 comments on commit 424b2f1

Please sign in to comment.