2013-03-26 162 views
0

我有一个USB DELCOM光 - 想建光(http://www.delcomproducts.com/products_USBLMP.asp),我试着从node.js的控制(在Ubuntu上运行,如果有什么差别)使用Node.JS和node-usb进行USB Light HID控制 - 仅闪光?

我使用节点-USB( https://github.com/schakko/node-usb),我可以连接&索赔设备。我甚至可以让它“闪”(就像它当您第一次插上),但我不能让它一直亮着,更不用说改变颜色

var usb_driver = require("../usb.js"), 
    assert = require('assert'); 

// setup our vars 
var lightVID = 0x0fc5 
var lightPID = 0xb080 

// Search for ledLight 
var usb = usb_driver.create() 

var theLight_devices = usb.find_by_vid_and_pid(lightVID, lightPID); 
assert.ok((theLight_devices.length >= 1)); 
console.log("Total lights found: " + theLight_devices.length); 

// get the light 
var theLight = theLight_devices[0]; 

var theLightInterfaces = theLight.getInterfaces(); 
assert.ok((theLightInterfaces.length >= 1)); 
console.log("The Light contains interfaces: " + theLightInterfaces.length); 

var theLightInterface = theLightInterfaces[0]; 
console.log("Claiming the LIGHT interface for further actions") 
theLightInterface.detachKernelDriver(); 
//theLightInterface.claim() 

console.log(theLightInterface.claim()); 

// controlTransfer(mixed read|write, _bmRequestTyc8, _bRequest, _wValue, _wIndex, func, timeout); 
theLight.controlTransfer(new Buffer(10), 0x88, 0xc8, 0x0635, 0x04, function() {  console.log("LED toggled") }, 0); 

当你运行它,它告诉我有一个设备,它声称它,它甚至闪烁,但它不会保持。

想转向下一个的任何想法?

与Node.js关闭有什么关系,“flash”是再次控制USB端口的计算机吗?

+0

好吧,首先,你应该将该逗号替换为分号,并且将分号放在语句的每一端都是一个好习惯; – 2013-03-26 07:09:40

+0

哈哈,你知道我来自php哪里;是必需的;)但是对于节点,似乎人们不使用它。 – keranm 2013-03-26 07:17:47

回答

0

继承人一些更新的代码:

var theLightInterface = theLightInterfaces[0] 
console.log("Claiming the LIGHT interface for further actions " + theLightInterface) 

for(var inter in theLightInterface){ 
    console.log("Name: "+ inter) 
    console.log("Value: "+ theLightInterface[inter]) 
} 
console.log("Is Active: "+ theLightInterface.isKernelDriverActive()) 
console.log("Release Kernel: "+ theLightInterface.detachKernelDriver()) 
console.log("Claim Interface: "+ theLightInterface.claim()) 

theLight.controlTransfer(new Buffer(0), 0x12, 0xc8, 0x04, 101, function() { console.log("LED toggled") }, 1000) 

而且outupt是:

Is Active: 1 
Release Kernel: undefined 
Claim Interface: undefined 

随着×12和0xc8集,它使光线闪烁/闪光 - 但我不认为我有控制的USB驱动程序