# `diag_message` — Diagnostic Modbus Messages

## API Documentation

### Diagnostic Record Read/Write

These need to be tied into a the current server context or linked to the appropriate data

class `pymodbus.diag_message.``DiagnosticStatusRequest`(**kwargs)

  This is a base class for all of the diagnostic request functions

  `__init__`(**kwargs)

    Base initializer for a diagnostic request

  `encode`()

    Base encoder for a diagnostic response we encode the data set in self.message

    Returns: | The encoded packet

  `decode`(data)

    Base decoder for a diagnostic request

    Parameters: | data – The data to decode into the function code

  `get_response_pdu_size`()

    Func_code (1 byte) + Sub function code (2 byte) + Data (2 * N bytes) :return:

class `pymodbus.diag_message.``DiagnosticStatusResponse`(**kwargs)

  This is a base class for all of the diagnostic response functions

  It works by performing all of the encoding and decoding of variable data and lets the higher classes define what extra data to append and how to execute a request

  `__init__`(**kwargs)

    Base initializer for a diagnostic response

  `encode`()

    Base encoder for a diagnostic response we encode the data set in self.message

    Returns: | The encoded packet

  `decode`(data)

    Base decoder for a diagnostic response

    Parameters: | data – The data to decode into the function code

class `pymodbus.diag_message.``DiagnosticStatusSimpleRequest`(data=0, **kwargs)

  A large majority of the diagnostic functions are simple status request functions. They work by sending 0x0000 as data and their function code and they are returned 2 bytes of data.

  If a function inherits this, they only need to implement the execute method

  `__init__`(data=0, **kwargs)

    General initializer for a simple diagnostic request

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

    Parameters: | data – The data to send along with the request

  `execute`(*args)

    Base function to raise if not implemented

class `pymodbus.diag_message.``DiagnosticStatusSimpleResponse`(data=0, **kwargs)

  A large majority of the diagnostic functions are simple status request functions. They work by sending 0x0000 as data and their function code and they are returned 2 bytes of data.

  `__init__`(data=0, **kwargs)

    General initializer for a simple diagnostic response

    Parameters: | data – The resulting data to return to the client

class `pymodbus.diag_message.``ReturnQueryDataRequest`(message=0, **kwargs)

  The data passed in the request data field is to be returned (looped back) in the response. The entire response message should be identical to the request.

  `__init__`(message=0, **kwargs)

    Initializes a new instance of the request

    Parameters: | message – The message to send to loopback

  `execute`(*args)

    Executes the loopback request (builds the response)

    Returns: | The populated loopback response message

class `pymodbus.diag_message.``ReturnQueryDataResponse`(message=0, **kwargs)

  The data passed in the request data field is to be returned (looped back) in the response. The entire response message should be identical to the request.

  `__init__`(message=0, **kwargs)

    Initializes a new instance of the response

    Parameters: | message – The message to loopback

class `pymodbus.diag_message.``RestartCommunicationsOptionRequest`(toggle=False, **kwargs)

  The remote device serial line port must be initialized and restarted, and all of its communications event counters are cleared. If the port is currently in Listen Only Mode, no response is returned. This function is the only one that brings the port out of Listen Only Mode. If the port is not currently in Listen Only Mode, a normal response is returned. This occurs before the restart is executed.

  `__init__`(toggle=False, **kwargs)

    Initializes a new request

    Parameters: | toggle – Set to True to toggle, False otherwise

  `execute`(*args)

    Clear event log and restart

    Returns: | The initialized response message

class `pymodbus.diag_message.``RestartCommunicationsOptionResponse`(toggle=False, **kwargs)

  The remote device serial line port must be initialized and restarted, and all of its communications event counters are cleared. If the port is currently in Listen Only Mode, no response is returned. This function is the only one that brings the port out of Listen Only Mode. If the port is not currently in Listen Only Mode, a normal response is returned. This occurs before the restart is executed.

  `__init__`(toggle=False, **kwargs)

    Initializes a new response

    Parameters: | toggle – Set to True if we toggled, False otherwise

