diff --git a/examples/client_custom_msg.py b/examples/client_custom_msg.py index 395370a21..67be8d0e1 100755 --- a/examples/client_custom_msg.py +++ b/examples/client_custom_msg.py @@ -38,7 +38,7 @@ class CustomModbusPDU(ModbusPDU): def __init__(self, values=None, slave=1, transaction=0): """Initialize.""" - super().__init__(slave_id=slave, transaction_id=transaction) + super().__init__(dev_id=slave, transaction_id=transaction) self.values = values or [] def encode(self): @@ -70,7 +70,7 @@ class CustomRequest(ModbusPDU): def __init__(self, address=None, slave=1, transaction=0): """Initialize.""" - super().__init__(slave_id=slave, transaction_id=transaction) + super().__init__(dev_id=slave, transaction_id=transaction) self.address = address self.count = 16 @@ -105,7 +105,7 @@ def __init__(self, address, slave=1, transaction=0): :param address: The address to start reading from """ - super().__init__(address=address, count=16, slave_id=slave, transaction_id=transaction) + super().__init__(address=address, count=16, dev_id=slave, transaction_id=transaction) # --------------------------------------------------------------------------- # diff --git a/examples/modbus_forwarder.py b/examples/modbus_forwarder.py index 7933f1bb3..2a98e16da 100755 --- a/examples/modbus_forwarder.py +++ b/examples/modbus_forwarder.py @@ -56,7 +56,7 @@ async def run_forwarder(args): ) args.client.connect() assert args.client.connected - # If required to communicate with a specified client use slave= + # If required to communicate with a specified client use slave= # in RemoteSlaveContext # For e.g to forward the requests to slave with slave address 1 use # store = RemoteSlaveContext(client, slave=1) diff --git a/examples/server_async.py b/examples/server_async.py index 86166341d..d205be648 100755 --- a/examples/server_async.py +++ b/examples/server_async.py @@ -152,7 +152,7 @@ async def run_async_server(args): # custom_functions=[], # allow custom handling framer=args.framer, # The framer strategy to use # ignore_missing_slaves=True, # ignore request to a missing slave - # broadcast_enable=False, # treat slave_id 0 as broadcast address, + # broadcast_enable=False, # treat slave 0 as broadcast address, # timeout=1, # waiting time for request to complete ) elif args.comm == "udp": @@ -167,7 +167,7 @@ async def run_async_server(args): # custom_functions=[], # allow custom handling framer=args.framer, # The framer strategy to use # ignore_missing_slaves=True, # ignore request to a missing slave - # broadcast_enable=False, # treat slave_id 0 as broadcast address, + # broadcast_enable=False, # treat slave 0 as broadcast address, # timeout=1, # waiting time for request to complete ) elif args.comm == "serial": @@ -186,7 +186,7 @@ async def run_async_server(args): baudrate=args.baudrate, # The baud rate to use for the serial device # handle_local_echo=False, # Handle local echo of the USB-to-RS485 adaptor # ignore_missing_slaves=True, # ignore request to a missing slave - # broadcast_enable=False, # treat slave_id 0 as broadcast address, + # broadcast_enable=False, # treat slave 0 as broadcast address, ) elif args.comm == "tls": address = (args.host if args.host else "", args.port if args.port else None) @@ -207,7 +207,7 @@ async def run_async_server(args): ), # The key file path for TLS (used if sslctx is None) # password="none", # The password for for decrypting the private key file # ignore_missing_slaves=True, # ignore request to a missing slave - # broadcast_enable=False, # treat slave_id 0 as broadcast address, + # broadcast_enable=False, # treat slave 0 as broadcast address, # timeout=1, # waiting time for request to complete ) return server diff --git a/examples/server_sync.py b/examples/server_sync.py index 871acd5f6..7c735b2d2 100755 --- a/examples/server_sync.py +++ b/examples/server_sync.py @@ -78,7 +78,7 @@ def run_sync_server(args): # custom_functions=[], # allow custom handling framer=args.framer, # The framer strategy to use # ignore_missing_slaves=True, # ignore request to a missing slave - # broadcast_enable=False, # treat slave_id 0 as broadcast address, + # broadcast_enable=False, # treat slave 0 as broadcast address, # timeout=1, # waiting time for request to complete ) elif args.comm == "udp": @@ -90,7 +90,7 @@ def run_sync_server(args): # custom_functions=[], # allow custom handling framer=args.framer, # The framer strategy to use # ignore_missing_slaves=True, # ignore request to a missing slave - # broadcast_enable=False, # treat slave_id 0 as broadcast address, + # broadcast_enable=False, # treat slave 0 as broadcast address, # timeout=1, # waiting time for request to complete ) elif args.comm == "serial": @@ -109,7 +109,7 @@ def run_sync_server(args): baudrate=args.baudrate, # The baud rate to use for the serial device # handle_local_echo=False, # Handle local echo of the USB-to-RS485 adaptor # ignore_missing_slaves=True, # ignore request to a missing slave - # broadcast_enable=False, # treat slave_id 0 as broadcast address, + # broadcast_enable=False, # treat slave 0 as broadcast address, ) elif args.comm == "tls": address = ("", args.port) if args.port else None @@ -130,7 +130,7 @@ def run_sync_server(args): ), # The key file path for TLS (used if sslctx is None) # password=None, # The password for for decrypting the private key file # ignore_missing_slaves=True, # ignore request to a missing slave - # broadcast_enable=False, # treat slave_id 0 as broadcast address, + # broadcast_enable=False, # treat slave 0 as broadcast address, # timeout=1, # waiting time for request to complete ) return server diff --git a/pymodbus/client/mixin.py b/pymodbus/client/mixin.py index b40196eb3..e16b7e8ec 100644 --- a/pymodbus/client/mixin.py +++ b/pymodbus/client/mixin.py @@ -67,7 +67,7 @@ def read_coils(self, address: int, *, count: int = 1, slave: int = 1, no_respons Coils are addressed as 0-N (Note some device manuals uses 1-N, assuming 1==0). """ - return self.execute(no_response_expected, pdu_bit.ReadCoilsRequest(address=address, count=count, slave_id=slave)) + return self.execute(no_response_expected, pdu_bit.ReadCoilsRequest(address=address, count=count, dev_id=slave)) def read_discrete_inputs(self, address: int, @@ -87,7 +87,7 @@ def read_discrete_inputs(self, Discrete Inputs are addressed as 0-N (Note some device manuals uses 1-N, assuming 1==0). """ - pdu = pdu_bit.ReadDiscreteInputsRequest(address=address, count=count, slave_id=slave) + pdu = pdu_bit.ReadDiscreteInputsRequest(address=address, count=count, dev_id=slave) return self.execute(no_response_expected, pdu) def read_holding_registers(self, @@ -111,7 +111,7 @@ def read_holding_registers(self, Registers are addressed starting at zero. Therefore devices that specify 1-16 are addressed as 0-15. """ - return self.execute(no_response_expected, pdu_reg.ReadHoldingRegistersRequest(address=address, count=count, slave_id=slave)) + return self.execute(no_response_expected, pdu_reg.ReadHoldingRegistersRequest(address=address, count=count, dev_id=slave)) def read_input_registers(self, address: int, @@ -134,7 +134,7 @@ def read_input_registers(self, Registers are addressed starting at zero. Therefore devices that specify 1-16 are addressed as 0-15. """ - return self.execute(no_response_expected, pdu_reg.ReadInputRegistersRequest(address=address, count=count, slave_id=slave)) + return self.execute(no_response_expected, pdu_reg.ReadInputRegistersRequest(address=address, count=count, dev_id=slave)) def write_coil(self, address: int, value: bool, *, slave: int = 1, no_response_expected: bool = False) -> T: """Write single coil (code 0x05). @@ -149,7 +149,7 @@ def write_coil(self, address: int, value: bool, *, slave: int = 1, no_response_e Coils are addressed as 0-N (Note some device manuals uses 1-N, assuming 1==0). """ - pdu = pdu_bit.WriteSingleCoilRequest(address=address, bits=[value], slave_id=slave) + pdu = pdu_bit.WriteSingleCoilRequest(address=address, bits=[value], dev_id=slave) return self.execute(no_response_expected, pdu) def write_register(self, address: int, value: int, *, slave: int = 1, no_response_expected: bool = False) -> T: @@ -168,7 +168,7 @@ def write_register(self, address: int, value: int, *, slave: int = 1, no_respons Registers are addressed starting at zero. Therefore register numbered 1 is addressed as 0. """ - return self.execute(no_response_expected, pdu_reg.WriteSingleRegisterRequest(address=address, registers=[value], slave_id=slave)) + return self.execute(no_response_expected, pdu_reg.WriteSingleRegisterRequest(address=address, registers=[value], dev_id=slave)) def read_exception_status(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Read Exception Status (code 0x07). @@ -183,7 +183,7 @@ def read_exception_status(self, *, slave: int = 1, no_response_expected: bool = accessing this information, because the Exception Output references are known (no output reference is needed in the function). """ - return self.execute(no_response_expected, pdu_other_msg.ReadExceptionStatusRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_other_msg.ReadExceptionStatusRequest(dev_id=slave)) def diag_query_data(self, msg: bytes, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose query data (code 0x08 sub 0x00). @@ -197,7 +197,7 @@ def diag_query_data(self, msg: bytes, *, slave: int = 1, no_response_expected: b in the response. The entire response message should be identical to the request. """ - return self.execute(no_response_expected, pdu_diag.ReturnQueryDataRequest(msg, slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ReturnQueryDataRequest(msg, dev_id=slave)) def diag_restart_communication(self, toggle: bool, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose restart communication (code 0x08 sub 0x01). @@ -215,7 +215,7 @@ def diag_restart_communication(self, toggle: bool, *, slave: int = 1, no_respons occurs before the restart is update_datastored. """ msg = ModbusStatus.ON if toggle else ModbusStatus.OFF - return self.execute(no_response_expected, pdu_diag.RestartCommunicationsOptionRequest(message=msg, slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.RestartCommunicationsOptionRequest(message=msg, dev_id=slave)) def diag_read_diagnostic_register(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose read diagnostic register (code 0x08 sub 0x02). @@ -226,7 +226,7 @@ def diag_read_diagnostic_register(self, *, slave: int = 1, no_response_expected: The contents of the remote device's 16-bit diagnostic register are returned in the response. """ - return self.execute(no_response_expected, pdu_diag.ReturnDiagnosticRegisterRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ReturnDiagnosticRegisterRequest(dev_id=slave)) def diag_change_ascii_input_delimeter(self, *, delimiter: int = 0x0a, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose change ASCII input delimiter (code 0x08 sub 0x03). @@ -241,7 +241,7 @@ def diag_change_ascii_input_delimeter(self, *, delimiter: int = 0x0a, slave: int character). This function is useful in cases of a Line Feed is not required at the end of ASCII messages. """ - return self.execute(no_response_expected, pdu_diag.ChangeAsciiInputDelimiterRequest(message=delimiter, slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ChangeAsciiInputDelimiterRequest(message=delimiter, dev_id=slave)) def diag_force_listen_only(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose force listen only (code 0x08 sub 0x04). @@ -256,7 +256,7 @@ def diag_force_listen_only(self, *, slave: int = 1, no_response_expected: bool = allowing them to continue communicating without interruption from the addressed remote device. No response is returned. """ - return self.execute(no_response_expected, pdu_diag.ForceListenOnlyModeRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ForceListenOnlyModeRequest(dev_id=slave)) def diag_clear_counters(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose clear counters (code 0x08 sub 0x0A). @@ -267,7 +267,7 @@ def diag_clear_counters(self, *, slave: int = 1, no_response_expected: bool = Fa Clear ll counters and the diagnostic register. Also, counters are cleared upon power-up """ - return self.execute(no_response_expected, pdu_diag.ClearCountersRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ClearCountersRequest(dev_id=slave)) def diag_read_bus_message_count(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose read bus message count (code 0x08 sub 0x0B). @@ -280,7 +280,7 @@ def diag_read_bus_message_count(self, *, slave: int = 1, no_response_expected: b remote device has detected on the communications systems since its last restart, clear counters operation, or power-up """ - return self.execute(no_response_expected, pdu_diag.ReturnBusMessageCountRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ReturnBusMessageCountRequest(dev_id=slave)) def diag_read_bus_comm_error_count(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose read Bus Communication Error Count (code 0x08 sub 0x0C). @@ -293,7 +293,7 @@ def diag_read_bus_comm_error_count(self, *, slave: int = 1, no_response_expected by the remote device since its last restart, clear counter operation, or power-up """ - return self.execute(no_response_expected, pdu_diag.ReturnBusCommunicationErrorCountRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ReturnBusCommunicationErrorCountRequest(dev_id=slave)) def diag_read_bus_exception_error_count(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose read Bus Exception Error Count (code 0x08 sub 0x0D). @@ -306,7 +306,7 @@ def diag_read_bus_exception_error_count(self, *, slave: int = 1, no_response_exp responses returned by the remote device since its last restart, clear counters operation, or power-up """ - return self.execute(no_response_expected, pdu_diag.ReturnBusExceptionErrorCountRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ReturnBusExceptionErrorCountRequest(dev_id=slave)) def diag_read_slave_message_count(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose read Slave Message Count (code 0x08 sub 0x0E). @@ -319,7 +319,7 @@ def diag_read_slave_message_count(self, *, slave: int = 1, no_response_expected: remote device, that the remote device has processed since its last restart, clear counters operation, or power-up """ - return self.execute(no_response_expected, pdu_diag.ReturnSlaveMessageCountRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ReturnSlaveMessageCountRequest(dev_id=slave)) def diag_read_slave_no_response_count(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose read Slave No Response Count (code 0x08 sub 0x0F). @@ -332,7 +332,7 @@ def diag_read_slave_no_response_count(self, *, slave: int = 1, no_response_expec remote device, that the remote device has processed since its last restart, clear counters operation, or power-up. """ - return self.execute(no_response_expected, pdu_diag.ReturnSlaveNoResponseCountRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ReturnSlaveNoResponseCountRequest(dev_id=slave)) def diag_read_slave_nak_count(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose read Slave NAK Count (code 0x08 sub 0x10). @@ -346,7 +346,7 @@ def diag_read_slave_nak_count(self, *, slave: int = 1, no_response_expected: boo response, since its last restart, clear counters operation, or power-up. Exception responses are described and listed in section 7 . """ - return self.execute(no_response_expected, pdu_diag.ReturnSlaveNAKCountRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ReturnSlaveNAKCountRequest(dev_id=slave)) def diag_read_slave_busy_count(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose read Slave Busy Count (code 0x08 sub 0x11). @@ -359,7 +359,7 @@ def diag_read_slave_busy_count(self, *, slave: int = 1, no_response_expected: bo remote device for which it returned a Slave Device Busy exception response, since its last restart, clear counters operation, or power-up. """ - return self.execute(no_response_expected, pdu_diag.ReturnSlaveBusyCountRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ReturnSlaveBusyCountRequest(dev_id=slave)) def diag_read_bus_char_overrun_count(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose read Bus Character Overrun Count (code 0x08 sub 0x12). @@ -374,7 +374,7 @@ def diag_read_bus_char_overrun_count(self, *, slave: int = 1, no_response_expect overrun is caused by data characters arriving at the port faster than they can be stored, or by the loss of a character due to a hardware malfunction. """ - return self.execute(no_response_expected, pdu_diag.ReturnSlaveBusCharacterOverrunCountRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ReturnSlaveBusCharacterOverrunCountRequest(dev_id=slave)) def diag_read_iop_overrun_count(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose read Iop overrun count (code 0x08 sub 0x13). @@ -387,7 +387,7 @@ def diag_read_iop_overrun_count(self, *, slave: int = 1, no_response_expected: b faster than they can be stored, or by the loss of a character due to a hardware malfunction. This function is specific to the 884. """ - return self.execute(no_response_expected, pdu_diag.ReturnIopOverrunCountRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ReturnIopOverrunCountRequest(dev_id=slave)) def diag_clear_overrun_counter(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose Clear Overrun Counter and Flag (code 0x08 sub 0x14). @@ -399,7 +399,7 @@ def diag_clear_overrun_counter(self, *, slave: int = 1, no_response_expected: bo An error flag should be cleared, but nothing else in the specification mentions is, so it is ignored. """ - return self.execute(no_response_expected, pdu_diag.ClearOverrunCountRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.ClearOverrunCountRequest(dev_id=slave)) def diag_getclear_modbus_response(self, *, data: int = 0, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose Get/Clear modbus plus (code 0x08 sub 0x15). @@ -418,7 +418,7 @@ def diag_getclear_modbus_response(self, *, data: int = 0, slave: int = 1, no_res them. Statistics are also cleared on power-up of the slave device. """ - return self.execute(no_response_expected, pdu_diag.GetClearModbusPlusRequest(message=data, slave_id=slave)) + return self.execute(no_response_expected, pdu_diag.GetClearModbusPlusRequest(message=data, dev_id=slave)) def diag_get_comm_event_counter(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose get event counter (code 0x0B). @@ -440,7 +440,7 @@ def diag_get_comm_event_counter(self, *, slave: int = 1, no_response_expected: b The event counter can be reset by means of the Diagnostics function Restart Communications or Clear Counters and Diagnostic Register. """ - return self.execute(no_response_expected, pdu_other_msg.GetCommEventCounterRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_other_msg.GetCommEventCounterRequest(dev_id=slave)) def diag_get_comm_event_log(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Diagnose get event counter (code 0x0C). @@ -467,7 +467,7 @@ def diag_get_comm_event_log(self, *, slave: int = 1, no_response_expected: bool chronological order. Byte 0 is the most recent event. Each new byte flushes the oldest byte from the field. """ - return self.execute(no_response_expected, pdu_other_msg.GetCommEventLogRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_other_msg.GetCommEventLogRequest(dev_id=slave)) def write_coils( self, @@ -489,7 +489,7 @@ def write_coils( Coils are addressed as 0-N (Note some device manuals uses 1-N, assuming 1==0). """ - pdu = pdu_bit.WriteMultipleCoilsRequest(address=address, bits=values, slave_id=slave) + pdu = pdu_bit.WriteMultipleCoilsRequest(address=address, bits=values, dev_id=slave) return self.execute(no_response_expected, pdu) def write_registers( @@ -511,7 +511,7 @@ def write_registers( This function is used to write a block of contiguous registers (1 to approx. 120 registers) in a remote device. """ - return self.execute(no_response_expected, pdu_reg.WriteMultipleRegistersRequest(address=address, registers=values,slave_id=slave)) + return self.execute(no_response_expected, pdu_reg.WriteMultipleRegistersRequest(address=address, registers=values,dev_id=slave)) def report_slave_id(self, *, slave: int = 1, no_response_expected: bool = False) -> T: """Report slave ID (code 0x11). @@ -523,7 +523,7 @@ def report_slave_id(self, *, slave: int = 1, no_response_expected: bool = False) This function is used to read the description of the type, the current status and other information specific to a remote device. """ - return self.execute(no_response_expected, pdu_other_msg.ReportSlaveIdRequest(slave_id=slave)) + return self.execute(no_response_expected, pdu_other_msg.ReportSlaveIdRequest(dev_id=slave)) def read_file_record(self, records: list[pdu_file_msg.FileRecord], *, slave: int = 1, no_response_expected: bool = False) -> T: """Read file record (code 0x14). @@ -553,7 +553,7 @@ def read_file_record(self, records: list[pdu_file_msg.FileRecord], *, slave: int in the expected response, must not exceed the allowable length of the MODBUS PDU: 235 bytes. """ - return self.execute(no_response_expected, pdu_file_msg.ReadFileRecordRequest(records, slave_id=slave)) + return self.execute(no_response_expected, pdu_file_msg.ReadFileRecordRequest(records, dev_id=slave)) def write_file_record(self, records: list[pdu_file_msg.FileRecord], *, slave: int = 1, no_response_expected: bool = False) -> T: """Write file record (code 0x15). @@ -568,7 +568,7 @@ def write_file_record(self, records: list[pdu_file_msg.FileRecord], *, slave: in and all record lengths are provided in terms of the number of 16 bit words. """ - return self.execute(no_response_expected, pdu_file_msg.WriteFileRecordRequest(records=records, slave_id=slave)) + return self.execute(no_response_expected, pdu_file_msg.WriteFileRecordRequest(records=records, dev_id=slave)) def mask_write_register( self, @@ -593,7 +593,7 @@ def mask_write_register( The function can be used to set or clear individual bits in the register. """ - return self.execute(no_response_expected, pdu_reg.MaskWriteRegisterRequest(address=address, and_mask=and_mask, or_mask=or_mask, slave_id=slave)) + return self.execute(no_response_expected, pdu_reg.MaskWriteRegisterRequest(address=address, and_mask=and_mask, or_mask=or_mask, dev_id=slave)) def readwrite_registers( self, @@ -629,7 +629,7 @@ def readwrite_registers( if address: read_address = address write_address = address - return self.execute(no_response_expected, pdu_reg.ReadWriteMultipleRegistersRequest( read_address=read_address, read_count=read_count, write_address=write_address, write_registers=values,slave_id=slave)) + return self.execute(no_response_expected, pdu_reg.ReadWriteMultipleRegistersRequest( read_address=read_address, read_count=read_count, write_address=write_address, write_registers=values,dev_id=slave)) def read_fifo_queue(self, *, address: int = 0x0000, slave: int = 1, no_response_expected: bool = False) -> T: """Read FIFO queue (code 0x18). @@ -649,7 +649,7 @@ def read_fifo_queue(self, *, address: int = 0x0000, slave: int = 1, no_response_ registers. The function reads the queue contents, but does not clear them. """ - return self.execute(no_response_expected, pdu_file_msg.ReadFifoQueueRequest(address, slave_id=slave)) + return self.execute(no_response_expected, pdu_file_msg.ReadFifoQueueRequest(address, dev_id=slave)) # code 0x2B sub 0x0D: CANopen General Reference Request and Response, NOT IMPLEMENTED @@ -673,7 +673,7 @@ def read_device_information(self, *, read_code: int | None = None, composed of a set of addressable data elements. The data elements are called objects and an object Id identifies them. """ - return self.execute(no_response_expected, pdu_mei.ReadDeviceInformationRequest(read_code, object_id, slave_id=slave)) + return self.execute(no_response_expected, pdu_mei.ReadDeviceInformationRequest(read_code, object_id, dev_id=slave)) # ------------------ # Converter methods diff --git a/pymodbus/datastore/context.py b/pymodbus/datastore/context.py index 4282c40e3..3938953b8 100644 --- a/pymodbus/datastore/context.py +++ b/pymodbus/datastore/context.py @@ -158,7 +158,7 @@ class ModbusServerContext: """This represents a master collection of slave contexts. If single is set to true, it will be treated as a single - context so every slave_id returns the same context. If single + context so every device id returns the same context. If single is set to false, it will be interpreted as a collection of slave contexts. """ diff --git a/pymodbus/framer/base.py b/pymodbus/framer/base.py index 91ae01dda..ddad1a11b 100644 --- a/pymodbus/framer/base.py +++ b/pymodbus/framer/base.py @@ -60,7 +60,7 @@ def buildFrame(self, message: ModbusPDU) -> bytes: :param message: The populated request/response to send """ data = message.function_code.to_bytes(1,'big') + message.encode() - frame = self.encode(data, message.slave_id, message.transaction_id) + frame = self.encode(data, message.dev_id, message.transaction_id) return frame def processIncomingFrame(self, data: bytes) -> tuple[int, ModbusPDU | None]: @@ -96,7 +96,7 @@ def _processIncomingFrame(self, data: bytes) -> tuple[int, ModbusPDU | None]: return used_len, None if (result := self.decoder.decode(frame_data)) is None: raise ModbusIOException("Unable to decode request") - result.slave_id = dev_id + result.dev_id = dev_id result.transaction_id = tid Log.debug("Frame advanced, resetting header!!") return used_len, result diff --git a/pymodbus/pdu/bit_message.py b/pymodbus/pdu/bit_message.py index efef4f81f..a8f0adada 100644 --- a/pymodbus/pdu/bit_message.py +++ b/pymodbus/pdu/bit_message.py @@ -39,7 +39,7 @@ async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: self.function_code, self.address, self.count ) response_class = (ReadCoilsResponse if self.function_code == 1 else ReadDiscreteInputsResponse) - return response_class(slave_id=self.slave_id, transaction_id=self.transaction_id, bits=cast(list[bool], values)) + return response_class(dev_id=self.dev_id, transaction_id=self.transaction_id, bits=cast(list[bool], values)) class ReadDiscreteInputsRequest(ReadCoilsRequest): @@ -97,7 +97,7 @@ async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: return ExceptionResponse(self.function_code, ExceptionResponse.ILLEGAL_ADDRESS) await context.async_setValues(self.function_code, self.address, self.bits) values = cast(list[bool], await context.async_getValues(self.function_code, self.address, 1)) - return WriteSingleCoilResponse(address=self.address, bits=values, slave_id=self.slave_id, transaction_id=self.transaction_id) + return WriteSingleCoilResponse(address=self.address, bits=values, dev_id=self.dev_id, transaction_id=self.transaction_id) def get_response_pdu_size(self) -> int: """Get response pdu size. @@ -134,7 +134,7 @@ async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: await context.async_setValues( self.function_code, self.address, self.bits ) - return WriteMultipleCoilsResponse(address=self.address, count=count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return WriteMultipleCoilsResponse(address=self.address, count=count, dev_id=self.dev_id, transaction_id=self.transaction_id) def get_response_pdu_size(self) -> int: """Get response pdu size. diff --git a/pymodbus/pdu/diag_message.py b/pymodbus/pdu/diag_message.py index 3b8301800..674f367cd 100644 --- a/pymodbus/pdu/diag_message.py +++ b/pymodbus/pdu/diag_message.py @@ -21,9 +21,9 @@ class DiagnosticBase(ModbusPDU): sub_function_code: int = 9999 rtu_frame_size = 8 - def __init__(self, message: bytes | int | list | tuple | None = 0, slave_id: int = 1, transaction_id: int = 0) -> None: + def __init__(self, message: bytes | int | list | tuple | None = 0, dev_id: int = 1, transaction_id: int = 0) -> None: """Initialize a diagnostic request.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id) + super().__init__(transaction_id=transaction_id, dev_id=dev_id) self.message: bytes | int | list | tuple | None = message def encode(self) -> bytes: @@ -72,7 +72,7 @@ async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: ReturnQueryDataResponse.sub_function_code: ReturnQueryDataResponse, RestartCommunicationsOptionResponse.sub_function_code: RestartCommunicationsOptionResponse, }[self.sub_function_code] - return response(message=self.message, slave_id=self.slave_id, transaction_id=self.transaction_id) + return response(message=self.message, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReturnQueryDataRequest(DiagnosticBase): @@ -107,7 +107,7 @@ class ReturnDiagnosticRegisterRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" register = pack_bitstring(_MCB.getDiagnosticRegister()) - return ReturnDiagnosticRegisterResponse(message=register, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReturnDiagnosticRegisterResponse(message=register, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReturnDiagnosticRegisterResponse(DiagnosticBase): @@ -125,7 +125,7 @@ async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" char = (cast(int, self.message) & 0xFF00) >> 8 _MCB.Delimiter = char - return ChangeAsciiInputDelimiterResponse(message=self.message, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ChangeAsciiInputDelimiterResponse(message=self.message, dev_id=self.dev_id, transaction_id=self.transaction_id) class ChangeAsciiInputDelimiterResponse(DiagnosticBase): @@ -142,7 +142,7 @@ class ForceListenOnlyModeRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" _MCB.ListenOnly = True - return ForceListenOnlyModeResponse(slave_id=self.slave_id, transaction_id=self.transaction_id) + return ForceListenOnlyModeResponse(dev_id=self.dev_id, transaction_id=self.transaction_id) class ForceListenOnlyModeResponse(DiagnosticBase): @@ -153,9 +153,9 @@ class ForceListenOnlyModeResponse(DiagnosticBase): sub_function_code = 0x0004 - def __init__(self, slave_id=1, transaction_id=0): + def __init__(self, dev_id=1, transaction_id=0): """Initialize to block a return response.""" - DiagnosticBase.__init__(self, slave_id=slave_id, transaction_id=transaction_id) + DiagnosticBase.__init__(self, dev_id=dev_id, transaction_id=transaction_id) self.message = [] @@ -167,7 +167,7 @@ class ClearCountersRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" _MCB.reset() - return ClearCountersResponse(slave_id=self.slave_id, transaction_id=self.transaction_id) + return ClearCountersResponse(dev_id=self.dev_id, transaction_id=self.transaction_id) class ClearCountersResponse(DiagnosticBase): @@ -184,7 +184,7 @@ class ReturnBusMessageCountRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" count = _MCB.Counter.BusMessage - return ReturnBusMessageCountResponse(message=count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReturnBusMessageCountResponse(message=count, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReturnBusMessageCountResponse(DiagnosticBase): @@ -201,7 +201,7 @@ class ReturnBusCommunicationErrorCountRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" count = _MCB.Counter.BusCommunicationError - return ReturnBusCommunicationErrorCountResponse(message=count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReturnBusCommunicationErrorCountResponse(message=count, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReturnBusCommunicationErrorCountResponse(DiagnosticBase): @@ -218,7 +218,7 @@ class ReturnBusExceptionErrorCountRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" count = _MCB.Counter.BusExceptionError - return ReturnBusExceptionErrorCountResponse(message=count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReturnBusExceptionErrorCountResponse(message=count, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReturnBusExceptionErrorCountResponse(DiagnosticBase): @@ -235,7 +235,7 @@ class ReturnSlaveMessageCountRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" count = _MCB.Counter.SlaveMessage - return ReturnSlaveMessageCountResponse(message=count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReturnSlaveMessageCountResponse(message=count, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReturnSlaveMessageCountResponse(DiagnosticBase): @@ -252,7 +252,7 @@ class ReturnSlaveNoResponseCountRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" count = _MCB.Counter.SlaveNoResponse - return ReturnSlaveNoResponseCountResponse(message=count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReturnSlaveNoResponseCountResponse(message=count, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReturnSlaveNoResponseCountResponse(DiagnosticBase): @@ -269,7 +269,7 @@ class ReturnSlaveNAKCountRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" count = _MCB.Counter.SlaveNAK - return ReturnSlaveNAKCountResponse(message=count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReturnSlaveNAKCountResponse(message=count, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReturnSlaveNAKCountResponse(DiagnosticBase): @@ -286,7 +286,7 @@ class ReturnSlaveBusyCountRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" count = _MCB.Counter.SLAVE_BUSY - return ReturnSlaveBusyCountResponse(message=count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReturnSlaveBusyCountResponse(message=count, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReturnSlaveBusyCountResponse(DiagnosticBase): @@ -303,7 +303,7 @@ class ReturnSlaveBusCharacterOverrunCountRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" count = _MCB.Counter.BusCharacterOverrun - return ReturnSlaveBusCharacterOverrunCountResponse(message=count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReturnSlaveBusCharacterOverrunCountResponse(message=count, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReturnSlaveBusCharacterOverrunCountResponse(DiagnosticBase): @@ -320,7 +320,7 @@ class ReturnIopOverrunCountRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" count = _MCB.Counter.BusCharacterOverrun - return ReturnIopOverrunCountResponse(message=count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReturnIopOverrunCountResponse(message=count, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReturnIopOverrunCountResponse(DiagnosticBase): @@ -337,7 +337,7 @@ class ClearOverrunCountRequest(DiagnosticBase): async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """update_datastore the diagnostic request on the given device.""" _MCB.Counter.BusCharacterOverrun = 0x0000 - return ClearOverrunCountResponse(slave_id=self.slave_id, transaction_id=self.transaction_id) + return ClearOverrunCountResponse(dev_id=self.dev_id, transaction_id=self.transaction_id) class ClearOverrunCountResponse(DiagnosticBase): @@ -368,7 +368,7 @@ async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: else: message = [self.message] message += _MCB.Plus.encode() - return GetClearModbusPlusResponse(message=message, slave_id=self.slave_id, transaction_id=self.transaction_id) + return GetClearModbusPlusResponse(message=message, dev_id=self.dev_id, transaction_id=self.transaction_id) def encode(self): """Encode a diagnostic response.""" diff --git a/pymodbus/pdu/file_message.py b/pymodbus/pdu/file_message.py index 85f1197ac..80297cd84 100644 --- a/pymodbus/pdu/file_message.py +++ b/pymodbus/pdu/file_message.py @@ -35,9 +35,9 @@ class ReadFileRecordRequest(ModbusPDU): function_code = 0x14 rtu_byte_count_pos = 2 - def __init__(self, records: list[FileRecord] | None = None, slave_id: int = 1, transaction_id: int = 0) -> None: + def __init__(self, records: list[FileRecord] | None = None, dev_id: int = 1, transaction_id: int = 0) -> None: """Initialize a new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id) + super().__init__(transaction_id=transaction_id, dev_id=dev_id) self.records: list[FileRecord] = records or [] def encode(self) -> bytes: @@ -78,7 +78,7 @@ async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: for record in self.records: record.record_data = b'SERVER DUMMY RECORD.' record.record_length = len(record.record_data) // 2 - return ReadFileRecordResponse(records=self.records,slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReadFileRecordResponse(records=self.records,dev_id=self.dev_id, transaction_id=self.transaction_id) class ReadFileRecordResponse(ModbusPDU): @@ -87,9 +87,9 @@ class ReadFileRecordResponse(ModbusPDU): function_code = 0x14 rtu_byte_count_pos = 2 - def __init__(self, records: list[FileRecord] | None = None, slave_id: int = 1, transaction_id: int = 0) -> None: + def __init__(self, records: list[FileRecord] | None = None, dev_id: int = 1, transaction_id: int = 0) -> None: """Initialize a new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id) + super().__init__(transaction_id=transaction_id, dev_id=dev_id) self.records: list[FileRecord] = records or [] def encode(self) -> bytes: @@ -125,9 +125,9 @@ class WriteFileRecordRequest(ModbusPDU): function_code = 0x15 rtu_byte_count_pos = 2 - def __init__(self, records: list[FileRecord] | None = None, slave_id: int = 1, transaction_id: int = 0) -> None: + def __init__(self, records: list[FileRecord] | None = None, dev_id: int = 1, transaction_id: int = 0) -> None: """Initialize a new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id) + super().__init__(transaction_id=transaction_id, dev_id=dev_id) self.records: list[FileRecord] = records or [] def encode(self) -> bytes: @@ -171,7 +171,7 @@ def get_response_pdu_size(self) -> int: async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """Run the write file record request against the context.""" - return WriteFileRecordResponse(records=self.records, slave_id=self.slave_id, transaction_id=self.transaction_id) + return WriteFileRecordResponse(records=self.records, dev_id=self.dev_id, transaction_id=self.transaction_id) class WriteFileRecordResponse(ModbusPDU): @@ -180,9 +180,9 @@ class WriteFileRecordResponse(ModbusPDU): function_code = 0x15 rtu_byte_count_pos = 2 - def __init__(self, records: list[FileRecord] | None = None, slave_id: int = 1, transaction_id: int = 0) -> None: + def __init__(self, records: list[FileRecord] | None = None, dev_id: int = 1, transaction_id: int = 0) -> None: """Initialize a new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id) + super().__init__(transaction_id=transaction_id, dev_id=dev_id) self.records: list[FileRecord] = records or [] def encode(self) -> bytes: @@ -223,9 +223,9 @@ class ReadFifoQueueRequest(ModbusPDU): function_code = 0x18 rtu_frame_size = 6 - def __init__(self, address: int = 0, slave_id: int = 1, transaction_id: int = 0) -> None: + def __init__(self, address: int = 0, dev_id: int = 1, transaction_id: int = 0) -> None: """Initialize a new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id) + super().__init__(transaction_id=transaction_id, dev_id=dev_id) self.address = address self.validateAddress() @@ -240,7 +240,7 @@ def decode(self, data: bytes) -> None: async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """Run a read exception status request against the store.""" values = [0, 1, 2, 3] # server dummy response (should be in datastore) - return ReadFifoQueueResponse(values=values, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReadFifoQueueResponse(values=values, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReadFifoQueueResponse(ModbusPDU): @@ -255,9 +255,9 @@ def calculateRtuFrameSize(cls, buffer: bytes) -> int: lo_byte = int(buffer[3]) return (hi_byte << 16) + lo_byte + 6 - def __init__(self, values: list[int] | None = None, slave_id: int = 1, transaction_id:int = 0) -> None: + def __init__(self, values: list[int] | None = None, dev_id: int = 1, transaction_id:int = 0) -> None: """Initialize a new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id) + super().__init__(transaction_id=transaction_id, dev_id=dev_id) self.values = values or [] def encode(self) -> bytes: diff --git a/pymodbus/pdu/mei_message.py b/pymodbus/pdu/mei_message.py index c905ce70e..b3b81418f 100644 --- a/pymodbus/pdu/mei_message.py +++ b/pymodbus/pdu/mei_message.py @@ -34,9 +34,9 @@ class ReadDeviceInformationRequest(ModbusPDU): sub_function_code = 0x0E rtu_frame_size = 7 - def __init__(self, read_code: int | None = None, object_id: int = 0, slave_id: int = 1, transaction_id: int = 0) -> None: + def __init__(self, read_code: int | None = None, object_id: int = 0, dev_id: int = 1, transaction_id: int = 0) -> None: """Initialize a new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id) + super().__init__(transaction_id=transaction_id, dev_id=dev_id) self.read_code = read_code or DeviceInformation.BASIC self.object_id = object_id @@ -59,7 +59,7 @@ async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: return ExceptionResponse(self.function_code, ExceptionResponse.ILLEGAL_VALUE) information = DeviceInformationFactory.get(_MCB, self.read_code, self.object_id) - return ReadDeviceInformationResponse(read_code=self.read_code, information=information, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReadDeviceInformationResponse(read_code=self.read_code, information=information, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReadDeviceInformationResponse(ModbusPDU): @@ -84,9 +84,9 @@ def calculateRtuFrameSize(cls, buffer: bytes) -> int: count -= 1 return size + 2 - def __init__(self, read_code: int | None = None, information: dict | None = None, slave_id: int = 1, transaction_id: int = 0) -> None: + def __init__(self, read_code: int | None = None, information: dict | None = None, dev_id: int = 1, transaction_id: int = 0) -> None: """Initialize a new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id) + super().__init__(transaction_id=transaction_id, dev_id=dev_id) self.read_code = read_code or DeviceInformation.BASIC self.information = information or {} self.number_of_objects = 0 diff --git a/pymodbus/pdu/other_message.py b/pymodbus/pdu/other_message.py index ec7ed2db5..fac49d41d 100644 --- a/pymodbus/pdu/other_message.py +++ b/pymodbus/pdu/other_message.py @@ -28,7 +28,7 @@ def decode(self, _data: bytes) -> None: async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """Run a read exception status request against the store.""" status = _MCB.Counter.summary() - return ReadExceptionStatusResponse(status=status, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReadExceptionStatusResponse(status=status, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReadExceptionStatusResponse(ModbusPDU): @@ -65,7 +65,7 @@ def decode(self, _data: bytes) -> None: async def update_datastore(self, _context) -> ModbusPDU: """Run a read exception status request against the store.""" count = _MCB.Counter.Event - return GetCommEventCounterResponse(count=count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return GetCommEventCounterResponse(count=count, dev_id=self.dev_id, transaction_id=self.transaction_id) class GetCommEventCounterResponse(ModbusPDU): @@ -105,7 +105,7 @@ async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: message_count=_MCB.Counter.BusMessage, event_count=_MCB.Counter.Event, events=_MCB.getEvents(), - slave_id=self.slave_id, transaction_id=self.transaction_id) + dev_id=self.dev_id, transaction_id=self.transaction_id) class GetCommEventLogResponse(ModbusPDU): @@ -114,9 +114,9 @@ class GetCommEventLogResponse(ModbusPDU): function_code = 0x0C rtu_byte_count_pos = 2 - def __init__(self, status: bool = True, message_count: int = 0, event_count: int = 0, events: list[int] | None = None, slave_id: int = 1, transaction_id: int = 0) -> None: + def __init__(self, status: bool = True, message_count: int = 0, event_count: int = 0, events: list[int] | None = None, dev_id: int = 1, transaction_id: int = 0) -> None: """Initialize a new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id, status=status) + super().__init__(transaction_id=transaction_id, dev_id=dev_id, status=status) self.message_count = message_count self.event_count = event_count self.events = events or [] @@ -171,7 +171,7 @@ async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: identifier = b"-".join(id_data) identifier = identifier or b"Pymodbus" - return ReportSlaveIdResponse(identifier=identifier, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReportSlaveIdResponse(identifier=identifier, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReportSlaveIdResponse(ModbusPDU): @@ -180,9 +180,9 @@ class ReportSlaveIdResponse(ModbusPDU): function_code = 0x11 rtu_byte_count_pos = 2 - def __init__(self, identifier: bytes = b"\x00", status: bool = True, slave_id: int = 1, transaction_id: int = 0) -> None: + def __init__(self, identifier: bytes = b"\x00", status: bool = True, dev_id: int = 1, transaction_id: int = 0) -> None: """Initialize a new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id, status=status) + super().__init__(transaction_id=transaction_id, dev_id=dev_id, status=status) self.identifier = identifier self.byte_count = 0 diff --git a/pymodbus/pdu/pdu.py b/pymodbus/pdu/pdu.py index f4c3f5931..792017c02 100644 --- a/pymodbus/pdu/pdu.py +++ b/pymodbus/pdu/pdu.py @@ -18,7 +18,7 @@ class ModbusPDU: rtu_byte_count_pos: int = 0 def __init__(self, - slave_id: int = 0, + dev_id: int = 0, transaction_id: int = 0, address: int = 0, count: int = 0, @@ -27,7 +27,7 @@ def __init__(self, status: int = 1, ) -> None: """Initialize the base data for a modbus request.""" - self.slave_id: int = slave_id + self.dev_id: int = dev_id self.transaction_id: int = transaction_id self.address: int = address self.bits: list[bool] = bits or [] @@ -58,7 +58,7 @@ def __str__(self) -> str: """Build a representation of an exception response.""" return ( f"{self.__class__.__name__}(" - f"slave_id={self.slave_id}, " + f"dev_id={self.dev_id}, " f"transaction_id={self.transaction_id}, " f"address={self.address}, " f"count={self.count}, " @@ -116,7 +116,7 @@ def __init__( slave: int = 1, transaction: int = 0) -> None: """Initialize the modbus exception response.""" - super().__init__(transaction_id=transaction, slave_id=slave) + super().__init__(transaction_id=transaction, dev_id=slave) self.function_code = function_code | 0x80 self.exception_code = exception_code Log.error(f"Exception response {self.function_code} / {self.exception_code}") diff --git a/pymodbus/pdu/register_message.py b/pymodbus/pdu/register_message.py index 2e3e70f05..8cfcdb96e 100644 --- a/pymodbus/pdu/register_message.py +++ b/pymodbus/pdu/register_message.py @@ -40,7 +40,7 @@ async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: self.function_code, self.address, self.count )) response_class = (ReadHoldingRegistersResponse if self.function_code == 3 else ReadInputRegistersResponse) - return response_class(registers=values, slave_id=self.slave_id, transaction_id=self.transaction_id) + return response_class(registers=values, dev_id=self.dev_id, transaction_id=self.transaction_id) class ReadHoldingRegistersResponse(ModbusPDU): @@ -88,12 +88,12 @@ def __init__(self, read_count: int = 0, write_address: int = 0x00, write_registers: list[int] | None = None, - slave_id: int = 1, + dev_id: int = 1, transaction_id: int = 0) -> None: """Initialize a new request message.""" if not write_registers: write_registers = [] - super().__init__(transaction_id=transaction_id, slave_id=slave_id) + super().__init__(transaction_id=transaction_id, dev_id=dev_id) self.read_address = read_address self.read_count = read_count self.write_address = write_address @@ -151,7 +151,7 @@ async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: registers = cast(list[int], await context.async_getValues( self.function_code, self.read_address, self.read_count )) - return ReadWriteMultipleRegistersResponse(registers=registers, slave_id=self.slave_id, transaction_id=self.transaction_id) + return ReadWriteMultipleRegistersResponse(registers=registers, dev_id=self.dev_id, transaction_id=self.transaction_id) def get_response_pdu_size(self) -> int: """Get response pdu size. @@ -238,7 +238,7 @@ async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: await context.async_setValues( self.function_code, self.address, self.registers ) - return WriteMultipleRegistersResponse(address=self.address, count=self.count, slave_id=self.slave_id, transaction_id=self.transaction_id) + return WriteMultipleRegistersResponse(address=self.address, count=self.count, dev_id=self.dev_id, transaction_id=self.transaction_id) def get_response_pdu_size(self) -> int: """Get response pdu size. @@ -269,9 +269,9 @@ class MaskWriteRegisterRequest(ModbusPDU): function_code = 0x16 rtu_frame_size = 10 - def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave_id=1, transaction_id=0) -> None: + def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, dev_id=1, transaction_id=0) -> None: """Initialize a new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id, address=address) + super().__init__(transaction_id=transaction_id, dev_id=dev_id, address=address) self.and_mask = and_mask self.or_mask = or_mask @@ -296,7 +296,7 @@ async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: await context.async_setValues( self.function_code, self.address, [values] ) - return MaskWriteRegisterResponse(address=self.address, and_mask=self.and_mask, or_mask=self.or_mask, slave_id=self.slave_id, transaction_id=self.transaction_id) + return MaskWriteRegisterResponse(address=self.address, and_mask=self.and_mask, or_mask=self.or_mask, dev_id=self.dev_id, transaction_id=self.transaction_id) class MaskWriteRegisterResponse(ModbusPDU): @@ -305,9 +305,9 @@ class MaskWriteRegisterResponse(ModbusPDU): function_code = 0x16 rtu_frame_size = 10 - def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave_id=1, transaction_id=0) -> None: + def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, dev_id=1, transaction_id=0) -> None: """Initialize new instance.""" - super().__init__(transaction_id=transaction_id, slave_id=slave_id, address=address) + super().__init__(transaction_id=transaction_id, dev_id=dev_id, address=address) self.and_mask = and_mask self.or_mask = or_mask diff --git a/pymodbus/server/async_io.py b/pymodbus/server/async_io.py index 578aca35c..79e52a9b3 100644 --- a/pymodbus/server/async_io.py +++ b/pymodbus/server/async_io.py @@ -155,18 +155,18 @@ async def server_async_execute(self, request, *addr): """Handle request.""" broadcast = False try: - if self.server.broadcast_enable and not request.slave_id: + if self.server.broadcast_enable and not request.dev_id: broadcast = True # if broadcasting then execute on all slave contexts, # note response will be ignored - for slave_id in self.server.context.slaves(): - response = await request.update_datastore(self.server.context[slave_id]) + for dev_id in self.server.context.slaves(): + response = await request.update_datastore(self.server.context[dev_id]) else: - context = self.server.context[request.slave_id] + context = self.server.context[request.dev_id] response = await request.update_datastore(context) except NoSuchSlaveException: - Log.error("requested slave does not exist: {}", request.slave_id) + Log.error("requested slave does not exist: {}", request.dev_id) if self.server.ignore_missing_slaves: return # the client will simply timeout waiting for a response response = ExceptionResponse(0x00, ExceptionResponse.GATEWAY_NO_RESPONSE) @@ -180,7 +180,7 @@ async def server_async_execute(self, request, *addr): # no response when broadcasting if not broadcast: response.transaction_id = request.transaction_id - response.slave_id = request.slave_id + response.dev_id = request.dev_id self.server_send(response, *addr) def server_send(self, pdu, addr): @@ -293,8 +293,8 @@ def __init__( :param address: An optional (interface, port) to bind to. :param ignore_missing_slaves: True to not send errors on a request to a missing slave - :param broadcast_enable: True to treat slave_id 0 as broadcast address, - False to treat 0 as any other slave_id + :param broadcast_enable: True to treat dev_id 0 as broadcast address, + False to treat 0 as any other dev_id :param trace_packet: Called with bytestream received/to be sent :param trace_pdu: Called with PDU received/to be sent :param trace_connect: Called when connected/disconnected @@ -365,8 +365,8 @@ def __init__( # pylint: disable=too-many-arguments :param password: The password for for decrypting the private key file :param ignore_missing_slaves: True to not send errors on a request to a missing slave - :param broadcast_enable: True to treat slave_id 0 as broadcast address, - False to treat 0 as any other slave_id + :param broadcast_enable: True to treat dev_id 0 as broadcast address, + False to treat 0 as any other dev_id """ self.tls_setup = CommParams( comm_type=CommType.TLS, @@ -423,8 +423,8 @@ def __init__( :param address: An optional (interface, port) to bind to. :param ignore_missing_slaves: True to not send errors on a request to a missing slave - :param broadcast_enable: True to treat slave_id 0 as broadcast address, - False to treat 0 as any other slave_id + :param broadcast_enable: True to treat dev_id 0 as broadcast address, + False to treat 0 as any other dev_id :param trace_packet: Called with bytestream received/to be sent :param trace_pdu: Called with PDU received/to be sent :param trace_connect: Called when connected/disconnected @@ -488,8 +488,8 @@ def __init__( :param handle_local_echo: (optional) Discard local echo from dongle. :param ignore_missing_slaves: True to not send errors on a request to a missing slave - :param broadcast_enable: True to treat slave_id 0 as broadcast address, - False to treat 0 as any other slave_id + :param broadcast_enable: True to treat dev_id 0 as broadcast address, + False to treat 0 as any other dev_id :param reconnect_delay: reconnect delay in seconds :param trace_packet: Called with bytestream received/to be sent :param trace_pdu: Called with PDU received/to be sent diff --git a/test/framer/generator.py b/test/framer/generator.py index 3f32033eb..0c78be765 100755 --- a/test/framer/generator.py +++ b/test/framer/generator.py @@ -23,21 +23,21 @@ def set_calls(): for tid in (0, 3077): print(f" tid --> {tid}") client = framer(DecodePDU(False)) - request = ReadHoldingRegistersRequest(address=124, count=2, slave_id=dev_id) + request = ReadHoldingRegistersRequest(address=124, count=2, dev_id=dev_id) request.transaction_id = tid result = client.buildFrame(request) print(f" request --> {result}") print(f" request --> {result.hex()}") server = framer(DecodePDU(True)) response = ReadHoldingRegistersResponse(registers=[141,142]) - response.slave_id = dev_id + response.dev_id = dev_id response.transaction_id = tid result = server.buildFrame(response) print(f" response --> {result}") print(f" response --> {result.hex()}") exception = ExceptionResponse(request.function_code, ExceptionResponse.ILLEGAL_ADDRESS) exception.transaction_id = tid - exception.slave_id = dev_id + exception.dev_id = dev_id result = server.buildFrame(exception) print(f" exception --> {result}") print(f" exception --> {result.hex()}") diff --git a/test/framer/test_framer.py b/test/framer/test_framer.py index 5838e3d8d..a07ceed03 100644 --- a/test/framer/test_framer.py +++ b/test/framer/test_framer.py @@ -428,7 +428,7 @@ def test_processIncomingFrame_roundtrip(self, entry, test_framer, msg, dev_id, t used_len, result = test_framer.processIncomingFrame(msg) assert used_len == len(msg) assert result - assert result.slave_id == dev_id + assert result.dev_id == dev_id assert result.transaction_id == tid expected = test_framer.encode( result.function_code.to_bytes(1,'big') + result.encode(), @@ -447,7 +447,7 @@ def test_framer_encode(self, test_framer, msg): with mock.patch.object(ModbusPDU, "encode") as mock_encode: message = ModbusPDU() message.transaction_id = 0x0001 - message.slave_id = 0xFF + message.dev_id = 0xFF message.function_code = 0x01 mock_encode.return_value = b"" diff --git a/test/pdu/test_pdu.py b/test/pdu/test_pdu.py index b4fe0de85..d441fba43 100644 --- a/test/pdu/test_pdu.py +++ b/test/pdu/test_pdu.py @@ -169,14 +169,11 @@ def test_pdu_instance_args(self, pdutype, kwargs): def test_pdu_instance_extras(self, pdutype, kwargs): """Test that all PDU types can be created.""" tid = 9112 - slave_id = 63 - try: - pdu = pdutype(transaction=tid, slave=slave_id, **kwargs) - except TypeError: - pdu = pdutype(transaction_id=tid, slave_id=slave_id, **kwargs) + dev_id = 63 + pdu = pdutype(transaction_id=tid, dev_id=dev_id, **kwargs) assert pdu assert str(pdu) - assert pdu.slave_id == slave_id + assert pdu.dev_id == dev_id assert pdu.transaction_id == tid assert pdu.function_code > 0 diff --git a/test/server/test_server_context.py b/test/server/test_server_context.py index 6c9148011..73e3b6247 100644 --- a/test/server/test_server_context.py +++ b/test/server/test_server_context.py @@ -17,8 +17,8 @@ def setup_method(self): def test_single_context_gets(self): """Test getting on a single context.""" - for slave_id in range(0, 0xFF): - assert self.slave == self.context[slave_id] + for dev_id in range(0, 0xFF): + assert self.slave == self.context[dev_id] def test_single_context_deletes(self): """Test removing on multiple context.""" @@ -70,8 +70,8 @@ def setup_method(self): def test_multiple_context_gets(self): """Test getting on multiple context.""" - for slave_id in range(0, 10): - assert self.slaves[slave_id] == self.context[slave_id] + for dev_id in range(0, 10): + assert self.slaves[dev_id] == self.context[dev_id] def test_multiple_context_deletes(self): """Test removing on multiple context.""" @@ -81,9 +81,9 @@ def test_multiple_context_deletes(self): def test_multiple_context_iter(self): """Test iterating over multiple context.""" - for slave_id, slave in self.context: - assert slave == self.slaves[slave_id] - assert slave_id in self.context + for dev_id, slave in self.context: + assert slave == self.slaves[dev_id] + assert dev_id in self.context def test_multiple_context_default(self): """Test that the multiple context default values work.""" @@ -94,8 +94,8 @@ def test_multiple_context_default(self): def test_multiple_context_set(self): """Test a setting multiple slave contexts.""" slaves = {id: ModbusSlaveContext() for id in range(10)} - for slave_id, slave in iter(slaves.items()): - self.context[slave_id] = slave - for slave_id, slave in iter(slaves.items()): - actual = self.context[slave_id] + for dev_id, slave in iter(slaves.items()): + self.context[dev_id] = slave + for dev_id, slave in iter(slaves.items()): + actual = self.context[dev_id] assert slave == actual