QModbusServer#
The QModbusServer class is the interface to receive and process Modbus requests. More…
Inherited by: QModbusTcpServer, QModbusRtuSerialServer
Synopsis#
Functions#
def
data(newData)def
data(table, address, data)def
serverAddress()def
setData(table, address, data)def
setData(unit)def
setServerAddress(serverAddress)
Virtual functions#
Signals#
def
dataWritten(table, address, size)
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#
Modbus networks can have multiple Modbus servers. Modbus Servers are read/written by a Modbus client represented by QModbusClient . QModbusServer communicates with a Modbus backend, providing users with a convenient API.
- class PySide6.QtSerialBus.QModbusServer([parent=None])#
- Parameters:
parent –
PySide6.QtCore.QObject
Constructs a Modbus server with the specified parent.
- PySide6.QtSerialBus.QModbusServer.Option#
Each Modbus server has a set of values associated with it, each with its own option.
The general purpose options (and the associated types) are:
Constant
Description
QModbusServer.DiagnosticRegister
The diagnostic register of the server.
quint16QModbusServer.ExceptionStatusOffset
The exception status byte offset of the server.
quint16QModbusServer.DeviceBusy
Flag to signal the server is engaged in processing a long-duration program command.
quint16QModbusServer.AsciiInputDelimiter
The Modbus ASCII end of message delimiter.
charQModbusServer.ListenOnlyMode
Flag to set listen only mode of the server. This function is typically supported only by Modbus serial devices.
boolQModbusServer.ServerIdentifier
The identifier of the server, not the server address.
quint8QModbusServer.RunIndicatorStatus
The run indicator of the server.
quint8QModbusServer.AdditionalData
The additional data of the server.
QByteArrayQModbusServer.DeviceIdentification
The physical and functional description of the server.
QModbusDeviceIdentification
User options:
Constant
Description
QModbusServer.UserOption
The first option that can be used for user-specific purposes.
For user options, it is up to the developer to decide which types to use and ensure that components use the correct types when accessing and setting values.
- PySide6.QtSerialBus.QModbusServer.data(newData)#
- Parameters:
newData –
PySide6.QtSerialBus.QModbusDataUnit- Return type:
bool
Returns the values in the register range given by newData.
newData must provide a valid register type, start address and valueCount. The returned newData will contain the register values associated with the given range.
If newData contains a valid register type but a negative start address the entire register map is returned and newData appropriately sized.
See also
- PySide6.QtSerialBus.QModbusServer.data(table, address, data)
- Parameters:
table –
RegisterTypeaddress –
quint16data –
quint16
- Return type:
bool
Reads data stored in the Modbus server. A Modbus server has four tables (table) and each have a unique address field, which is used to read data from the desired field. See RegisterType for more information about the different tables. Returns false if address is outside of the map range or the register type is not even defined.
See also
RegisterTypesetData()
- PySide6.QtSerialBus.QModbusServer.dataWritten(table, address, size)#
- Parameters:
table –
RegisterTypeaddress – int
size – int
This signal is emitted when a Modbus client has written one or more fields of data to the Modbus server. The signal contains information about the fields that were written:
Register type (
table) that was written,
addressof the first field that was written,and
sizeof consecutive fields that were written starting fromaddress.
The signal is not emitted when the to-be-written fields have not changed due to no change in value.
- PySide6.QtSerialBus.QModbusServer.processesBroadcast()#
- Return type:
bool
Subclasses should implement this function if the transport layer shall handle broadcasts. The implementation then should return true if the currently processed request is a broadcast request; otherwise false. The default implementation returns always false.
Note
The return value of this function only makes sense from within processRequest() or processPrivateRequest() , otherwise it can only tell that the last request processed was a broadcast request.
- PySide6.QtSerialBus.QModbusServer.readData(newData)#
- Parameters:
newData –
PySide6.QtSerialBus.QModbusDataUnit- Return type:
bool
Reads the values in the register range given by newData and writes the data back to newData. Returns true on success or false if newData is 0, the newData range is outside of the map range or the registerType() does not exist.
Note
Sub-classes that implement reading from a different backing store then default one, also need to implement setMap() and writeData() .
See also
- PySide6.QtSerialBus.QModbusServer.serverAddress()#
- Return type:
int
Returns the address of this Modbus server instance.
See also
- PySide6.QtSerialBus.QModbusServer.setData(table, address, data)#
- Parameters:
table –
RegisterTypeaddress –
quint16data –
quint16
- Return type:
bool
Writes data to the Modbus server. A Modbus server has four tables (table) and each have a unique address field, which is used to write data to the desired field. Returns false if address outside of the map range.
If the call was successful the dataWritten() signal is emitted. Note that the signal is not emitted when data has not changed. Nevertheless this function returns true in such cases.
See also
RegisterTypedata()dataWritten()
- PySide6.QtSerialBus.QModbusServer.setData(unit)
- Parameters:
- Return type:
bool
Writes newData to the Modbus server map. Returns false if the newData range is outside of the map range.
If the call was successful the dataWritten() signal is emitted. Note that the signal is not emitted when the addressed register has not changed. This may happen when newData contains exactly the same values as the register already. Nevertheless this function returns true in such cases.
See also
- PySide6.QtSerialBus.QModbusServer.setMap(map)#
- Parameters:
map –
- Return type:
bool
Sets the registered map structure for requests from other ModBus clients to map. The register values are initialized with zero. Returns true on success; otherwise false.
If this function is not called before connecting, a default register with zero entries is setup.
Note
Calling this function discards any register value that was previously set.
- PySide6.QtSerialBus.QModbusServer.setServerAddress(serverAddress)#
- Parameters:
serverAddress – int
Sets the address for this Modbus server instance to serverAddress.
See also
- PySide6.QtSerialBus.QModbusServer.setValue(option, value)#
- Parameters:
option – int
value – object
- Return type:
bool
Sets the newValue for option and returns true on success; false otherwise.
Note
If the option’s associated type is quint8 or quint16 and the type of newValue is larger, the data will be truncated or conversation will fail.
Key |
Description |
|---|---|
|
Sets the diagnostic register of the server in a device specific encoding to |
|
Sets the exception status byte offset of the server to The function returns |
|
Sets a flag that signals that the server is engaged in processing a long-duration program command. Valid values are |
|
The |
|
Ss the server’s listen only state to |
|
Sets the server’s manufacturer identifier to |
|
Sets the servers’ run indicator status to |
|
Sets the server’s additional data to |
|
Sets the server’s physical and functional description. By default there is no additional device identification data set. |
|
Sets the value of a user option to Note For user options, it is up to the developer to decide which types to use and ensure that components use the correct types when accessing and setting values. |
See also
- PySide6.QtSerialBus.QModbusServer.value(option)#
- Parameters:
option – int
- Return type:
object
Returns the value for option or an invalid QVariant if the option is not set.
Option
Description
DiagnosticRegisterReturns the diagnostic register value of the server. The diagnostic register contains device specific contents where each bit has a specific meaning.
ExceptionStatusOffsetReturns the offset address of the exception status byte location in the coils register.
DeviceBusyReturns a flag that signals if the server is engaged in processing a long-duration program command.
AsciiInputDelimiterReturns a end of message delimiter of Modbus ASCII messages.
ListenOnlyModeReturns the server’s listen only state. Messages are monitored but no response will be sent.
ServerIdentifierReturns the server manufacturer’s identifier code. This can be an arbitrary value in the range of
0x00to 0xff.
RunIndicatorStatusReturns the server’s run indicator status. This data is used as addendum by the
ReportServerIdfunction code.
AdditionalDataReturns the server’s additional data. This data is used as addendum by the
ReportServerIdfunction code.
DeviceIdentificationReturns the server’s physical and functional description.
UserOptionReturns the value of a user option.
Note
For user options, it is up to the developer to decide which types to use and ensure that components use the correct types when accessing and setting values.
See also
- PySide6.QtSerialBus.QModbusServer.writeData(unit)#
- Parameters:
- Return type:
bool
Writes newData to the Modbus server map. Returns true on success, or false if the newData range is outside of the map range or the registerType() does not exist.
Note
Sub-classes that implement writing to a different backing store then default one, also need to implement setMap() and readData() . The dataWritten() signal needs to be emitted from within the functions implementation as well.
See also