class `pymodbus.diag_message.``ReturnDiagnosticRegisterRequest`(data=0, **kwargs)

  The contents of the remote device’s 16-bit diagnostic register are returned in the response

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ReturnDiagnosticRegisterResponse`(data=0, **kwargs)

  The contents of the remote device’s 16-bit diagnostic register are returned in the response

class `pymodbus.diag_message.``ChangeAsciiInputDelimiterRequest`(data=0, **kwargs)

  The character ‘CHAR’ passed in the request data field becomes the end of message delimiter for future messages (replacing the default LF character). This function is useful in cases of a Line Feed is not required at the end of ASCII messages.

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ChangeAsciiInputDelimiterResponse`(data=0, **kwargs)

  The character ‘CHAR’ passed in the request data field becomes the end of message delimiter for future messages (replacing the default LF character). This function is useful in cases of a Line Feed is not required at the end of ASCII messages.

class `pymodbus.diag_message.``ForceListenOnlyModeRequest`(data=0, **kwargs)

  Forces the addressed remote device to its Listen Only Mode for MODBUS communications. This isolates it from the other devices on the network, allowing them to continue communicating without interruption from the addressed remote device. No response is returned.

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ForceListenOnlyModeResponse`(**kwargs)

  Forces the addressed remote device to its Listen Only Mode for MODBUS communications. This isolates it from the other devices on the network, allowing them to continue communicating without interruption from the addressed remote device. No response is returned.

  This does not send a response

  `__init__`(**kwargs)

    Initializer to block a return response

class `pymodbus.diag_message.``ClearCountersRequest`(data=0, **kwargs)

  The goal is to clear ll counters and the diagnostic register. Also, counters are cleared upon power-up

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ClearCountersResponse`(data=0, **kwargs)

  The goal is to clear ll counters and the diagnostic register. Also, counters are cleared upon power-up

class `pymodbus.diag_message.``ReturnBusMessageCountRequest`(data=0, **kwargs)

  The response data field returns the quantity of messages that the remote device has detected on the communications systems since its last restart, clear counters operation, or power-up

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ReturnBusMessageCountResponse`(data=0, **kwargs)

  The response data field returns the quantity of messages that the remote device has detected on the communications systems since its last restart, clear counters operation, or power-up

class `pymodbus.diag_message.``ReturnBusCommunicationErrorCountRequest`(data=0, **kwargs)

  The response data field returns the quantity of CRC errors encountered by the remote device since its last restart, clear counter operation, or power-up

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ReturnBusCommunicationErrorCountResponse`(data=0, **kwargs)

  The response data field returns the quantity of CRC errors encountered by the remote device since its last restart, clear counter operation, or power-up

class `pymodbus.diag_message.``ReturnBusExceptionErrorCountRequest`(data=0, **kwargs)

  The response data field returns the quantity of modbus exception responses returned by the remote device since its last restart, clear counters operation, or power-up

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ReturnBusExceptionErrorCountResponse`(data=0, **kwargs)

  The response data field returns the quantity of modbus exception responses returned by the remote device since its last restart, clear counters operation, or power-up

class `pymodbus.diag_message.``ReturnSlaveMessageCountRequest`(data=0, **kwargs)

  The response data field returns the quantity of messages addressed to the remote device, or broadcast, that the remote device has processed since its last restart, clear counters operation, or power-up

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ReturnSlaveMessageCountResponse`(data=0, **kwargs)

  The response data field returns the quantity of messages addressed to the remote device, or broadcast, that the remote device has processed since its last restart, clear counters operation, or power-up

