def from_bytes(cls, data): msgid, btag, btaginverse = struct.unpack_from('BBBx', data) assert msgid == MsgID.dev_dep_msg_in transfer_size, transfer_attributes = struct.unpack_from('<LBxxx', data, 4) data = data[12:] return cls(msgid, btag, btaginverse, transfer_size, transfer_attributes, data)
def from_bytes(cls, data): msgid, btag, btaginverse = struct.unpack_from('BBBx', data) assert msgid == MsgID.dev_dep_msg_in transfer_size, transfer_attributes = struct.unpack_from( '<LBxxx', data, 4) data = data[12:] return cls(msgid, btag, btaginverse, transfer_size, transfer_attributes, data)
def from_quirky(cls, data): """Constructs a correct response for quirky devices""" msgid, btag, btaginverse = struct.unpack_from('BBBx', data) data = data.rstrip(b'\x00') # check whether it contains a ';' and if throw away the first 12 bytes if ';' in str(data): transfer_size, transfer_attributes = struct.unpack_from('<LBxxx', data, 4) data = data[12:] else: transfer_size = 0 transfer_attributes = 1 return cls(msgid, btag, btaginverse, transfer_size, transfer_attributes, data)
def from_bytes(cls, data): msgid, btag, btaginverse = struct.unpack_from('BBBx', data) if msgid != MsgID.dev_dep_msg_in: warnings.warn('Unexpected MsgID format. Consider updating the device\'s firmware. See https://github.com/pyvisa/pyvisa-py/issues/20') return BulkInMessage.from_quirky(data) transfer_size, transfer_attributes = struct.unpack_from('<LBxxx', data, 4) # Truncate data to the specified length (discard padding). data = data[12:12+transfer_size] return cls(msgid, btag, btaginverse, transfer_size, transfer_attributes, data)
def from_bytes(cls, data): msgid, btag, btaginverse = struct.unpack_from('BBBx', data) if msgid != MsgID.dev_dep_msg_in: raise ValueError("Unexpected MsgID 0x{:02x}".format(msgid)) transfer_size, transfer_attributes = struct.unpack_from( '<LBxxx', data, 4) # Truncate data to the specified length (discard padding). data = data[12:12 + transfer_size] return cls(msgid, btag, btaginverse, transfer_size, transfer_attributes, data)
def from_quirky(cls, data): """Constructs a correct response for quirky devices""" msgid, btag, btaginverse = struct.unpack_from('BBBx', data) data = data.rstrip(b'\x00') # check whether it contains a ';' and if throw away the first 12 bytes if ';' in str(data): transfer_size, transfer_attributes = struct.unpack_from( '<LBxxx', data, 4) data = data[12:] else: transfer_size = 0 transfer_attributes = 1 return cls(msgid, btag, btaginverse, transfer_size, transfer_attributes, data)
def from_bytes(cls, data): msgid, btag, btaginverse = struct.unpack_from('BBBx', data) if msgid != MsgID.dev_dep_msg_in: warnings.warn( 'Unexpected MsgID format. Consider updating the device\'s firmware. See https://github.com/pyvisa/pyvisa-py/issues/20' ) return BulkInMessage.from_quirky(data) transfer_size, transfer_attributes = struct.unpack_from( '<LBxxx', data, 4) # Truncate data to the specified length (discard padding). data = data[12:12 + transfer_size] return cls(msgid, btag, btaginverse, transfer_size, transfer_attributes, data)