QModbusDataUnit#

QModbusDataUnit is a container class representing single bit and 16 bit word entries in the Modbus register. More

Inheritance diagram of PySide6.QtSerialBus.QModbusDataUnit

Synopsis#

Functions#

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#

QModbusDataUnit can be used for read and write operations. The entries are addressed via startAddress() and the valueCount() number of contiguous entries. registerType() determines which register is used for the operations. Note that some registers are read-only registers.

The actual values() are either single bit or 16 bit based. DiscreteInputs and Coils only accept single bits. Therefore 0 is interpreted as 0 and anything else 1.

class PySide6.QtSerialBus.QModbusDataUnit#

PySide6.QtSerialBus.QModbusDataUnit(type)

PySide6.QtSerialBus.QModbusDataUnit(type, newStartAddress, newValues)

PySide6.QtSerialBus.QModbusDataUnit(type, newStartAddress, newValueCount)

Parameters:
  • newStartAddress – int

  • newValues

  • typeRegisterType

  • newValueCountquint16

Constructs an empty, invalid QModbusDataUnit . Start address is set to -1 and the registerType is set to Invalid .

Constructs a unit of data for register type. Start address is set to 0, data range and data values are empty.

Constructs a unit of data for register``type``. Start address of the data is set to address and the unit’s values to data. The value count is implied by the data size.

Constructs a unit of data for register``type``. Start address of the data is set to address and the size of the unit to size. The entries of values() are initialized with 0.

PySide6.QtSerialBus.QModbusDataUnit.RegisterType#

This enum describes all supported register types.

Constant

Description

QModbusDataUnit.Invalid

Set by the default constructor, do not use.

QModbusDataUnit.DiscreteInputs

This type of data can be provided by an I/O system.

QModbusDataUnit.Coils

This type of data can be alterable by an application program.

QModbusDataUnit.InputRegisters

This type of data can be provided by an I/O system.

QModbusDataUnit.HoldingRegisters

This type of data can be alterable by an application program.

PySide6.QtSerialBus.QModbusDataUnit.isValid()#
Return type:

bool

Returns true if the QModbusDataUnit is valid; otherwise false. A QModbusDataUnit is considered valid if the registerType() is not Invalid and the startAddress() is greater than or equal to 0.

PySide6.QtSerialBus.QModbusDataUnit.registerType()#
Return type:

RegisterType

Returns the type of the register.

See also

setRegisterType() RegisterType

PySide6.QtSerialBus.QModbusDataUnit.setRegisterType(type)#
Parameters:

typeRegisterType

Sets the register type.

See also

registerType() RegisterType

PySide6.QtSerialBus.QModbusDataUnit.setStartAddress(newAddress)#
Parameters:

newAddress – int

Sets the start address of the data unit.

See also

startAddress()

PySide6.QtSerialBus.QModbusDataUnit.setValue(index, newValue)#
Parameters:
  • indexqsizetype

  • newValuequint16

Sets the register at position index to value.

See also

value()

PySide6.QtSerialBus.QModbusDataUnit.setValueCount(newCount)#
Parameters:

newCountqsizetype

Sets the size of the requested register’s data block to newCount.

This may be different from values() size as this function is used to indicated the size of a data request. Only once the data request has been processed valueCount() is equal to the size of values() .

See also

valueCount()

PySide6.QtSerialBus.QModbusDataUnit.setValues(newValues)#
Parameters:

newValues

Sets the values of the data unit. DiscreteInputs and Coils tables only accept single bit value, so 0 is interpreted as 0 and anything else as 1.

See also

values()

PySide6.QtSerialBus.QModbusDataUnit.startAddress()#
Return type:

int

Returns the start address of data unit in the register.

PySide6.QtSerialBus.QModbusDataUnit.value(index)#
Parameters:

indexqsizetype

Return type:

quint16

Return the value at position index.

See also

setValue()

PySide6.QtSerialBus.QModbusDataUnit.valueCount()#
Return type:

qsizetype

Returns the size of the requested register’s data block or the size of data read from the device.

This function may not always return a count that equals values() size. Since this class is used to request data from the remote data register, the valueCount() can be used to indicate the size of the requested register’s data block. Once the request has been processed, the valueCount() is equal to the size of values() .

See also

setValueCount()

PySide6.QtSerialBus.QModbusDataUnit.values()#

Returns the data in the data unit. DiscreteInputs and Coils tables only accept single bit value, so 0 is interpreted as 0 and anything else as 1.

See also

setValues()