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

Remove unused protocol_id from pdu #2340

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions examples/client_custom_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class CustomModbusResponse(ModbusResponse):
function_code = 55
_rtu_byte_count_pos = 2

def __init__(self, values=None, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, values=None, slave=1, transaction=0, skip_encode=False):
"""Initialize."""
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
ModbusResponse.__init__(self, slave, transaction, skip_encode)
self.values = values or []

def encode(self):
Expand Down Expand Up @@ -68,9 +68,9 @@ class CustomModbusRequest(ModbusRequest):
function_code = 55
_rtu_frame_size = 8

def __init__(self, address=None, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, address=None, slave=1, transaction=0, skip_encode=False):
"""Initialize."""
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
ModbusRequest.__init__(self, slave, transaction, skip_encode)
self.address = address
self.count = 16

Expand Down Expand Up @@ -100,12 +100,12 @@ def execute(self, context):
class Read16CoilsRequest(ReadCoilsRequest):
"""Read 16 coils in one request."""

def __init__(self, address, count=None, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, address, count=None, slave=1, transaction=0, skip_encode=False):
"""Initialize a new instance.

:param address: The address to start reading from
"""
ReadCoilsRequest.__init__(self, address, count=16, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode)
ReadCoilsRequest.__init__(self, address, count=16, slave=slave, transaction=transaction, skip_encode=skip_encode)


# --------------------------------------------------------------------------- #
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _helper(self, data: str):
function_code = int(data[0])
if not (request := self.lookup.get(function_code, lambda: None)()):
Log.debug("Factory Request[{}]", function_code)
request = pdu.IllegalFunctionRequest(function_code, 0, 0, 0, False)
request = pdu.IllegalFunctionRequest(function_code, 0, 0, False)
else:
fc_string = "{}: {}".format( # pylint: disable=consider-using-f-string
str(self.lookup[function_code]) # pylint: disable=use-maxsplit-arg
Expand Down
1 change: 0 additions & 1 deletion pymodbus/framer/old_framer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def populateResult(self, result):
"""
result.slave_id = self.dev_id
result.transaction_id = self.tid
result.protocol_id = 0

def processIncomingPacket(self, data: bytes, callback, slave, single=False, tid=None):
"""Process new packet pattern.
Expand Down
24 changes: 12 additions & 12 deletions pymodbus/pdu/bit_read_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class ReadBitsRequestBase(ModbusRequest):

_rtu_frame_size = 8

def __init__(self, address, count, slave, transaction, protocol, skip_encode):
def __init__(self, address, count, slave, transaction, skip_encode):
"""Initialize the read request data.

:param address: The start address to read from
:param count: The number of bits after "address" to read
:param slave: Modbus slave slave ID
"""
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
ModbusRequest.__init__(self, slave, transaction, skip_encode)
self.address = address
self.count = count

Expand Down Expand Up @@ -67,13 +67,13 @@ class ReadBitsResponseBase(ModbusResponse):

_rtu_byte_count_pos = 2

def __init__(self, values, slave, transaction, protocol, skip_encode):
def __init__(self, values, slave, transaction, skip_encode):
"""Initialize a new instance.

:param values: The requested values to be returned
:param slave: Modbus slave slave ID
"""
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
ModbusResponse.__init__(self, slave, transaction, skip_encode)

#: A list of booleans representing bit values
self.bits = values or []
Expand Down Expand Up @@ -138,14 +138,14 @@ class ReadCoilsRequest(ReadBitsRequestBase):
function_code = 1
function_code_name = "read_coils"

def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, address=None, count=None, slave=1, transaction=0, skip_encode=False):
"""Initialize a new instance.

:param address: The address to start reading from
:param count: The number of bits to read
:param slave: Modbus slave slave ID
"""
ReadBitsRequestBase.__init__(self, address, count, slave, transaction, protocol, skip_encode)
ReadBitsRequestBase.__init__(self, address, count, slave, transaction, skip_encode)

async def execute(self, context):
"""Run a read coils request against a datastore.
Expand Down Expand Up @@ -185,13 +185,13 @@ class ReadCoilsResponse(ReadBitsResponseBase):

function_code = 1

def __init__(self, values=None, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, values=None, slave=1, transaction=0, skip_encode=False):
"""Initialize a new instance.

