You can create a UBXMessage object using its constructor. This allows you to manually construct any UBX message by specifying its class, ID, and payload.
Constructor Signature:
pyubx2.ubxmessage.UBXMessage(ubxClass, ubxID, mode: int, **kwargs)
Parameters:
ubxClass: Message class (can be a lookup string, integer, or bytes from pyubx2.UBX_CLASSES).ubxID: Message ID (can be a lookup string, integer, or bytes from pyubx2.UBX_MSGIDS).mode: Operation mode (0=GET, 1=SET, 2=POLL).**kwargs: Optional keyword arguments representing the message payload.payload: (Optional) A single sequence of bytes representing the full payload. Required for messages with 'variable by size' repeating groups.- Individual attributes: One or more keyword arguments corresponding to message attributes. Unspecified attributes are set to nominal values.
parsebitfield: (Optional) 1 to define bitfields as individual bits (default), 0 to define as byte sequences.
Payload Definition Methods:
- Full Bytes: Pass
payload=b'...'. Use this for variable-sized messages. - Individual Attributes: Pass attributes as keyword arguments (e.g.,
rateUART1=1). - Minimal: If no keyword arguments are passed, the payload is assumed to be null.
from pyubx2 import UBXMessage, SET
# Method A: Pass entire payload as bytes
msg1 = UBXMessage(b'\x06', b'\x01', SET, payload=b'\x01\x03\x00\x01\x00\x00\x00\x00')
# Method B: Pass individual attributes as keyword arguments
msg2 = UBXMessage(0x06, 0x01, SET, msgClass=0x01, msgID=0x03, rateDDC=0, rateUART1=1, rateUART2=0, rateUSB=0, rateSPI=0)
# Method C: Pass selected attributes (others default to nominal/0)
msg3 = UBXMessage('CFG','CFG-MSG', SET, msgClass=0x01, msgID=0x03, rateUART1=1)