How to use the hidapi.write function in hidapi

To help you get started, we’ve selected a few hidapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pwr-Solaar / Solaar / lib / logitech_receiver / View on Github external
been physically removed from the machine, or the kernel driver has been
	unloaded. The handle will be closed automatically.
	# the data is padded to either 5 or 18 bytes
	assert data is not None
	assert isinstance(data, bytes), (repr(data), type(data))

	if len(data) > _SHORT_MESSAGE_SIZE - 2 or data[:1] == b'\x82':
		wdata = _pack('!BB18s', 0x11, devnumber, data)
		wdata = _pack('!BB5s', 0x10, devnumber, data)
	if _log.isEnabledFor(_DEBUG):
		_log.debug("(%s) <= w[%02X %02X %s %s]", handle, ord(wdata[:1]), devnumber, _strhex(wdata[2:4]), _strhex(wdata[4:]))

		_hid.write(int(handle), wdata)
	except Exception as reason:
		_log.error("write failed, assuming handle %r no longer available", handle)
		raise NoReceiver(reason=reason)
github pwr-Solaar / Solaar / lib / hidapi / View on Github external
# move the cursor at the bottom of the screen
			sys.stdout.write('\033[300B')  # move cusor at most 300 lines down, don't scroll

		while t.is_alive():
			line = read_packet(prompt)
			line = line.strip().replace(' ', '')
			# print ("line", line)
			if not line:

			data = _validate_input(line, args.hidpp)
			if data is None:

			_print('<<', data)
			_hid.write(handle, data)
			# wait for some kind of reply
			if args.hidpp and not interactive:
				rlist, wlist, xlist = _select([handle], [], [], 1)
				if data[1:2] == b'\xFF':
					# the receiver will reply very fast, in a few milliseconds
					# the devices might reply quite slow
	except EOFError:
		if interactive:
			print ("")