-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integrate message.encode() into framer.buildPacket. (#2062)
- Loading branch information
1 parent
16b63b1
commit 214c7ed
Showing
18 changed files
with
1,094 additions
and
887 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
"""Build framer encode responses.""" | ||
|
||
from pymodbus.factory import ClientDecoder, ServerDecoder | ||
from pymodbus.framer import ( | ||
ModbusAsciiFramer, | ||
ModbusRtuFramer, | ||
ModbusSocketFramer, | ||
ModbusTlsFramer, | ||
) | ||
from pymodbus.pdu import ModbusExceptions as merror | ||
from pymodbus.register_read_message import ( | ||
ReadHoldingRegistersRequest, | ||
ReadHoldingRegistersResponse, | ||
) | ||
|
||
|
||
def set_calls(): | ||
"""Define calls.""" | ||
for framer in (ModbusAsciiFramer, ModbusRtuFramer, ModbusSocketFramer, ModbusTlsFramer): | ||
print(f"framer --> {framer}") | ||
for dev_id in (0, 17, 255): | ||
print(f" dev_id --> {dev_id}") | ||
for tid in (0, 3077): | ||
print(f" tid --> {tid}") | ||
client = framer(ClientDecoder()) | ||
request = ReadHoldingRegistersRequest(124, 2, dev_id) | ||
request.transaction_id = tid | ||
result = client.buildPacket(request) | ||
print(f" request --> {result}") | ||
print(f" request --> {result.hex()}") | ||
server = framer(ServerDecoder()) | ||
response = ReadHoldingRegistersResponse([141,142]) | ||
response.slave_id = dev_id | ||
response.transaction_id = tid | ||
result = server.buildPacket(response) | ||
print(f" response --> {result}") | ||
print(f" response --> {result.hex()}") | ||
exception = request.doException(merror.IllegalAddress) | ||
exception.transaction_id = tid | ||
exception.slave_id = dev_id | ||
result = server.buildPacket(exception) | ||
print(f" exception --> {result}") | ||
print(f" exception --> {result.hex()}") | ||
|
||
set_calls() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.