angles0394
angles0394

Reputation: 1

No response from serial communication write command

I have a serial port that I want to communicate with using node js. Here is the dump of successful communication interaction. this is my spec (async serial protocol) spec doc

(COM1 in windows) successful serial port communication screenshot

However when I use nodejs to replicate that interaction, I don't get any response from the port. (/dev/tty.usbserial-14420 in macOS)

var serialport = require("serialport"); 

const port = "/dev/tty.usbserial-14420";

const ACK = 0x06;
const NAK = 0x15;
const ENQ = 0x05;
const EOT = 0x04;
const STX = 0xF2;
const ETX   = 0x03;
const CMT = "C";


let f3 = new serialport(port, {
  baudRate: 9600
})

var Readline = serialport.parsers.Readline; // make instance of Readline parser
var parser = new Readline(); // make a new parser to read ASCII lines
f3.pipe(parser); // pipe the serial stream to the parser

f3.on('open', () => {
    console.log('port open');
    f3.write(makeMessage1());
    f3.write(makeMessage0());
    f3.write(makeMessage2());
});

parser.on('data', (data) => {
    console.log("data received "+data);
});

f3.on('error', (error) => {
  console.log('error: ' + error);
})

function makeMessage0() {
  return new Buffer.from('05');
}

function makeMessage1() {
  return new Buffer.from('f2 00 00 03 43 30 33 03 b2');
}


function makeMessage2() {
  return new Buffer.from('f2 00 00 03 43 32 03 ba');
}

output:

port open

Upvotes: 0

Views: 716

Answers (1)

Eric Betts
Eric Betts

Reputation: 471

Assuming this is node, I can see two major issues with your code as written:

  • You should not have spaces between the hex values in the first parameter of Buffer.from
  • You should provide a second parameter of "hex" to Buffer.from: Buffer.from('f200000343303303b2', 'hex');

Upvotes: 0

Related Questions