PDA

View Full Version : HID Transport Example script


Ron
December 21st, 2006, 08:55 AM
By popular demand here is an example of a HID transport. Note that we are still in Alpha stage meaning that stuff will change. Most notable we will be adding a wrapper class around the transport system to make it easier to write code that can talk any of the protocols without change.


function hid_cb(a,b)

if ( a ) then
print(math.formatbytes(a),b)
-- do something smart with the data coming in here
-- remove the print line above when done analyzing the protocol.
else
print(b)
end

end

-- print all attached HID devices.
table.print(transport.support.usbhid.ListDevices() )

-- create a HID transport channel.
hid = transport.New(transport.constants.transport.USBHID )
-- HID devices always prepend a report ID number, for most this is unimportant, but you might need it.
hid:StripReportID(false)
-- Set the CALLBACK method to read the incoming data.
hid:Callback(transport.constants.parser.STREAM, hid_cb)
-- Open the actually channel to the HID device
-- You'll need to have enough of the parameters below to uniquely identify the
-- device.
-- Open ( <VendorID>, <ProductID>, <Manufacterer>, <Serial Number>, <Device Name>)
-- Any of those parameters can be 'nil', which means match any device.
print(hid:Open(1151,3233,nil,nil,nil))

thermometer
December 23rd, 2006, 04:07 AM
Hi Ron,
excuse me for the question, but where should i write this script?

Regrads.

Ron
December 23rd, 2006, 03:39 PM
You can simply put this in a script action.

Chad
December 27th, 2006, 08:37 AM
Hi Ron! Thanks for the response to the problem! If I'm using version 4 should I change to 5 Alpha to test new HID? Thanks.

Ron
December 27th, 2006, 08:38 AM
Yes, you must upgrade to G5-Alpha as this is only support there.

offbyone
January 17th, 2007, 03:09 AM
Hi, I added a new action and pasted the script from your post into it and tested the action. This is the output:

[1] = {
["DeviceName"] = "USB",
["SerialNumber"] = "",
["ProductID"] = 49409,
["Manufacturer"] = "Logitech",
["VendorID"] = 1133,
},
[2] = {
["DeviceName"] = "USB",
["SerialNumber"] = "",
["ProductID"] = 49409,
["Manufacturer"] = "Logitech",
["VendorID"] = 1133,
},

I`m testing Girder5 because I have the Logitech USB HID Remote that has 2 devices and Girder4 wasn`t able to save the x, if you remeber what I mean.

Judging from the above output, there is still no way to make a difference between the 2 :(

Ron
January 17th, 2007, 10:57 AM
Then I'm afraid there is nothing I can do. If logitec doesn't even bother to put in a serial number how on earth are we supposed to always open the correct one. In the USB standard there is no such thing as a fixed usb port like a com1 in the serial case.

offbyone
January 17th, 2007, 12:41 PM
The point here is:
In Girder4 with the HID Plugin, the two devices alway come up in the same order.
There must be a way to differentiate between them. Isn't there any more info available on the HID device, or maybe the serial retrieval didn't work right? I used alpha 507 ...