class 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#

Methods#

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 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.

__init__()#

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

__init__(type)
Parameters:

typeRegisterType

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

__init__(type, newStartAddress, newValues)
Parameters:
  • typeRegisterType

  • newStartAddress – int

  • newValues – .list of quint16

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.

__init__(type, newStartAddress, newValueCount)
Parameters:
  • typeRegisterType

  • newStartAddress – int

  • newValueCount – int

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.

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.

registerType()#
Return type:

RegisterType

Returns the type of the register.

setRegisterType(type)#
Parameters:

typeRegisterType

Sets the register type.

setStartAddress(newAddress)#
Parameters:

newAddress – int

Sets the start address of the data unit.

See also

startAddress()

setValue(index, newValue)#
Parameters:
  • index – int

  • newValue – int

Sets the register at position index to value.

See also

value()

setValueCount(newCount)#
Parameters:

newCount – int

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()

setValues(newValues)#
Parameters:

newValues – .list of quint16

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()

startAddress()#
Return type:

int

Returns the start address of data unit in the register.

value(index)#
Parameters:

index – int

Return type:

int

Return the value at position index.

See also

setValue()

valueCount()#
Return type:

int

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()

values()#
Return type:

.list of quint16

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()