:param values: The request values to respond with
:param slave: Modbus slave slave ID
"""
ReadBitsResponseBase.__init__(self, values, slave, transaction, protocol, skip_encode)
ReadBitsResponseBase.__init__(self, values, slave, transaction, skip_encode)


class ReadDiscreteInputsRequest(ReadBitsRequestBase):
Expand All @@ -206,14 +206,14 @@ class ReadDiscreteInputsRequest(ReadBitsRequestBase):
function_code = 2
function_code_name = "read_discrete_input"

def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, address=None, count=None, slave=1, transaction=0, skip_encode=False):
"""Initialize a new instance.

:param address: The address to start reading from
:param count: The number of bits to read
:param slave: Modbus slave slave ID
"""
ReadBitsRequestBase.__init__(self, address, count, slave, transaction, protocol, skip_encode)
ReadBitsRequestBase.__init__(self, address, count, slave, transaction, skip_encode)

async def execute(self, context):
"""Run a read discrete input request against a datastore.
Expand Down Expand Up @@ -253,10 +253,10 @@ class ReadDiscreteInputsResponse(ReadBitsResponseBase):

function_code = 2

def __init__(self, values=None, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, values=None, slave=1, transaction=0, skip_encode=False):
"""Initialize a new instance.

:param values: The request values to respond with
:param slave: Modbus slave slave ID
"""
ReadBitsResponseBase.__init__(self, values, slave, transaction, protocol, skip_encode)
ReadBitsResponseBase.__init__(self, values, slave, transaction, skip_encode)
16 changes: 8 additions & 8 deletions pymodbus/pdu/bit_write_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class WriteSingleCoilRequest(ModbusRequest):

_rtu_frame_size = 8

def __init__(self, address=None, value=None, slave=None, transaction=0, protocol=0, skip_encode=0):
def __init__(self, address=None, value=None, slave=None, transaction=0, skip_encode=0):
"""Initialize a new instance.

:param address: The variable address to write
:param value: The value to write at address
"""
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
ModbusRequest.__init__(self, slave, transaction, skip_encode)
self.address = address
self.value = bool(value)

Expand Down Expand Up @@ -113,13 +113,13 @@ class WriteSingleCoilResponse(ModbusResponse):
function_code = 5
_rtu_frame_size = 8

def __init__(self, address=None, value=None, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, address=None, value=None, slave=1, transaction=0, skip_encode=False):
"""Initialize a new instance.

:param address: The variable address written to
:param value: The value written at address
"""
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
ModbusResponse.__init__(self, slave, transaction, skip_encode)
self.address = address
self.value = value

Expand Down Expand Up @@ -167,13 +167,13 @@ class WriteMultipleCoilsRequest(ModbusRequest):
function_code_name = "write_coils"
_rtu_byte_count_pos = 6

def __init__(self, address=None, values=None, slave=None, transaction=0, protocol=0, skip_encode=0):
def __init__(self, address=None, values=None, slave=None, transaction=0, skip_encode=0):
"""Initialize a new instance.

:param address: The starting request address
:param values: The values to write
"""
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
ModbusRequest.__init__(self, slave, transaction, skip_encode)
self.address = address
if values is None:
values = []
Expand Down Expand Up @@ -250,13 +250,13 @@ class WriteMultipleCoilsResponse(ModbusResponse):
function_code = 15
_rtu_frame_size = 8

def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, address=None, count=None, slave=1, transaction=0, skip_encode=False):
"""Initialize a new instance.

:param address: The starting variable address written to
:param count: The number of values written
"""
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
ModbusResponse.__init__(self, slave, transaction, skip_encode)
self.address = address
self.count = count

Expand Down
40 changes: 20 additions & 20 deletions pymodbus/pdu/diag_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class DiagnosticStatusRequest(ModbusRequest):
function_code_name = "diagnostic_status"
_rtu_frame_size = 8

def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, slave=1, transaction=0, skip_encode=False):
"""Initialize a diagnostic request."""
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
ModbusRequest.__init__(self, slave, transaction, skip_encode)
self.message = None

