''' ThorLABS APT Protocol Message Registry Thomas Ales | Feb 2026 Version 1 ''' import struct class APTProtocol(): ADDRESSES = { 'HOST_PC': 0x01, 'CONTROLLER': 0x11, 'X_AXIS': 0x21, 'Y_AXIS': 0x22 } # N.B.: If the format is anything other than the following # two, it is considered a 'long' message. In this case # the format key refers only to the payload part of the # message. # BB - Short Message, Only Source/Destination # BBBB - Short Message, Using Parameters 1 & 2 # Dictionary entries MUST BE in the order they # appear in the thorlabs documentation, if you don't # the unpacking logic goes all to 💩 and 'fun' things # happen. MSGS = { 0x0002: { 'name': 'MGMSG_HW_DISCONNECT', 'format': 'BB', 'response': None, 'fields': ['destination', 'source'], 'data_fields': None }, 0x0005: { 'name': 'MGMSG_HW_REQ_INFO', 'format': 'BB', 'response': 0x0006, 'fields': ['destination', 'source'], 'data_fields': None }, 0x0006: { 'name': 'MGMSG_HW_GET_INFO', 'format': ' 0 else 0x00 p2 = kwargs.get(param_fields[1], 0x00) if len(param_fields) > 1 else 0x00 message = struct.pack(' 0: data[param_fields[0]] = bdata[2] if len(param_fields) > 1: data[param_fields[1]] = bdata[3] return msg_id, data else: raise ValueError(f"Message format {fmt_string} isn't defined/valid!") @classmethod def get_name(cls, msg_id): return cls.MSGS.get(msg_id, {}).get('name', f'UNKNOWN_{hex(msg_id)}')