Serialport module in node.js works only if minicom is active on the port

本小妞迷上赌 提交于 2019-11-28 12:34:08

问题


I am using version 3.10 of the serialport module of Node.js.
I have a GSM modem attached to an Ubuntu machine's serialport and I am sending SMS through the modem. Here is the simplified code:

var serialPort = require("serialport");
const Readline = serialPort.parsers.Readline;

var portSerial = new serialPort("/dev/ttyUSB1", {
    baudrate: 115200,
    dataBits:8, stopBits:1, parity: 'none'
}, function (err) {
    if (err)
      //log error here
    });

parser = new Readline();

portSerial.pipe(parser);

portSerial.on("open", function(err) {
  if (err)
     return console.log("Error in opening serial port");
  console.log("Port opened");
});

portSerial.on('error', function(err) {
   //log error
})

//Send SMS
setTimeout(function() {
  portSerial.write('AT+CMGF=1\nAT+CMGS="'+SMSphone + '"\n' +     
              SMSmessage +  '\032');
}, 1000);

Yes, I am setting SMSphone and SMSmessage variables. And the code is actually a bit more complex but the core code for sending SMS is as shown above.

PROBLEM: All works fine if I am running minicom when the SMS is sent. The moment I exit minicom, the SMS do not go out. portSerial.write stops working.

It was all working fine until I upgraded the serialport version.

来源:https://stackoverflow.com/questions/45936310/serialport-module-in-node-js-works-only-if-minicom-is-active-on-the-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!