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

Updated Message_Parser example #2079

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Changes from all commits
Commits
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
15 changes: 6 additions & 9 deletions examples/message_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import logging
import textwrap

from pymodbus import pymodbus_apply_logging_config
from pymodbus.factory import ClientDecoder, ServerDecoder
from pymodbus.transaction import (
ModbusAsciiFramer,
Expand Down Expand Up @@ -80,15 +81,10 @@ def decode(self, message):
print(f"{decoder.decoder.__class__.__name__}")
print("-" * 80)
try:
decoder.addToFrame(message)
if decoder.checkFrame():
slave = decoder._header.get( # pylint: disable=protected-access
"uid", 0x00
)
decoder.advanceFrame()
decoder.processIncomingPacket(message, self.report, slave)
else:
self.check_errors(decoder, message)
slave = decoder._header.get( # pylint: disable=protected-access
"uid", 0x00
)
decoder.processIncomingPacket(message, self.report, slave)
except Exception: # pylint: disable=broad-except
self.check_errors(decoder, message)

Expand Down Expand Up @@ -144,6 +140,7 @@ def report(self, message):
def parse_messages(cmdline=None):
"""Do a helper method to generate the messages to parse."""
args = get_commandline(cmdline=cmdline)
pymodbus_apply_logging_config(args.log.upper())
_logger.setLevel(args.log.upper())
if not args.message:
_logger.error("Missing --message.")
Expand Down