AT命令通过Serialport Node.js停止

时间:2019-07-29 18:52:24

标签: node.js gsm

262/5000 您好,我正在尝试通过nodejs和充当调制解调器的USB软件狗发送SMS,但是当我执行命令时,它被阻止,而其余部分则不执行,但是当我删除该命令时,我收到了SMS,但文本为带有AT命令HELP的消息!

var SerialPort = require('serialport');
var port = new SerialPort("COM5", {
 baudRate: 9600,
 dataBits: 8,
 parity: 'none',
 stopBits: 1,
 flowControl: false});
 port.on("open", onOpen);
 port.on('error', onError);
 port.on('data', onDataReceived);

function onOpen(error) {
 if(!error){
    console.log('Port open sucessfully');
        send(port, "XXXX", "BAL");
        //read(port);
 }
}

function onDataReceived(data){
console.log("Received data: " + data);}

function send(serial, toAddress, message) {
serial.write("AT+CMGF=1"); //This command stopped script
serial.write('\r');
serial.write("AT+CMGS=\"" + toAddress + "\""); //send sms but the text included AT COMMAND
serial.write('\r');
serial.write(message);
serial.write(Buffer([0x1A]));
serial.write('^z');}

0 个答案:

没有答案