编辑:我知道JS是异步的,我看过如何返回线程。我遇到的问题是从“ foo”示例到特定的东西=我不确定在哪里重新设置格式。
另外这里是一些上下文:https : //github.com/sharkwheels/beanballs/blob/master/bean-to-osc-two.js
我有一个关于节点收益的问题。这可能是一个愚蠢的问题,但这是正确的。我有一个连接到套接字并从处理中获取OSC消息的函数:
var sock = dgram.createSocket("udp4", function(msg, rinfo) {
try {
// get at all that info being sent out from Processing.
//console.log(osc.fromBuffer(msg));
var getMsg = osc.fromBuffer(msg);
var isMsg = getMsg.args[0].value;
var isName = getMsg.args[1].value;
var isAdd = getMsg.address;
var isType = getMsg.oscType;
// make an array out of it
var isAll = [];
isAll.push(isName);
isAll.push(isMsg);
isAll.push(isAdd);
isAll.push(isType);
// return the array
console.log(isAll);
return isAll;
} catch (error) {
console.log(error);
}
});
下面是另一个功能的开始,它将一些该数组写入BLE设备。它需要不同功能的名称和特征。如何获得下面的函数以使用isAll和两个现有参数?
var writeToChars = function (name, characteristics) { // this is passing values from the BLE setup function
// i need to get isAll to here.
// eventually this will write some values from isAll into a scratch bank.
}
谢谢。
好吧。因此,我至少在这种情况下才知道该怎么办。我敢肯定有更好的方法可以做到这一点,但是目前为止,这是可行的。
我将现有的外围设备全局数组映射到write函数中,同时将OSC消息作为参数传递给它。这解决了我的问题“如何将两个信息发送到同一位置”。它找出哪个外围设备,并向每个外围设备的每个暂存区写入不同的值。留在这里以备将来参考。
var writeToBean = function(passThrough){
var passThrough = passThrough;
console.log("in Write to bean: ", passThrough);
_.map(beanArray, function(n){
if(n.advertisement.localName === passThrough.name){
//var name = n.advertisement.localName;
n.discoverSomeServicesAndCharacteristics(['a495ff20c5b14b44b5121370f02d74de'], [scratchThr], function(error, services, characteristics){
var service = services[0];
var characteristic = characteristics[0];
var toSend = passThrough.msg;
console.log("service", service);
console.log("characteristic", characteristic);
if (toSend != null) {
characteristic.write(new Buffer([toSend]), false, function(error) {
if (error) { console.log(error); }
console.log("wrote " + toSend + " to scratch bank 3");
});
}
// not sure how to make the program resume, it stops here. No error, just stops processing.
});
}
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句