QModbusDevice#
The QModbusDevice
class is the base class for Modbus classes, QModbusServer
and QModbusClient
. More…
Inherited by: QModbusServer, QModbusTcpServer, QModbusRtuSerialServer, QModbusClient, QModbusTcpClient, QModbusRtuSerialClient
Synopsis#
Functions#
def
connectDevice
()def
connectionParameter
(parameter)def
device
()def
disconnectDevice
()def
error
()def
errorString
()def
setConnectionParameter
(parameter, value)def
setError
(errorText, error)def
setState
(newState)def
state
()
Virtual functions#
Signals#
def
errorOccurred
(error)def
stateChanged
(state)
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
- class PySide6.QtSerialBus.QModbusDevice([parent=None])#
- Parameters:
parent –
PySide6.QtCore.QObject
Constructs a Modbus device with the specified parent
.
- PySide6.QtSerialBus.QModbusDevice.Error#
This enum describes all the possible error conditions.
Constant
Description
QModbusDevice.NoError
No errors have occurred.
QModbusDevice.ReadError
An error occurred during a read operation.
QModbusDevice.WriteError
An error occurred during a write operation.
QModbusDevice.ConnectionError
An error occurred when attempting to open the backend.
QModbusDevice.ConfigurationError
An error occurred when attempting to set a configuration parameter.
QModbusDevice.TimeoutError
A timeout occurred during I/O. An I/O operation did not finish within a given time frame.
QModbusDevice.ProtocolError
A Modbus specific protocol error occurred.
QModbusDevice.ReplyAbortedError
The reply was aborted due to a disconnection of the device.
QModbusDevice.UnknownError
An unknown error occurred.
QModbusDevice.InvalidResponseError
An error occurred while parsing the response, or the
FunctionCode
is not supported by the current implementation. In the latter case custom Modbus client implementation can override theprocessResponse()
andprocessPrivateResponse()
methods to provide support for needed functions.
- PySide6.QtSerialBus.QModbusDevice.State#
This enum describes all possible device states.
Constant
Description
QModbusDevice.UnconnectedState
The device is disconnected.
QModbusDevice.ConnectingState
The device is being connected.
QModbusDevice.ConnectedState
The device is connected to the Modbus network.
QModbusDevice.ClosingState
The device is being closed.
- PySide6.QtSerialBus.QModbusDevice.ConnectionParameter#
This enum describes the possible values that can be set for a Modbus device connection.
The general purpose value (and the associated types) are:
Constant
Description
QModbusDevice.SerialPortNameParameter
This parameter holds the serial port used for device communication, e.g. COM1.
QString
QModbusDevice.SerialParityParameter
This parameter holds the parity checking mode.
QSerialPort::Parity
QModbusDevice.SerialBaudRateParameter
This parameter holds the data baud rate for the communication.
QSerialPort::BaudRate
QModbusDevice.SerialDataBitsParameter
This parameter holds the data bits in a frame.
QSerialPort::DataBits
QModbusDevice.SerialStopBitsParameter
This parameter holds the number of stop bits in a frame.
QSerialPort::StopBits
QModbusDevice.NetworkPortParameter
This parameter holds the network port.
int
QModbusDevice.NetworkAddressParameter
This parameter holds the host address for network communication.
QString
- PySide6.QtSerialBus.QModbusDevice.IntermediateError#
This enum describes possible errors that can happen during a full send and receive cycle for a Modbus reply.
Constant
Description
QModbusDevice.ResponseCrcError
A Modbus response with a wrong CRC was received.
QModbusDevice.ResponseRequestMismatch
A Modbus response was received but did not match the open request, probably due to the PDU’s function code not matching.
If any of the above intermediate errors occurred, the frame is likely resent until the maximum number of retries has been reached.
The list of intermediate errors can be inspected from the QModbusReply
intermediate errors function.
See also
- abstract PySide6.QtSerialBus.QModbusDevice.close()#
This function is responsible for closing the Modbus connection. The implementation must ensure that the instance’s state()
is set to UnconnectedState
.
See also
- PySide6.QtSerialBus.QModbusDevice.connectDevice()#
- Return type:
bool
Connects the device to the Modbus network. Returns true
if the connection process was successfully initiated; otherwise false
. Final connection success confirmation requires the state()
changing to ConnectedState
.
This function calls open()
as part of its implementation.
See also
- PySide6.QtSerialBus.QModbusDevice.connectionParameter(parameter)#
- Parameters:
parameter –
ConnectionParameter
- Return type:
object
Returns the value associated with the given connection parameter
. The returned value can be empty.
By default the QModbusDevice
is initialized with some common values. The serial port settings are even parity, a baud rate of 19200 bits per second, eight data bits and one stop bit. The network settings for the host address is set to local host and port to 502.
Note
For a serial connection to succeed, the SerialPortNameParameter
needs to be set to a valid communication port. The information about valid serial ports can be obtained from QSerialPortInfo.
Note
If the device is already connected, the settings are taken into account after reconnecting the device.
See also
setConnectionParameter()
ConnectionParameter
- PySide6.QtSerialBus.QModbusDevice.device()#
- Return type:
Returns the underlying QIODevice used for ModBus communication or nullptr
if the device was not yet fully initialized.
Note
Do not store a pointer to the underlying device, because it can be invalidated at any point in time.
- PySide6.QtSerialBus.QModbusDevice.disconnectDevice()#
Disconnects the device.
This function calls close()
as part of its implementation.
Returns the error state of the device.
See also
setError()
Error
This signal is emitted when an error of the type, error
, occurs.
- PySide6.QtSerialBus.QModbusDevice.errorString()#
- Return type:
str
Returns descriptive error text for the device error.
See also
Error
- abstract PySide6.QtSerialBus.QModbusDevice.open()#
- Return type:
bool
This function is called by connectDevice()
. Subclasses must provide an implementation that returns true
on successful Modbus connection or connection initiation; otherwise returns false
.
The implementation must ensure that the instance’s state()
is set to ConnectingState
or ConnectedState
upon success; otherwise UnconnectedState
. Typically, ConnectingState
is used when the connection process reports back asynchronously and ConnectedState
in case of synchronous connect behavior.
See also
- PySide6.QtSerialBus.QModbusDevice.setConnectionParameter(parameter, value)#
- Parameters:
parameter –
ConnectionParameter
value – object
Sets the value of parameter
to value
. If the parameter
already exists, the previous value is overwritten. A active or running connection is not affected by such parameter changes.
See also
ConnectionParameter
connectionParameter()
- PySide6.QtSerialBus.QModbusDevice.setError(errorText, error)#
- Parameters:
errorText – str
error –
Error
Sets the error state of the device. ModBus device implementations must use this function in case of an error to set the error
type and a descriptive errorText
.
See also
error()
Error
Sets the state of the device to newState
. Modbus device implementations must use this function to update the device state.
See also
Returns the current state of the device.
See also
This signal is emitted every time the state of the device changes. The new state is represented by state
.
See also