0

I am trying to read from serial port that receives data from an Arduino nanodevice, I already have matlab implementation of it and it reads the correct data,

However, I am trying to migrate it to node js, and I am having following issue, The data that should be received as ']<N ÿÿ¢ ÿÿò½·½ÓïÏÜÔιõa' is actually getting received as ']<N�������������������P�k�z^�y| zz{zz|{|��s?f���>oC���B�'

The first frame above is how I am receiving it in matlab and therefore I am able to use it, in node js for some reason the whole frame is replaced by '?'. especially characters such as 'ÿ' are replaced by '?'. I am using the serial port module used a read line parser the snippet looks like,

  myPort.on("data", data => {
    console.log(data);
  });

This definitely not a baudrate issue as other data is received perfectly. it has something to do with the encoding.

  • can you set a specific encoding/charset before the sending of the data? – mik3fly-4steri5k Jul 16 '20 at 08:20
  • As you have noticed, is it treating the part of the binary data as a string? Is it all right to consider all as binary data and convert each byte to a hexadecimal character string, or to separate character/character string data and binary data and convert each separately before outputting to the log? – kunif Jul 16 '20 at 08:32
  • I think the encoding before sending the data should be fine, as it is received fine in Matlab, only problem is how node js is parsing it... – Rohit Rai Jul 16 '20 at 15:26
  • I am also not worried about the data being sent. For example, before doing the real processing, I suggest that you convert it to hexadecimal and check it in order to confirm that the data is correctly received on the node.js side. [How to display nodejs raw Buffer data as Hex string](https://stackoverflow.com/q/18879880/9014308) – kunif Jul 18 '20 at 15:56

1 Answers1

0

I was using the wrong parsers. The deadline parser was trying to read the bytes and converted the extended ascii characters into ?. Using byte parser fixed the issue.