我是节点 js 的新手。我使用 node、express、socket 和 serialport 创建了一个应用程序。我有一个连接到串行端口(COM2)的称重秤。在 Windows(本地主机)上它工作得很好。但是当我将它部署在我的 Linux CentOS 6 服务器上时,它没有读取任何串行端口。
包.json
{
"name": "socket",
"version": "0.0.1",
"description": "wieghing machine serial port socket app",
"dependencies": {
"express": "^4.10.2",
"socket.io": "1.2.0",
"bindings": "1.2.1",
"commander": "^2.9.0",
"debug": "^2.4.5",
"nan": "^2.4.0",
"node-pre-gyp": "^0.6.32"
},
"devDependencies": {
"serialport": "^4.0.7"
}
}
应用程序.js
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var SerialPort = require('serialport');
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
socket.on('register', function(msg){
io.emit('register', msg);
});
});
http.listen(8081, function(){
console.log('listening on *:8081');
});
var port = new SerialPort("COM2", {
baudrate: 9600
});
port.on('data', function (data) {
io.emit('WeightMachine', data.toString());
});
SerialPort.list(function (err, ports) {
ports.forEach(function(port) {
console.log(port.comName);
console.log(port.pnpId);
console.log(port.manufacturer);
});
});
请不要将我的问题标记为否定我真的是节点 js 的新手。提前致谢。