Last active
May 30, 2020 15:07
-
-
Save jhgorse/a584724153ad75aff3d6fdd81c5c9242 to your computer and use it in GitHub Desktop.
A simple push/pull USB HID API script for raw devices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# rvm use default | |
#### install for macOS | |
# \curl -sSL https://get.rvm.io | bash -s stable --ruby | |
# source $HOME/.rvm/scripts/rvm | |
# rvm use default | |
# gem install hidapi | |
require "hidapi" | |
STDOUT.sync = true # allow us to use pipes on the output | |
vendor_id = 0x10c4 | |
product_id = 0x63cd | |
kext_handle = HIDAPI::SetupTaskHelper.new( | |
vendor_id, # vendor_id | |
product_id, # product_id | |
"irradiance", # simple_name | |
0 # interface | |
).run | |
handle = HIDAPI::open(0x10c4, 0x63cd) | |
# printf "%04X:%04X %02x Mfg: %-12s P: %s\n", 0x10c4, 0x63cd, 0, handle.get_manufacturer_string, handle.get_product_string | |
buf = Array.new(61) { |i| (0) }; | |
buf[0] = 0x2 | |
while 1 do | |
handle.write(buf) | |
rbuf = handle.read_timeout(buf.length,1000) | |
print rbuf.read_bytes(buf.length).unpack("C*"), "\n" | |
#rbuf.read_bytes(61).unpack("C*") # full packet | |
sleep(0.2) | |
end | |
HIDAPI::hid_close(handle) |
still works 2020. must use rvm on macOS, though.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if you want to use the HIDAPI layer via FFI, we need buffers like this: