Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor / improve python modbus #1581

Merged
merged 173 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 161 commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
a5d746d
fix(plc4py/umas): Start to add write support
hutcheb Mar 7, 2024
ebfe381
build(deps): bump github.com/stretchr/testify in /plc4go (#1439)
dependabot[bot] Mar 11, 2024
02a6f24
build(deps): bump golang.org/x/tools from 0.18.0 to 0.19.0 in /plc4go…
dependabot[bot] Mar 11, 2024
4e1f5bc
build(deps): bump logback.version from 1.5.0 to 1.5.1 (#1435)
dependabot[bot] Mar 11, 2024
f65dbd7
build(deps): bump github.com/gdamore/tcell/v2 in /plc4go (#1438)
dependabot[bot] Mar 11, 2024
eb662d4
build(deps): bump golang.org/x/net from 0.21.0 to 0.22.0 in /plc4go (…
dependabot[bot] Mar 11, 2024
061ebfc
build(deps): bump jakarta.activation:jakarta.activation-api (#1436)
dependabot[bot] Mar 11, 2024
39538e0
fix(plc4j/genericcan) Fix of generic CAN driver and CAN transports af…
splatch Mar 11, 2024
9352b0a
chore: Disabled a flaky test in GO
chrisdutz Mar 13, 2024
539d252
docs: Updated the url for the opie tool
chrisdutz Mar 13, 2024
604ba8a
chore: Updated vendor ids
chrisdutz Mar 13, 2024
22b3099
docs: Added some information on the site plugin and the asciidoctor p…
chrisdutz Mar 13, 2024
0f5f2f4
chore: Updated vendor ids
chrisdutz Mar 13, 2024
5723fad
build: Continued fine-tuning the reproducible build release-scripts.
chrisdutz Mar 13, 2024
52009e3
chore: Updated vendor ids
chrisdutz Mar 13, 2024
8323caf
feat: The S7 driver now returns supporting S7, if the connected devic…
chrisdutz Mar 13, 2024
53adbaf
fix: Fixed logging in the example.
chrisdutz Mar 13, 2024
ba11ff1
refactor: Made the "protocol" accessible in the AbstractPlcConnection
chrisdutz Mar 13, 2024
215d1bf
refactor: Added S7-400 to the list of supported devices.
chrisdutz Mar 13, 2024
49b882d
fix: Fixed the dependency usage error.
chrisdutz Mar 13, 2024
bc874ea
Fix/s7async (#1451)
glcj Mar 15, 2024
575bf83
build(deps): bump com.google.googlejavaformat:google-java-format (#1449)
dependabot[bot] Mar 18, 2024
3a15b84
build(deps): bump logback.version from 1.5.1 to 1.5.3 (#1448)
dependabot[bot] Mar 18, 2024
e295259
build(deps): bump com.gradle:common-custom-user-data-maven-extension …
dependabot[bot] Mar 18, 2024
3b21a8c
Update PlcRawByteArray.java (#1453)
mrwhy-orig Mar 18, 2024
a90e492
chore: Disabled some OPC-UA tests, that were continuously failing the…
chrisdutz Mar 18, 2024
1f20465
chore: Disabled some OPC-UA tests, that were continuously failing the…
chrisdutz Mar 18, 2024
55efeec
feat: Added a new flag allowing to disable tests on Jenkins. Added th…
chrisdutz Mar 18, 2024
f596a26
build(deps-dev): bump org.apache.commons:commons-compress (#1456)
dependabot[bot] Mar 20, 2024
f694abf
build(deps): bump org.awaitility:awaitility from 4.2.0 to 4.2.1 (#1455)
dependabot[bot] Mar 20, 2024
8933491
docs: Added "slave-id" to the description of the unit-identifier.
chrisdutz Mar 21, 2024
195e4ad
chore: Disabled the OpcuaPlcDriverTest as it also seems to regularly …
chrisdutz Mar 21, 2024
0b68f16
build(deps): bump org.springframework.boot:spring-boot-maven-plugin (…
dependabot[bot] Mar 22, 2024
0511e3c
build(deps): bump com.google.errorprone:error_prone_annotations (#1461)
dependabot[bot] Mar 22, 2024
07350bd
build(deps): bump org.springframework.boot:spring-boot-dependencies (…
dependabot[bot] Mar 22, 2024
11920e1
docs: Updated some documentation on the code-generation.
chrisdutz Mar 22, 2024
e594988
refactor: Renamed the paddingField paddingCondition to timesPadding
chrisdutz Mar 22, 2024
ed8dae0
chore: Removed some unneeded code.
chrisdutz Mar 22, 2024
934aa11
chore: Updated vendor ids
chrisdutz Mar 22, 2024
ae38064
chore: Cleaned up in the sandbox
chrisdutz Mar 23, 2024
016ad77
fix(plc4py): type extensions module added to setup.py
hutcheb Mar 23, 2024
80b75aa
fix(plc4py): Move out of sandbox
hutcheb Mar 23, 2024
dab01f0
chore(sandbox): Remove the Sandbox Directory
hutcheb Mar 23, 2024
90d671b
chore(plc4px): Remove manual test
hutcheb Mar 23, 2024
cb5714b
feat(plc4x/modbus): Add support for unit-id option for modbus tags.
splatch Mar 27, 2024
2ea34de
build(deps): bump nl.jqno.equalsverifier:equalsverifier (#1467)
dependabot[bot] Apr 2, 2024
71fb92f
build(deps): bump org.cyclonedx:cyclonedx-maven-plugin (#1466)
dependabot[bot] Apr 2, 2024
508a18c
build(deps): bump org.apache.maven.plugins:maven-remote-resources-plu…
dependabot[bot] Apr 2, 2024
3c03181
build(deps): bump org.aspectj:aspectjweaver from 1.9.21.1 to 1.9.22 (…
dependabot[bot] Apr 3, 2024
3652bb4
build(deps): bump jakarta.xml.bind:jakarta.xml.bind-api (#1474)
dependabot[bot] Apr 3, 2024
86060a1
build(deps): bump com.google.guava:guava from 33.0.0-jre to 33.1.0-jr…
dependabot[bot] Apr 3, 2024
efc10e9
build(deps): bump golang.org/x/net from 0.22.0 to 0.23.0 in /plc4go (…
dependabot[bot] Apr 4, 2024
3c2b30c
build(deps): bump mockito.version from 5.10.0 to 5.11.0 (#1478)
dependabot[bot] Apr 4, 2024
0157fe0
build(deps): bump io.swagger:swagger-annotations from 1.6.13 to 1.6.1…
dependabot[bot] Apr 4, 2024
a47ea37
build(deps): bump org.sonarsource.scanner.maven:sonar-maven-plugin (#…
dependabot[bot] Apr 4, 2024
2489556
Update PlcCHAR.java add Character type check to of method (#1489)
mrwhy-orig Apr 5, 2024
2e3d44b
build(deps): bump golang.org/x/net from 0.23.0 to 0.24.0 in /plc4go (…
dependabot[bot] Apr 5, 2024
da2aa30
build(deps): bump groovy.version from 4.0.18 to 4.0.20 (#1486)
dependabot[bot] Apr 5, 2024
2da79f2
build(deps): bump org.jacoco:jacoco-maven-plugin from 0.8.11 to 0.8.1…
dependabot[bot] Apr 5, 2024
03a2588
build(deps): bump org.apache.maven.plugins:maven-source-plugin (#1484)
dependabot[bot] Apr 5, 2024
6f9bcce
build(deps): bump golang.org/x/tools from 0.19.0 to 0.20.0 in /plc4go…
dependabot[bot] Apr 5, 2024
fb0e145
fix: A compilation error.
chrisdutz Apr 5, 2024
cc17fe5
refactor: Moved the examples, integrations and other extra stuff into…
chrisdutz Apr 5, 2024
820d3aa
fix: Disabling "Trivy Scan" workflow as it's randomy failing and I ca…
chrisdutz Apr 5, 2024
b67f559
chore: Updated the issue-tracker settings to point to GitHub instead …
chrisdutz Apr 5, 2024
33030f9
build(deps): bump nl.jqno.equalsverifier:equalsverifier (#1490)
dependabot[bot] Apr 8, 2024
373fd86
build(deps): bump org.apache.maven.plugins:maven-assembly-plugin (#1491)
dependabot[bot] Apr 8, 2024
e818b67
fix(plc4py): Fix exception on closing the connection
hutcheb Apr 9, 2024
c41e3a3
fix(plc4py): Fix connection lost exception being raised
hutcheb Apr 9, 2024
57c52e6
fix(plc4py): set test to manual
hutcheb Apr 9, 2024
e229c54
fix(plc4py): Got rid of returning future, starting to understand it a…
hutcheb Apr 9, 2024
a238c00
build(deps): bump jakarta.annotation:jakarta.annotation-api (#1494)
dependabot[bot] Apr 9, 2024
a0d41fd
build(deps): bump io.netty:netty-bom from 4.1.107.Final to 4.1.108.Fi…
dependabot[bot] Apr 9, 2024
24e59ef
fix(plc4py): Add to dependabot
hutcheb Apr 9, 2024
bdaacf2
build(deps): bump pytest-mock from 3.12.0 to 3.14.0 in /plc4py (#1501)
dependabot[bot] Apr 9, 2024
65a2325
build(deps): bump identify from 2.5.33 to 2.5.35 in /plc4py (#1500)
dependabot[bot] Apr 9, 2024
9e2fd21
build(deps): bump packaging from 23.2 to 24.0 in /plc4py (#1499)
dependabot[bot] Apr 9, 2024
debb8a6
build(deps): bump pytest-asyncio from 0.23.5 to 0.23.6 in /plc4py (#1…
dependabot[bot] Apr 9, 2024
1c27f79
build(deps): bump build from 1.0.3 to 1.2.1 in /plc4py (#1496)
dependabot[bot] Apr 9, 2024
004c2f8
fix(plc4py): Use packet length estimator to be able to handle multipl…
hutcheb Apr 12, 2024
ecfadf9
Update apache-kafka links to plc4x extra
ottlukas Apr 10, 2024
adf1568
feat(plc4go): change to TestingLog interface for TestLogger
sruehl Apr 10, 2024
2599310
build(deps): bump com.fasterxml.jackson.datatype:jackson-datatype-jsr…
dependabot[bot] Apr 11, 2024
a095a17
build(deps): bump com.gradle:common-custom-user-data-maven-extension …
dependabot[bot] Apr 11, 2024
84d6802
build(deps): bump mypy from 1.8.0 to 1.9.0 in /plc4py (#1502)
dependabot[bot] Apr 11, 2024
b85c765
build(deps): bump black from 24.1.1 to 24.3.0 in /plc4py (#1503)
dependabot[bot] Apr 11, 2024
6a6bade
build(deps): bump filelock from 3.13.1 to 3.13.4 in /plc4py (#1504)
dependabot[bot] Apr 11, 2024
6911bc9
build(deps): bump virtualenv from 20.25.0 to 20.25.1 in /plc4py (#1506)
dependabot[bot] Apr 11, 2024
7fb8b42
build(deps): bump typing-extensions from 4.9.0 to 4.11.0 in /plc4py (…
dependabot[bot] Apr 11, 2024
6f4bed9
build(deps): bump org.apache.maven.plugins:maven-invoker-plugin (#1514)
dependabot[bot] Apr 12, 2024
e5b90c6
build(deps): bump org.asciidoctor:asciidoctorj from 2.5.11 to 2.5.12 …
dependabot[bot] Apr 12, 2024
0f9520a
build(deps): bump com.google.googlejavaformat:google-java-format (#1516)
dependabot[bot] Apr 12, 2024
5fa88da
build(deps): bump coverage from 7.4.1 to 7.4.4 in /plc4py (#1511)
dependabot[bot] Apr 12, 2024
cb15079
build(deps): bump pytest from 8.0.0 to 8.1.1 in /plc4py (#1510)
dependabot[bot] Apr 12, 2024
906fa87
build(deps): bump pre-commit from 3.6.0 to 3.7.0 in /plc4py (#1512)
dependabot[bot] Apr 12, 2024
e551fb7
build(deps): bump pip-tools from 7.3.0 to 7.4.1 in /plc4py (#1513)
dependabot[bot] Apr 12, 2024
4da7244
fix(plc4j/ads): Fixed List serialization passing invalid datatype for…
IsmoLeszczynski Apr 12, 2024
b7529aa
feat: Changed the ManualTest to allow enabling read and write request…
chrisdutz Apr 12, 2024
dd5aad4
fix(plc4j/opcua): Cleanup discovery connection resources.
splatch Apr 12, 2024
3589478
fix(plc4j/ads): Invalid size writing multiple tags (#1524)
IsmoLeszczynski Apr 13, 2024
d4c2066
fix: Added the struct back to the manual ads test.
chrisdutz Apr 13, 2024
8a2f138
fix(plc4j/opcua): Make sure UA subscription acknowledges are retained…
splatch Apr 14, 2024
c98e9fc
chore: Updated vendor ids
chrisdutz Apr 14, 2024
ea61a35
chore: Addressed most high severity sonarcloud issues
chrisdutz Apr 14, 2024
257aff4
build(deps): bump black from 24.3.0 to 24.4.0 in /plc4py (#1528)
dependabot[bot] Apr 15, 2024
beaf82b
build(deps): bump org.apache.maven.plugins:maven-compiler-plugin (#1525)
dependabot[bot] Apr 15, 2024
1faae83
build(deps): bump org.codehaus.plexus:plexus-compiler-api (#1526)
dependabot[bot] Apr 15, 2024
11267a2
build(deps): bump com.google.errorprone:error_prone_annotations (#1527)
dependabot[bot] Apr 15, 2024
73913e0
build(deps): bump logback.version from 1.5.3 to 1.5.5 (#1531)
dependabot[bot] Apr 16, 2024
0872d89
build(deps): bump io.netty:netty-bom from 4.1.108.Final to 4.1.109.Fi…
dependabot[bot] Apr 16, 2024
384471f
build(deps): bump groovy.version from 4.0.20 to 4.0.21 (#1533)
dependabot[bot] Apr 16, 2024
cd38cb0
fix(plc4j/ads): Fixed connection hang on exception (#1530)
IsmoLeszczynski Apr 16, 2024
08f9260
build(deps): bump virtualenv from 20.25.1 to 20.25.2 in /plc4py (#1537)
dependabot[bot] Apr 17, 2024
6d42733
Remove Protocols section in developers section (duplicate from
ottlukas Apr 17, 2024
af6a4b8
Delete src/site/asciidoc/developers/protocols directory
ottlukas Apr 17, 2024
0ab6465
chore: Updated vendor ids
chrisdutz Apr 17, 2024
1c320f5
feat: Added a default-payload-byte-order option to the modbus driver …
chrisdutz Apr 17, 2024
63094a3
chore: Addressed more of the high severity sonarcloud issues
chrisdutz Apr 17, 2024
d8720ad
build(deps): bump slf4j.version from 2.0.12 to 2.0.13 (#1536)
dependabot[bot] Apr 17, 2024
b9846ed
build(deps): bump org.jetbrains.kotlin:kotlin-stdlib-jdk8 (#1534)
dependabot[bot] Apr 17, 2024
60f079d
Revert "Remove Protocols section in developers section (duplicate from "
ottlukas Apr 17, 2024
ab46e7a
Revert "Delete src/site/asciidoc/developers/protocols directory"
ottlukas Apr 17, 2024
c8bb411
Modbus in progress
ottlukas Apr 18, 2024
8e59aec
add index for protocol usage page
ottlukas Apr 18, 2024
12e646f
Add eip
ottlukas Apr 18, 2024
0d3ee01
fixing URLs
ottlukas Apr 18, 2024
5256375
build(deps): bump org.apache.commons:commons-configuration2 (#1541)
dependabot[bot] Apr 18, 2024
663034d
build(deps): bump org.apache.karaf.tooling:karaf-maven-plugin (#1539)
dependabot[bot] Apr 18, 2024
06cda0f
build(deps): bump com.googlecode.maven-download-plugin:download-maven…
dependabot[bot] Apr 18, 2024
ea50932
build(deps): bump virtualenv from 20.25.2 to 20.25.3 in /plc4py (#1542)
dependabot[bot] Apr 18, 2024
4cdd64a
build(deps): bump net.bytebuddy:byte-buddy from 1.14.12 to 1.14.13 (#…
dependabot[bot] Apr 19, 2024
71121e3
build(deps-dev): bump commons-io:commons-io from 2.15.1 to 2.16.1 (#1…
dependabot[bot] Apr 19, 2024
6212b0a
build(deps): bump org.apache.commons:commons-text from 1.11.0 to 1.12…
dependabot[bot] Apr 19, 2024
a95115d
chore: Made line-breaks in the configuration option descriptions get …
chrisdutz Apr 19, 2024
4dd77dd
chore: Updated vendor ids
chrisdutz Apr 19, 2024
834ab08
feat: Added device-group options for local, remote and remote2 to the…
chrisdutz Apr 19, 2024
8efab49
chore: Disabled the OpcuaSubscriptionHandleTest all together as it al…
chrisdutz Apr 19, 2024
4fffc88
feat: Added a "Since" annotation that provides information on when a …
chrisdutz Apr 19, 2024
75342ba
feat: Create a source bundle for PLC4C
chrisdutz Apr 19, 2024
8c87b04
chore: Added newly generated files.
chrisdutz Apr 19, 2024
f346f9f
build(deps): bump org.codehaus.mojo:extra-enforcer-rules (#1548)
dependabot[bot] Apr 22, 2024
85ee0bc
build(deps): bump logback.version from 1.5.5 to 1.5.6 (#1549)
dependabot[bot] Apr 22, 2024
6981261
build(deps): bump bouncycastle.version from 1.77 to 1.78.1 (#1550)
dependabot[bot] Apr 22, 2024
b1fabc9
build(deps): bump identify from 2.5.35 to 2.5.36 in /plc4py (#1546)
dependabot[bot] Apr 22, 2024
6c514bf
build(deps): bump pluggy from 1.4.0 to 1.5.0 in /plc4py (#1547)
dependabot[bot] Apr 22, 2024
431b9e3
build(deps): bump com.fazecast:jSerialComm from 2.10.4 to 2.11.0 (#1554)
dependabot[bot] Apr 23, 2024
104313f
feat(plc4j/api): Convert the string address into a PlcTag (#1468)
qtvbwfn Apr 23, 2024
fcfa85e
build(deps): bump commons-logging:commons-logging from 1.3.0 to 1.3.1…
dependabot[bot] Apr 23, 2024
b0aa7aa
build(deps-dev): bump org.json:json from 20240205 to 20240303 (#1552)
dependabot[bot] Apr 23, 2024
0fcc8b2
build(deps): bump org.apache.maven.plugins:maven-jar-plugin (#1559)
dependabot[bot] Apr 24, 2024
5762d51
build(deps): bump virtualenv from 20.25.3 to 20.26.0 in /plc4py (#1555)
dependabot[bot] Apr 24, 2024
8abefe6
build(deps): bump platformdirs from 4.2.0 to 4.2.1 in /plc4py (#1556)
dependabot[bot] Apr 24, 2024
109efa1
build(deps): bump coverage from 7.4.4 to 7.5.0 in /plc4py (#1557)
dependabot[bot] Apr 24, 2024
435edd7
build(deps): bump net.bytebuddy:byte-buddy from 1.14.13 to 1.14.14 (#…
dependabot[bot] Apr 25, 2024
1c684a8
build(deps): bump commons-cli:commons-cli from 1.6.0 to 1.7.0 (#1563)
dependabot[bot] Apr 25, 2024
720cdc9
build(deps): bump org.apache:apache from 31 to 32 (#1558)
dependabot[bot] Apr 25, 2024
453eef4
Change Python version to 3.10+
ottlukas Apr 25, 2024
bb63281
fix(plc4py/umas): Start to add write support
hutcheb Mar 7, 2024
c0f0f67
rebase umas
ottlukas Apr 25, 2024
67274f5
Merge branch 'develop' into feat/plc4py/umas_write_support
ottlukas May 1, 2024
3876158
Some small changes to python code
ottlukas May 3, 2024
46c0f7a
add additional comments in python code
ottlukas May 3, 2024
3e9054a
Merge branch 'develop' into Refactor-/-Improve-Python-Modbus
ottlukas May 7, 2024
e7a0510
fix(plc4py): Fix optional fields and clean some template stuff up
hutcheb May 8, 2024
d870810
Reset to capture timeouts
ottlukas May 8, 2024
7fc2b1f
Revert "Reset to capture timeouts"
ottlukas May 8, 2024
bc9b82a
Adding commentary / explaination for PLC4Py
ottlukas May 10, 2024
5799461
Merge branch 'develop' into Refactor-/-Improve-Python-Modbus
ottlukas May 10, 2024
e0735e8
some smaller changes
ottlukas May 10, 2024
26b333a
fix(plc4py): start to make the umas and modbus drivers act similialy.
hutcheb May 10, 2024
d751833
fix(plc4py/umas): Start to add write support
ottlukas May 15, 2024
13e9f79
Merge branch 'develop' into Refactor-/-Improve-Python-Modbus
ottlukas May 15, 2024
74de652
add @pytest.mark.xfail so that PLC4Py build succeeds (to be changed o…
ottlukas May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -768,17 +768,18 @@ private String toTernaryTermExpression(Field field, TypeReference fieldType, Ter
Term b = ternaryTerm.getB();
Term c = ternaryTerm.getC();
String castExpressionForTypeReference = getCastExpressionForTypeReference(fieldType);
String inlineIf = "utils.InlineIf(" + toExpression(field, new DefaultBooleanTypeReference(), a, parserArguments, serializerArguments, serialize, false) + ", " +
"func() any {return " + castExpressionForTypeReference + "(" + toExpression(field, fieldType, b, parserArguments, serializerArguments, serialize, false) + ")}, " +
"func() any {return " + castExpressionForTypeReference + "(" + toExpression(field, fieldType, c, parserArguments, serializerArguments, serialize, false) + ")})";
String inlineIf = castExpressionForTypeReference + "(" + toExpression(field, fieldType, b, parserArguments, serializerArguments, serialize, false) + ") if " +
toExpression(field, new DefaultBooleanTypeReference(), a, parserArguments, serializerArguments, serialize, false) + " else " +
castExpressionForTypeReference + "(" + toExpression(field, fieldType, c, parserArguments, serializerArguments, serialize, false) + ")";

if (fieldType != null) {
if (fieldType instanceof ByteOrderTypeReference) {
return tracer.dive("byteordertypereference") + "(" + inlineIf + ").(binary.ByteOrder)";
}
if (fieldType.isNonSimpleTypeReference()) {
return tracer.dive("nonsimpletypereference") + castExpressionForTypeReference + "(" + inlineIf + ")";
}
return tracer + inlineIf + ".(" + castExpressionForTypeReference + ")";
return tracer + inlineIf;
}
return tracer + inlineIf;
} else {
Expand Down Expand Up @@ -1289,7 +1290,7 @@ private String toCastVariableExpression(Field field, TypeReference typeReference

private String toOptionalVariableExpression(Field field, TypeReference typeReference, VariableLiteral variableLiteral, List<Argument> parserArguments, List<Argument> serializerArguments, boolean suppressPointerAccess, Tracer tracer) {
tracer = tracer.dive("optional fields");
return tracer + "(" + (suppressPointerAccess || (typeReference != null && typeReference.isComplexTypeReference()) ? "" : "*") + variableLiteral.getName() + ")" +
return tracer + "(" + (suppressPointerAccess || (typeReference != null && typeReference.isComplexTypeReference()) ? "" : "") + camelCaseToSnakeCase(variableLiteral.getName()) + ")" +
variableLiteral.getChild().map(child -> "." + camelCaseToSnakeCase(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, false, suppressPointerAccess, true))).orElse("");
}

Expand Down
8 changes: 0 additions & 8 deletions plc4go/protocols/knxnetip/readwrite/model/KnxManufacturer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions plc4py/plc4py/drivers/modbus/ModbusConfiguration.py
ottlukas marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ class ModbusConfiguration(PlcConfiguration):
def __init__(self, url):
super().__init__(url)

if self.transport is None:
self.transport = "tcp"

if self.port is None:
self.port = 502

if "unit_identifier" not in self.parameters:
self.unit_identifier = 1
self.transport = self.transport or "tcp"
self.port = self.port or 502
self.unit_identifier = self.parameters.get("unit_identifier", 1)
39 changes: 18 additions & 21 deletions plc4py/plc4py/drivers/modbus/ModbusConnection.py
ottlukas marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,12 @@ def __init__(self, config: ModbusConfiguration, transport: Plc4xBaseTransport):
self._transport: Plc4xBaseTransport = transport

@staticmethod
async def create(url: str):
"""
Static Factory to return an instance of a ModbusConnection.
It creates the TCP connection to the Modbus device before returning.

:param url: PLC4X connection string of the Modbus TCP connection
:return ModbusConnection instance using the configuration from the url provided
"""
config = ModbusConfiguration(url)
loop = asyncio.get_running_loop()
connection_future = loop.create_future()
transport = await asyncio.wait_for(
TCPTransport.create(
protocol_factory=lambda: ModbusProtocol(connection_future),
host=config.host,
port=config.port,
),
10,
async def create(connection_string: str) -> "ModbusConnection":
config = ModbusConfiguration(connection_string)
transport = await TCPTransport.create(
protocol_factory=lambda: ModbusProtocol(connection_future),
host=config.host,
port=config.port,
)
return ModbusConnection(config, transport)

Expand Down Expand Up @@ -108,22 +96,31 @@ def read_request_builder(self) -> ReadRequestBuilder:

async def execute(self, request: PlcRequest) -> PlcResponse:
"""
Executes a PlcRequest as long as it's already connected
Executes a PlcRequest as long as it's already connected.

:param request: Plc Request to execute
:return: The response from the Plc/Device
"""
# Check if the connection is established
if not self.is_connected():
# Return a default failed response if not connected
return self._default_failed_request(PlcResponseCode.NOT_CONNECTED)

# Check the type of the request and execute the corresponding method
if isinstance(request, PlcReadRequest):
# Execute a read request
return await self._read(request)
elif isinstance(request, PlcWriteRequest):
# Execute a write request
return await self._write(request)

# Return a default failed response if the request type is not supported
return self._default_failed_request(PlcResponseCode.NOT_CONNECTED)

def _check_connection(self) -> bool:
return self._device is None

def _connection_established(self) -> bool:
"""Check if the connection to the PLC is established."""
return self._device is not None

async def _read(self, request: PlcReadRequest) -> PlcReadResponse:
"""
Expand Down
11 changes: 6 additions & 5 deletions plc4py/plc4py/drivers/umas/UmasDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
from plc4py.protocols.umas.readwrite.UmasUnlocatedVariableReference import (
UmasUnlocatedVariableReference,
)
from plc4py.protocols.umas.readwrite.VariableRequestReference import (
VariableRequestReference,
from plc4py.protocols.umas.readwrite.VariableReadRequestReference import (
VariableReadRequestReference,
)
from plc4py.spi.generation.ReadBuffer import ReadBufferByteBased
from plc4py.spi.messages.utils.ResponseItem import ResponseItem
Expand Down Expand Up @@ -351,7 +351,7 @@ async def _send_read_variable_request(
):
message_future = loop.create_future()

sorted_variable_list: List[VariableRequestReference] = [
sorted_variable_list: List[VariableReadRequestReference] = [
variable_reference[1] for variable_reference in sorted_tags
]
request_pdu = UmasPDUReadVariableRequestBuilder(
Expand Down Expand Up @@ -391,7 +391,7 @@ async def _send_read_variable_request(
return response

def _sort_tags_based_on_memory_address(self, request):
tag_list: List[List[Tuple[str, VariableRequestReference]]] = [[]]
tag_list: List[List[Tuple[str, VariableReadRequestReference]]] = [[]]
current_list_index = 0
current_list = tag_list[current_list_index]
byte_count: int = 0
Expand All @@ -412,7 +412,8 @@ def _sort_tags_based_on_memory_address(self, request):
variable.get_variable_reference(umas_tag.tag_name),
)
)
sorted_tag_lists: List[List[Tuple[str, VariableRequestReference]]] = []

sorted_tag_lists: List[List[Tuple[str, VariableReadRequestReference]]] = []
for request in tag_list:
sorted_tags = sorted(
request,
Expand Down
20 changes: 10 additions & 10 deletions plc4py/plc4py/drivers/umas/UmasVariables.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

from plc4py.protocols.umas.readwrite.UmasDataType import UmasDataType

from plc4py.protocols.umas.readwrite.VariableRequestReference import (
VariableRequestReference,
from plc4py.protocols.umas.readwrite.VariableReadRequestReference import (
VariableReadRequestReference,
)

from plc4py.api.exceptions.exceptions import PlcDataTypeNotFoundException
Expand All @@ -42,7 +42,7 @@ class UmasVariable:
block_no: int
offset: int

def get_variable_reference(self, address: str) -> VariableRequestReference:
def get_variable_reference(self, address: str) -> VariableReadRequestReference:
raise NotImplementedError(
f"UmasVariable subclass not implemented for variable {self.variable_name}"
)
Expand All @@ -55,9 +55,9 @@ def get_byte_length(self) -> int:

@dataclass
class UmasElementryVariable(UmasVariable):
def get_variable_reference(self, address: str) -> VariableRequestReference:
def get_variable_reference(self, address: str) -> VariableReadRequestReference:
if self.data_type == UmasDataType.STRING.value:
return VariableRequestReference(
return VariableReadRequestReference(
is_array=1,
data_size_index=UmasDataType(self.data_type).request_size,
block=self.block_no,
Expand All @@ -66,7 +66,7 @@ def get_variable_reference(self, address: str) -> VariableRequestReference:
array_length=16,
)
else:
return VariableRequestReference(
return VariableReadRequestReference(
is_array=0,
data_size_index=UmasDataType(self.data_type).request_size,
block=self.block_no,
Expand All @@ -83,7 +83,7 @@ def get_byte_length(self) -> int:
class UmasCustomVariable(UmasVariable):
children: Dict[str, UmasVariable]

def get_variable_reference(self, address: str) -> VariableRequestReference:
def get_variable_reference(self, address: str) -> VariableReadRequestReference:
split_tag_address: List[str] = address.split(".")
child_index = None
if len(split_tag_address) > 1:
Expand All @@ -106,14 +106,14 @@ class UmasArrayVariable(UmasVariable):
start_index: int
end_index: int

def get_variable_reference(self, address: str) -> VariableRequestReference:
def get_variable_reference(self, address: str) -> VariableReadRequestReference:
split_tag_address: List[str] = address.split(".")
address_index = None
if len(split_tag_address) > 1:
address_index = int(split_tag_address[1])
data_type_enum = UmasDataType(self.data_type)
if address_index:
return VariableRequestReference(
return VariableReadRequestReference(
is_array=0,
data_size_index=data_type_enum.request_size,
block=self.block_no,
Expand All @@ -123,7 +123,7 @@ def get_variable_reference(self, address: str) -> VariableRequestReference:
array_length=None,
)
else:
return VariableRequestReference(
return VariableReadRequestReference(
is_array=1,
data_size_index=data_type_enum.request_size,
block=self.block_no,
Expand Down
19 changes: 19 additions & 0 deletions plc4py/plc4py/protocols/umas/readwrite/UmasPDUItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ def static_parse_context(
builder = UmasPDUReadVariableRequest.static_parse_builder(
read_buffer, umas_request_function_key, byte_length
)
from plc4py.protocols.umas.readwrite.UmasPDUWriteVariableRequest import (
UmasPDUWriteVariableRequest,
)

if umas_function_key == int(0x23):

builder = UmasPDUWriteVariableRequest.static_parse_builder(
read_buffer, umas_request_function_key, byte_length
)

from plc4py.protocols.umas.readwrite.UmasPDUReadUnlocatedVariableNamesRequest import (
UmasPDUReadUnlocatedVariableNamesRequest,
)
Expand Down Expand Up @@ -256,6 +266,15 @@ def static_parse_context(
builder = UmasPDUReadVariableResponse.static_parse_builder(
read_buffer, umas_request_function_key, byte_length
)
from plc4py.protocols.umas.readwrite.UmasPDUWriteVariableResponse import (
UmasPDUWriteVariableResponse,
)

if umas_function_key == int(0xFE) and umas_request_function_key == int(0x23):

builder = UmasPDUWriteVariableResponse.static_parse_builder(
read_buffer, umas_request_function_key, byte_length
)
from plc4py.protocols.umas.readwrite.UmasPDUReadUnlocatedVariableResponse import (
UmasPDUReadUnlocatedVariableResponse,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from plc4py.api.exceptions.exceptions import SerializationException
from plc4py.api.messages.PlcMessage import PlcMessage
from plc4py.protocols.umas.readwrite.UmasPDUItem import UmasPDUItem
from plc4py.protocols.umas.readwrite.VariableRequestReference import (
VariableRequestReference,
from plc4py.protocols.umas.readwrite.VariableReadRequestReference import (
VariableReadRequestReference,
)
from plc4py.spi.generation.ReadBuffer import ReadBuffer
from plc4py.spi.generation.WriteBuffer import WriteBuffer
Expand All @@ -39,7 +39,7 @@
class UmasPDUReadVariableRequest(UmasPDUItem):
crc: int
variable_count: int
variables: List[VariableRequestReference]
variables: List[VariableReadRequestReference]
# Arguments.
byte_length: int
# Accessors for discriminator values.
Expand Down Expand Up @@ -106,7 +106,7 @@ def static_parse_builder(

variables: List[Any] = read_buffer.read_array_field(
logical_name="variables",
read_function=VariableRequestReference.static_parse,
read_function=VariableReadRequestReference.static_parse,
count=variable_count,
byte_order=ByteOrder.LITTLE_ENDIAN,
umas_request_function_key=umas_request_function_key,
Expand Down Expand Up @@ -151,7 +151,7 @@ def __str__(self) -> str:
class UmasPDUReadVariableRequestBuilder:
crc: int
variable_count: int
variables: List[VariableRequestReference]
variables: List[VariableReadRequestReference]

def build(self, byte_length: int, pairing_key) -> UmasPDUReadVariableRequest:
umas_pdu_read_variable_request: UmasPDUReadVariableRequest = (
Expand Down
Loading
Loading