class `pymodbus.diag_message.``ReturnSlaveNoResponseCountRequest`(data=0, **kwargs)

  The response data field returns the quantity of messages addressed to the remote device, or broadcast, that the remote device has processed since its last restart, clear counters operation, or power-up

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ReturnSlaveNoReponseCountResponse`(data=0, **kwargs)

  The response data field returns the quantity of messages addressed to the remote device, or broadcast, that the remote device has processed since its last restart, clear counters operation, or power-up

class `pymodbus.diag_message.``ReturnSlaveNAKCountRequest`(data=0, **kwargs)

  The response data field returns the quantity of messages addressed to the remote device for which it returned a Negative Acknowledge (NAK) exception response, since its last restart, clear counters operation, or power-up. Exception responses are described and listed in section 7 .

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ReturnSlaveNAKCountResponse`(data=0, **kwargs)

  The response data field returns the quantity of messages addressed to the remote device for which it returned a Negative Acknowledge (NAK) exception response, since its last restart, clear counters operation, or power-up. Exception responses are described and listed in section 7.

class `pymodbus.diag_message.``ReturnSlaveBusyCountRequest`(data=0, **kwargs)

  The response data field returns the quantity of messages addressed to the remote device for which it returned a Slave Device Busy exception response, since its last restart, clear counters operation, or power-up.

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ReturnSlaveBusyCountResponse`(data=0, **kwargs)

  The response data field returns the quantity of messages addressed to the remote device for which it returned a Slave Device Busy exception response, since its last restart, clear counters operation, or power-up.

class `pymodbus.diag_message.``ReturnSlaveBusCharacterOverrunCountRequest`(data=0, **kwargs)

  The response data field returns the quantity of messages addressed to the remote device that it could not handle due to a character overrun condition, since its last restart, clear counters operation, or power-up. A character 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.

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ReturnSlaveBusCharacterOverrunCountResponse`(data=0, **kwargs)

  The response data field returns the quantity of messages addressed to the remote device that it could not handle due to a character overrun condition, since its last restart, clear counters operation, or power-up. A character 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.

class `pymodbus.diag_message.``ReturnIopOverrunCountRequest`(data=0, **kwargs)

  An IOP 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. This function is specific to the 884.

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ReturnIopOverrunCountResponse`(data=0, **kwargs)

  The response data field returns the quantity of messages addressed to the slave that it could not handle due to an 884 IOP overrun condition, since its last restart, clear counters operation, or power-up.

class `pymodbus.diag_message.``ClearOverrunCountRequest`(data=0, **kwargs)

  Clears the overrun error counter and reset the error flag

  An error flag should be cleared, but nothing else in the specification mentions is, so it is ignored.

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

class `pymodbus.diag_message.``ClearOverrunCountResponse`(data=0, **kwargs)

  Clears the overrun error counter and reset the error flag

class `pymodbus.diag_message.``GetClearModbusPlusRequest`(**kwargs)

  In addition to the Function code (08) and Subfunction code (00 15 hex) in the query, a two-byte Operation field is used to specify either a ‘Get Statistics’ or a ‘Clear Statistics’ operation. The two operations are exclusive - the ‘Get’ operation cannot clear the statistics, and the ‘Clear’ operation does not return statistics prior to clearing them. Statistics are also cleared on power-up of the slave device.

  `get_response_pdu_size`()

    Returns a series of 54 16-bit words (108 bytes) in the data field of the response (this function differs from the usual two-byte length of the data field). The data contains the statistics for the Modbus Plus peer processor in the slave device. Func_code (1 byte) + Sub function code (2 byte) + Operation (2 byte) + Data (108 bytes) :return:

  `execute`(*args)

    Execute the diagnostic request on the given device

    Returns: | The initialized response message

  `encode`()

    Base encoder for a diagnostic response we encode the data set in self.message

    Returns: | The encoded packet

class `pymodbus.diag_message.``GetClearModbusPlusResponse`(data=0, **kwargs)

  Returns a series of 54 16-bit words (108 bytes) in the data field of the response (this function differs from the usual two-byte length of the data field). The data contains the statistics for the Modbus Plus peer processor in the slave device.