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

753 views Asked by At

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.

0

There are 0 answers