Shop OBEX P1 Docs P2 Docs Learn Events
Trouble with node js serialport.parser and PST... — Parallax Forums

Trouble with node js serialport.parser and PST...

I'm having some trouble with node js serialport.parser

I have a dead simple program (HelloPST basically) running on my prop dev board just spitting out "This is a test message!" over and over...
''This code example is from Propeller Education Kit Labs: Fundamentals, v1.2.
''A .pdf copy of the book is available from www.parallax.com, and also through
''the Propeller Tool software's Help menu (v1.2.6 or newer).
''
''HelloPST.spin
''Test message to Parallax Serial Terminal.

CON
   
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
   
OBJ
   
  pst : "Parallax Serial Terminal"
  ''pst : "FullDuplexSerial"
   
PUB TestMessages

  ''Send test messages to Parallax Serial Terminal.
 
  ''pst.Start(115_200)
  pst.Start(9600)
  ''pst.Start(31, 30, 0, 115_200)

  repeat
    pst.Str(string("This is a test message! \n"))
    Pst.NewLine
    waitcnt(clkfreq + cnt)

I tried using FullDuplexSerial since PST says in the comments it's "for the parallax serial terminal" (didn't help)...

I tried slowing down the data rate just because...

on the server, the port opens successfully, and if I register a 'data' event with the port I get:

port open.
port data:
port data: T
port data: his
port data: is
port data: a
port data:
port data: te
port data: st
port data:
port data: m
port data: e
port data: s
port data: s
port data: a
port data: g
port data: e
port data: !
port data:

but the parser's 'data' event never fires (should with new line; tried adding '\n' to message just in case, but no effect)...

server code for serial port stuff:
  var serialPort = require('serialport');
  var serOptions = {
    baudRate: 9600,
    databits: 8,
    stopbits: 1,
    parity: 'none',
    buffersize: 256,
    encoding: 'utf8'
  };

  const readLine = serialPort.parsers.Readline;
  const port = new serialPort('/dev/ttyUSB0', serOptions);
  const parser = port.pipe(new readLine({delimiter: '\r\n'}));
  parser.on('data', function(data){console.log('parser data: ' + data.toString('utf8'));});
  //port.on('data', function(data){console.log('port data: ' + data.toString('utf8'));});
  port.on('open', ShowPortOpen);
  port.on('error', ShowError);

based on Heater's post/thread from 2013
http://forums.parallax.com/discussion/147253/node-js-and-the-propeller

and the node serialport documentation
https://github.com/node-serialport/node-serialport/blob/v6.0.4/README.md

my node js version is v6.11.3

I'm afraid I don't know what to try next... I would appreciate any suggestions...

Comments

  • rosco_pcrosco_pc Posts: 464
    edited 2017-11-17 22:28
    Adding '\n' to a string just transmits as '\' 'n'. Instead use
    pst.Str(string("This is a test message!",10))

    Edit: \n = 10, \r=13
  • I probably should have realized that. Working now. Thanks.
Sign In or Register to comment.