exsilium / xmodem.js

XMODEM implementation in JavaScript
BSD 2-Clause "Simplified" License
12 stars 6 forks source link

SerialPort doesn't function as a socket #5

Open pcprince opened 4 years ago

pcprince commented 4 years ago

I'm attempting to use xmodem to send data to a serial port. The API and code comments suggest this is possible. However if a SerialPort is given to the send function:

serialPort = new SerialPort(port, {baudRate: 9600}, false);
xmodem.send(port, buffer);

The following error occurs:

.\node_modules\xmodem.js\lib\index.js:221 Uncaught (in promise) TypeError: socket.on is not a function
    at Xmodem.send (.\node_modules\xmodem.js\lib\index.js:221)
    at ReadLineParser.<anonymous> (app.js:490)
    at ReadLineParser.emit (events.js:200)
    at addChunk (_stream_readable.js:294)
    at readableAddChunk (_stream_readable.js:271)
    at ReadLineParser.Readable.push (_stream_readable.js:210)
    at ReadLineParser.Transform.push (_stream_transform.js:150)
    at ReadLineParser._transform (.\node_modules\@serialport\parser-delimiter\delimiter.js:35)
    at ReadLineParser.Transform._read (_stream_transform.js:189)
    at ReadLineParser.Transform._write (_stream_transform.js:177)

Does this package not support SerialPort?

exsilium commented 4 years ago

Hi @pcprince ! Hope you are doing well. SerialPort has gone through many iterations of its API and most likely, xmodem.js is not compatible with the latest releases. Check out https://github.com/exsilium/pxbee-fwup.js project of mine for implementation example with xmodem.js and SerialPort 4.x - if you have the option to use that version of SP.

PS. Compatibility PRs are very welcome to xmodem.js stack! ;) Cheers! 🍻