Skip to content

Commit

Permalink
fix(plc4py): Continue working through help docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
hutcheb committed Mar 4, 2024
1 parent f4a6511 commit 59abb39
Show file tree
Hide file tree
Showing 8 changed files with 522 additions and 392 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,13 @@ class ${type.name}:
<#else>
<#assign defaultCaseOutput=true>
</#if>

<#list case.fields as field>
<#switch field.typeName>
<#case "array">
<#assign arrayField=field.asArrayField().orElseThrow()>
<#assign elementTypeReference=arrayField.type.elementTypeReference>
values: PlcList = _value

<@emitImport import="from typing import cast" />
values: PlcList = cast(PlcList, _value)
<#if case.name == "Struct">
for val in values.getStruct().get("${arrayField.name}").get_list():
<#if elementTypeReference.isByteBased()>
Expand Down Expand Up @@ -396,22 +395,26 @@ class ${type.name}:
# Const Field (${constField.name})
${helper.getWriteBufferWriteMethodCall(constField.type.asSimpleTypeReference().orElseThrow(), constField.referenceValue, constField)}
<#break>

<#case "enum">
<#assign enumField=field.asEnumField().orElseThrow()>
# Enum field (${enumField.name})
${enumField.name}: ${helper.getLanguageTypeNameForField(field)} = _value.get_${helper.camelCaseToSnakeCase(enumField.name?cap_first)}()
${helper.getWriteBufferWriteMethodCall(helper.getEnumBaseTypeReference(field.asTypedField().orElseThrow().type), "(" + enumField.name + ".value)", enumField)}
<#break>

<#case "manual">
<#assign manualField=field.asManualField().orElseThrow()>
# Manual Field (${manualField.name})
${helper.toSerializationExpression(manualField, manualField.type, manualField.serializeExpression, type.parserArguments.orElse(null))}
<#break>

<#case "reserved">
<#assign reservedField=field.asReservedField().orElseThrow()>
# Reserved Field
${helper.getWriteBufferWriteMethodCall(reservedField.type.asSimpleTypeReference().orElseThrow(), helper.getReservedValue(reservedField), reservedField)}
<#break>

<#case "simple">
<#assign simpleField=field.asSimpleField().orElseThrow()>
# Simple Field (${simpleField.name})
Expand All @@ -429,10 +432,13 @@ class ${type.name}:
</#if>
<#if simpleField.type.isSimpleTypeReference()>
${helper.getWriteBufferWriteMethodCall(simpleField.type.asSimpleTypeReference().orElseThrow(), "(" + simpleField.name + ")", simpleField)}

<#else>
${simpleField.type.asComplexTypeReference().orElseThrow().name}IO.static_serialize(write_buffer, ${helper.camelCaseToSnakeCase(simpleField.name)})

</#if>
<#break>

</#switch>
</#list>
<#sep><@compress single_line=true>elif </@compress></#sep></#list>
Expand All @@ -451,9 +457,7 @@ class ${type.name}:
size_in_bits: int = 0
<#assign defaultCaseOutput=false>
<#assign dataIoTypeDefinition=type.asDataIoTypeDefinition().orElseThrow()>
<#list dataIoTypeDefinition.switchField.orElseThrow().cases as case>
<#if case.discriminatorValueTerms?has_content>
if <@compress single_line=true>
if <#list dataIoTypeDefinition.switchField.orElseThrow().cases as case><#if case.discriminatorValueTerms?has_content> <@compress single_line=true>
<#list case.discriminatorValueTerms as discriminatorValueTerm>
<#assign discriminatorExpression=dataIoTypeDefinition.switchField.orElseThrow().discriminatorExpressions[discriminatorValueTerm?index].asLiteral().orElseThrow().asVariableLiteral().orElseThrow()>
<#assign discriminatorType=helper.getDiscriminatorTypes()[discriminatorExpression.name]>
Expand All @@ -463,7 +467,7 @@ class ${type.name}:
<#else>
${helper.toParseExpression(dataIoTypeDefinition.switchField.orElseThrow(), discriminatorType, discriminatorValueTerm, parserArguments)}
</#if>
<#sep> and </#sep>
<#sep> & </#sep>
</#list>
</@compress>: # ${case.name}
<#else>
Expand All @@ -474,7 +478,8 @@ class ${type.name}:
<#case "array">
<#assign arrayField=field.asArrayField().orElseThrow()>
<#assign elementTypeReference=arrayField.type.elementTypeReference>
values: PlcList = _value
<@emitImport import="from typing import cast" />
values: PlcList = cast(PlcList, _value)
<#if case.name == "Struct">
# TODO: Finish this!
<#elseif elementTypeReference.isComplexTypeReference()>
Expand Down Expand Up @@ -511,7 +516,7 @@ class ${type.name}:
<#break>
</#switch>
</#list>
<#sep></#sep></#list>
<#sep><@compress single_line=true>elif </@compress></#sep></#list>
return size_in_bits


Expand Down
28 changes: 28 additions & 0 deletions sandbox/plc4py/plc4py/drivers/mock/MockConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,34 @@ async def _request(req, device) -> PlcReadResponse:
future = asyncio.ensure_future(_request(request, self.device))
return future

def is_read_supported(self) -> bool:
"""
Indicates if the connection supports read requests.
:return: True if connection supports reading, False otherwise
"""
return True

def is_write_supported(self) -> bool:
"""
Indicates if the connection supports write requests.
:return: True if connection supports writing, False otherwise
"""
return False

def is_subscribe_supported(self) -> bool:
"""
Indicates if the connection supports subscription requests.
:return: True if connection supports subscriptions, False otherwise
"""
return False

def is_browse_supported(self) -> bool:
"""
Indicates if the connection supports browsing requests.
:return: True if connection supports browsing, False otherwise
"""
return False


class MockDriver(PlcDriver):
def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion sandbox/plc4py/plc4py/drivers/modbus/ModbusConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def is_write_supported(self) -> bool:
Indicates if the connection supports write requests.
:return: True if connection supports writing, False otherwise
"""
return True
return False

def is_subscribe_supported(self) -> bool:
"""
Expand Down
Loading

0 comments on commit 59abb39

Please sign in to comment.