node.js<-&燃气轮机;带有串行端口的arduino。错误资源暂时不可用无法锁定端口
当号码第一次从NodeJS发送到Arduino时,我看到以下错误:node.js<-&燃气轮机;带有串行端口的arduino。错误资源暂时不可用无法锁定端口,node.js,arduino,serial-port,webserver,Node.js,Arduino,Serial Port,Webserver,当号码第一次从NodeJS发送到Arduino时,我看到以下错误: 错误资源暂时不可用无法锁定端口 我使用Linux 我首先更新一些值(在web服务器中),然后串口捕获该值, 所以我可以在Arduino串行监视器中看到值 但是在我再次更新一些值之后,它会导致一个错误 这是NodeJS代码: var serialport = require('serialport'), SerialPort = serialport.SerialPort, portName = '/dev/ttyACM0
错误资源暂时不可用无法锁定端口
我使用Linux
我首先更新一些值(在web服务器中),然后串口捕获该值,
所以我可以在Arduino串行监视器中看到值
但是在我再次更新一些值之后,它会导致一个错误
这是NodeJS代码:
var serialport = require('serialport'),
SerialPort = serialport.SerialPort,
portName = '/dev/ttyACM0',
portConfig = {
baudRate: 9600,
// call myPort.on('data') when a newline is received:
//parser: serialport.parsers.readline('\n')
};
... (code) ...
pool.getConnection(function(err,connection)
{
var sql = "update value set temperature=? , humidity=? where idx=?";
connection.query(sql,[temperature,humidity,idx],function(err,result)
{
console.log(result);
if(err) console.error("update errrr : ",err);
var myPort = new SerialPort(portName, portConfig);
myPort.on('open', openPort);
function openPort() {
var temp = temperature;
console.log('port open');
console.log('baud rate: ' + myPort.options.baudRate);
function sendData() {
//myPort.write(temp.toString()); for(var i=0; i<temp.length; i++) {
myPort.write(new Buffer(temp[i], 'ascii'), function(err, results) {
});
}
console.log('Sending ' + temp + ' out the serial port');
} setTimeout(sendData, 500); myPort.close
}
res.redirect('/');
connection.release();
});
}); });
我找到了答案
function openPort() {
var temp = temperature;
console.log('port open');
console.log('baud rate: ' + myPort.options.baudRate);
setTimeout(sendData, 1);
function sendData() {myPort.write(new Buffer(temp, 'ascii'), function(err, results) {});
console.log('Sending ' + temp + ' out the serial port');
myPort.close(function () {console.log('port Closed.');});
}
}
我找到了答案
function openPort() {
var temp = temperature;
console.log('port open');
console.log('baud rate: ' + myPort.options.baudRate);
setTimeout(sendData, 1);
function sendData() {myPort.write(new Buffer(temp, 'ascii'), function(err, results) {});
console.log('Sending ' + temp + ' out the serial port');
myPort.close(function () {console.log('port Closed.');});
}
}