serial.pipe #851
Replies: 9 comments
-
Posted at 2016-02-26 by DrAzzy Is there a reason you're using serial.pipe instead of using the serial.on("data",...) handler? That's what I've always used for serial interfacing... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-26 by countxerox No DrAzzy, no particular reason. I've already done version of the module using serial.on and serial.read, I'm learning JavaScript and just trying out the alternatives. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-26 by @gfwilliams The serial port doesn't really have any concept of when it is finished - so you won't get any 'end' or 'complete' event produced by it. Also, the chunk size used by To be honest in this case, using the I don't know anything about SBUS, but you might get a framing error if the serial line is brought low after each transmission. Maybe try:
If that's the case, you can use the serial data handler to store the data, and can then parse it all when you get the framing error from the serial port - it'd be a nice way of working without worrying about possibly being out of sync. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-26 by countxerox Good suggestion, thanks Gordon, I tried that and got this:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-26 by countxerox Here's my code using pipe:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-29 by @gfwilliams That's odd - getting that many framing errors points to something being wrong though. Your With that, you might find you get more sensible framing errors. Also, I'm not sure you want |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-29 by countxerox Yep, with parity:'e' all the framing errors are gone.
0x0F is the startbyte, the following 22 bytes are the payload, then the next byte is for flags which show if the receiver has dropped frames or if the signal has been lost and then the last byte is the endbyte 0x00. The framerate is about 7ms but it wibbles at bit so I can't think of anyway to sync using timing. The startbyte and endbyte could potentially appear in the payload so I'm watching for 0x00 followed by 0x0F to mark the start of a frame, then when the 25 bytes have been received I check the last byte is 0x00 for validation. Hers's my code using Serial.on('data'...
I seem to have bytes going missing sometimes when the callback's called |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-03-01 by @gfwilliams Depending on the datarate and what else you do when you get the decoded data it could be that the data can't be processed fast enough and the buffer overflows? Maybe check
Not tested, but might work - of course the way I've done it above you're always one frame behind. Also... which board are you using? different boards have different serial buffer sizes |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-03-07 by countxerox I wish I'd thought of that, I'm not seeing any E.getErrorFlags() but I'm getting better results with that method, thanks for the help. I'm using the pico board which seems to have a 512 byte buffer. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-26 by countxerox
Hi, I'm writing a module to interface with a radio control receiver, the receiver has a serial interface which is like the Futaba SBUS protocol.
I'm piping the serial data, which comes in frames of 25 bytes, to an object with a write method so I've set the chunksize option to 25 but when I console.log the data being written to the object I see randomly sized chucks of 2-8 bytes?
So the module is kind of working now but I want to make some further refinements, I tried using the 'end' and 'complete' options but nothing seems to happen, is it the 'end' of the chunk or something else? I've tried reducing the chunksize. What indicates when the pipe activity is complete or the when source has finished? Are the end/complete functions written like 'function end() {...}' or should they be functions of the object, how would I go about that?
Beta Was this translation helpful? Give feedback.
All reactions