def disableSniffing(self): self.sn = self.sn + 1 if self.sn > 255: self.sn = 1 data = struct.pack('BBBBBBBBBB', 0xAA, HASSEB_CONFIGURE_DEVICE, self.sn, 0, 0, 0, 0, 0, 0, 0) hidapi.hid_write(self.device, data)
def send(self, command): time.sleep(0.02) # a delay between sent messages need to be at lest 22*417 µs self._response_message = None data = self.construct(command) self.send_message = struct.pack('BB', data[7], data[8]) if command.response is not None: self._pending = command self._response_message = None hidapi.hid_write(self.device, data) self.wait_for_response() return command.response(self.extract(self._response_message)) else: self._pending = None hidapi.hid_write(self.device, data) return
def ptt_stop(self) -> int: """[TX] Stops Transmit on the Radio.""" stop = roip.PTT_STOP wrote = hidapi.hid_write(self.hid_device, stop) self._logger.debug('stop="%s" wrote="%s"', stop, wrote) assert len(stop) == wrote return wrote
def ptt_start(self) -> int: """[TX] Triggers Transmit on the Radio.""" start = roip.PTT_START wrote = hidapi.hid_write(self.hid_device, start) self._logger.debug('start="%s" wrote="%s"', start, wrote) assert len(start) == wrote return wrote
def readFirmwareVersion(self): self.sn = self.sn + 1 if self.sn > 255: self.sn = 1 data = struct.pack('BBBBBBBBBB', 0xAA, HASSEB_READ_FIRMWARE_VERSION, self.sn, 0, 0, 0, 0, 0, 0, 0) hidapi.hid_write(self.device, data) data = hidapi.hid_read(self.device, 10) for i in range(0, 100): if len(data) == 10: if data[1] != HASSEB_READ_FIRMWARE_VERSION: data = hidapi.hid_read(self.device, 10) else: return f"{data[3]}.{data[4]}" else: data = hidapi.hid_read(self.device, 10) return f"VERSION_ERROR"
def SendCommand(packet_array): packets = chr(0x00) # pre-pad with 0x00 per hid_write documentation for byte in packet_array: packets = packets + chr(int(byte, 16)) hidapi.hid_init() # Connect to the RadioSHARK dev = hidapi.hid_open(0x077d, 0x627a) # Write the packets packets_written = hidapi.hid_write(dev, packets) # Close out hidapi.hid_close(dev) if (args.debug): print "Packet Array: %s" % packet_array print "Number of Packets Sent: %s" % str(1 + len(packet_array)) print "Number of Packets Written: %i" % packets_written
def clear_display(no): for i in range(0, 8): hidapi.hid_write(device, (bytearray((("e00000%02x00200008" % (8 * i) + ((265 - 8) * "00")).replace("e0", "e%d" %no)).decode("hex"))))
hidapi.hid_init() print 'Loaded hidapi library from: {:s}\n'.format(hidapi.hid_lib_path()) devices = hidapi.hid_enumerate(0x17cc, 0x1140) if len(devices) == 0: print "No maschine attached" exit(1) device = hidapi.hid_open(0x17cc, 0x1140) quiet_state = "20000000100020003000400050006000700080009000a000b000c000d000e000f0000000100020003000400050006000700080009000a000b000c000d000e000f0" to_bytearray = lambda display: [bytearray(line.replace(" ", "").decode("hex")) for line in display] write_display = lambda display: [hidapi.hid_write(device, line) for line in to_bytearray(display)] def clear_display(no): for i in range(0, 8): hidapi.hid_write(device, (bytearray((("e00000%02x00200008" % (8 * i) + ((265 - 8) * "00")).replace("e0", "e%d" %no)).decode("hex")))) led_state = bytearray("820a0a0a 0a0a0a0a 0a0a0a0a 0a0a0a0a 0a0a0a0a 0a0a0a0a 0a3f3f3f 3f3f3f3f".replace(" ", "").decode("hex")) hidapi.hid_write(device, led_state) def import_image(display_no, fname): import textwrap result_str = open(fname, "r").read() result_bytes = textwrap.wrap(result_str, 2) # reverse bits of each byte result_bytes = ''.join(['%02x' % int('{0:08b}'.format(int(n, 16))[::-1], 2) for n in result_bytes]) print result_bytes
def tx_type2(handle, msg): msg = bytes('@', 'utf-8') + seq2.to_bytes(1, byteorder='big') + bytes('{}\n@@@@@@@@@@@@@'.format(msg), 'utf-8') hidapi.hid_write(handle, msg)
def tx_type1(handle, msg): msg = bytes('@{:04X}{}\n@@@@@@@@@@'.format(0x0001, msg), 'utf-8') hidapi.hid_write(handle, msg)
def send_message(self, command, data=[]): message_id, message = self.construct_message(command, data) result = Deferred() self.pending_requests[message_id] = result hidapi.hid_write(self.device, message) return Promise(result)
def write_teensy(dev, buf, buf_size): # add report id buf = ctypes.create_string_buffer("\x00" + buf.raw) buf_size = buf_size + 1 # write data return hidapi.hid_write(dev, buf, buf_size)
def tx_type2(self, handle, msg): msg = bytes('@') + self.to_bytes(self.seq2, 1) + bytes( '{}\n@@@@@@@@@@@@@'.format(msg)) hidapi.hid_write(handle, msg)
def tx_type1(self, handle, msg): msg = bytes('@{:04X}{}\n@@@@@@@@@@'.format(self.seq1, msg)) hidapi.hid_write(handle, msg)