def encode(self):
Expand Down Expand Up @@ -93,9 +93,9 @@ class DiagnosticStatusResponse(ModbusResponse):
function_code = 0x08
_rtu_frame_size = 8

def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, slave=1, transaction=0, skip_encode=False):
"""Initialize a diagnostic response."""
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
ModbusResponse.__init__(self, slave, transaction, skip_encode)
self.message = None

def encode(self):
Expand Down Expand Up @@ -150,15 +150,15 @@ class DiagnosticStatusSimpleRequest(DiagnosticStatusRequest):
the execute method
"""

def __init__(self, data=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, data=0x0000, slave=1, transaction=0, skip_encode=False):
"""Initialize a simple diagnostic request.

The data defaults to 0x0000 if not provided as over half
of the functions require it.

:param data: The data to send along with the request
"""
DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode)
DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode)
self.message = data

async def execute(self, *args):
Expand All @@ -175,12 +175,12 @@ class DiagnosticStatusSimpleResponse(DiagnosticStatusResponse):
2 bytes of data.
"""

def __init__(self, data=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, data=0x0000, slave=1, transaction=0, skip_encode=False):
"""Return a simple diagnostic response.

:param data: The resulting data to return to the client
"""
DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode)
DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode)
self.message = data


Expand All @@ -197,12 +197,12 @@ class ReturnQueryDataRequest(DiagnosticStatusRequest):

sub_function_code = 0x0000

def __init__(self, message=b"\x00\x00", slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, message=b"\x00\x00", slave=1, transaction=0, skip_encode=False):
"""Initialize a new instance of the request.

:param message: The message to send to loopback
"""
DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode)
DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode)
if not isinstance(message, bytes):
raise ModbusException(f"message({type(message)}) must be bytes")
self.message = message
Expand All @@ -225,12 +225,12 @@ class ReturnQueryDataResponse(DiagnosticStatusResponse):

sub_function_code = 0x0000

def __init__(self, message=b"\x00\x00", slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, message=b"\x00\x00", slave=1, transaction=0, skip_encode=False):
"""Initialize a new instance of the response.

:param message: The message to loopback
"""
DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode)
DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode)
if not isinstance(message, bytes):
raise ModbusException(f"message({type(message)}) must be bytes")
self.message = message
Expand All @@ -252,12 +252,12 @@ class RestartCommunicationsOptionRequest(DiagnosticStatusRequest):

sub_function_code = 0x0001

def __init__(self, toggle=False, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, toggle=False, slave=1, transaction=0, skip_encode=False):
"""Initialize a new request.

:param toggle: Set to True to toggle, False otherwise
"""
DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode)
DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode)
if toggle:
self.message = [ModbusStatus.ON]
else:
Expand Down Expand Up @@ -285,12 +285,12 @@ class RestartCommunicationsOptionResponse(DiagnosticStatusResponse):

sub_function_code = 0x0001

def __init__(self, toggle=False, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, toggle=False, slave=1, transaction=0, skip_encode=False):
"""Initialize a new response.

:param toggle: Set to True if we toggled, False otherwise
"""
DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode)
DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode)
if toggle:
self.message = [ModbusStatus.ON]
else:
Expand Down Expand Up @@ -396,9 +396,9 @@ class ForceListenOnlyModeResponse(DiagnosticStatusResponse):
sub_function_code = 0x0004
should_respond = False

def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, slave=1, transaction=0, skip_encode=False):
"""Initialize to block a return response."""
DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode)
DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode)
self.message = []


Expand Down Expand Up @@ -778,9 +778,9 @@ class GetClearModbusPlusRequest(DiagnosticStatusSimpleRequest):

sub_function_code = 0x0015

def __init__(self, data=0, slave=1, transaction=0, protocol=0, skip_encode=False):
def __init__(self, data=0, slave=1, transaction=0, skip_encode=False):
"""Initialize."""
super().__init__(slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode)
super().__init__(slave=slave, transaction=transaction, skip_encode=skip_encode)
self.message=data

def get_response_pdu_size(self):
Expand Down
Loading