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))
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))