Exemplo n.º 1
0
    def __init__(self, config_path, config_option):
        self.is_configured = False
        self.is_connected = False
        self.connected_to = None
        self._ser = []
        self._mode = []
        self._port = None
        self._baud = []
        self._timeout = []
        self._vpi_mask = []
        self.id = []

        self._autoconnect = []
        self._in_buffer = []
        self._out_buffer = []
        self._wait_for_ver = []
        self._wait_for_data = []
        self.crc = Crc('crc-8')

        # ###### INCOMPLETE ###### #
        self.configure(config_path, config_option)
        if self._autoconnect:
            if TransceiverModes[self._mode] is TransceiverModes.MASTER:

                pass
            elif TransceiverModes[self._mode] is TransceiverModes.SLAVE:
                pass
Exemplo n.º 2
0
 def receive_raw(self):
     """
     Receives a response and returns the raw values
     """
     length_byte = self.connection.read(1)
     length = struct.unpack("<B", length_byte)[0]
     packet = self.connection.read(length)
     # Check the CRC checksum
     crc16 = Crc("crc-16-mcrf4xx")
     crc16.update(length_byte + packet[:-2])
     packet_crc = struct.unpack("<H", packet[-2:])[0]
     if crc16.crcValue != packet_crc:
         raise RuntimeError("Bad CRC checksum on response: %s != %s" %
                            (crc16.crcValue, packet_crc))
     # Unpack main values
     address, command, status = struct.unpack("<BBB", packet[:3])
     data = packet[3:-2]
     # Check for errors
     if status == STATUS.ERROR_COMMAND_EXECUTE:
         raise CommandExecutionError()
     if status == STATUS.ERROR_POOR_COMMS:
         raise PoorCommunicationError()
     if status == STATUS.ERROR_NO_TAG:
         raise NoTagError()
     if status == STATUS.ERROR_COMMAND_LENGTH:
         raise CommandLengthWrong()
     if status == STATUS.ERROR_TAG_INTERNAL:
         raise InternalTagError(struct.unpack("<B", data)[0])
     if status == STATUS.ERROR_ILLEGAL_COMMAND:
         raise IllegalCommand()
     if status == STATUS.ERROR_PARAMETER:
         raise ParameterError()
     # Return raw data
     return address, command, status, data
Exemplo n.º 3
0
 def send_raw(self, address, command, data):
     """
     Sends a command to the device.
     """
     # Packet header
     packet = struct.pack("<BBB", len(data) + 4, address, command)
     # Packet data
     packet += data
     # CRC
     crc16 = Crc("crc-16-mcrf4xx")
     crc16.update(packet)
     packet += struct.pack("<H", crc16.crcValue)
     # print(["%02x" % x for x in packet])
     self.connection.write(packet)
Exemplo n.º 4
0
def set_speed(speed, acceleration, deceleration=None):
    """Set the speed of the vial spinner

    Args:
        speed (int): The permille to spin the vial at (-1000 to 1000)
        acceleration: The acceleration in units/s^2
        deceleration: The deceleration in units/s^2
            Default acceleration
    """

    if deceleration is None:
        deceleration = acceleration

    if not (-1000 <= speed <= 1000):
        raise ValueError(
            f'{speed} is outside the permitted range (-1000 to 1000)')

    speed = speed.to_bytes(2, byteorder='little', signed=True)
    acceleration = acceleration.to_bytes(2, byteorder='little')
    deceleration = deceleration.to_bytes(2, byteorder='little')

    packet = speed + acceleration + deceleration

    crc16 = Crc('crc-ccitt-false')
    crc16.update(packet)
    packet += crc16.crcValue.to_bytes(2, byteorder='little')

    ser = serial.Serial()
    ser.baudrate = 115200
    ser.port = port
    ser.timeout = 0.1
    ser.dtr = None

    with ser as com:
        com.write(b'!' + packet)
        line = com.read(1)
        print(line.decode())
Exemplo n.º 5
0
    print "Illegal band and/or spacing"
    sys.exit(1)

if modf(chan)[0] != 0.0:
    print "Illegal freq/spacing combo"
    sys.exit(2)

chan = int(chan)

# First create the data without the checksum, note that we specify
# little-endianness for multi-byte values.

t = pack('<BBBHB8x', band, demphasis, spacing, chan, volume)

# Calculate and append a crc-16 checksum
crc16 = Crc('crc-16')
crc16.update(t)

t = t + pack('<H', crc16.crcValue)

#
# Simply create a hex file with the concatenation of two tuning structures (t)
# and optionally one manufacturing structure, then write the result.
#
eeprom = t + t

if manuf:
    eeprom = eeprom + manuf_record(sn, ts, campaign)

hexfile = IntelHex()
hexfile.puts(0, eeprom)