fix serial port list race condition for windows
This commit is contained in:
parent
9cbed822ab
commit
1a5fa6f00f
1 changed files with 14 additions and 12 deletions
|
|
@ -112,17 +112,18 @@ var WebsocketController = function(sockets, version) {
|
||||||
machine.requestSettings();
|
machine.requestSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
var comName = '';
|
var onGetPorts = function(cb) {
|
||||||
|
|
||||||
var onGetPorts = function() {
|
|
||||||
sp_controller.listPorts(function (ports) {
|
sp_controller.listPorts(function (ports) {
|
||||||
|
|
||||||
ports.forEach(function(p) {
|
|
||||||
if(/Arduino/gi.test(p.manufacturer)) comName = p.comName;
|
|
||||||
});
|
|
||||||
|
|
||||||
sockets.emit('ports', ports);
|
sockets.emit('ports', ports);
|
||||||
|
|
||||||
|
if( !cb)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ports.forEach(function(p) {
|
||||||
|
if(/Arduino/gi.test(p.manufacturer)) cb(p.comName);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -159,12 +160,12 @@ var WebsocketController = function(sockets, version) {
|
||||||
|
|
||||||
if (connectedClients !== 0)
|
if (connectedClients !== 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
machine.disconnect();
|
machine.disconnect();
|
||||||
|
|
||||||
// turn off power
|
// turn off power
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
power.writeSync(0);
|
power.writeSync(0);
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -195,10 +196,11 @@ var WebsocketController = function(sockets, version) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! comName) onGetPorts();
|
onGetPorts(function(cn) {
|
||||||
|
logger.log("trying to init port: " + cn);
|
||||||
|
sp_controller.initPortWithConfigs(cn, config);
|
||||||
|
});
|
||||||
|
|
||||||
logger.log("trying to init port: " + comName);
|
|
||||||
sp_controller.initPortWithConfigs(comName, config);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sockets.on('connection', function(socket) {
|
sockets.on('connection', function(socket) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue