【发布时间】:2013-03-26 06:01:50
【问题描述】:
我有一个 Delcom USB 灯 - 想想我试图从 node.js 控制的构建灯 (http://www.delcomproducts.com/products_USBLMP.asp)(如果这有什么不同,可以在 Ubuntu 上运行)
我正在使用 node-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 并且“闪存”是计算机再次控制 USB 端口有关?
【问题讨论】:
-
嗯,首先你应该把那个逗号换成分号,另外,在语句的每一个结尾都加上分号是一个好习惯;
-
哈哈,你知道我来自php哪里;是必需的;)但是对于节点,似乎人们不使用它。