Serial events and threaded mode

With threaded mode now as default, can you comment on how Particle.process() works with serial events and projects that use both serial events and SerialLogHandler?

Serial events are dispatched between calls to loop() so they'll be in the normal application loop thread and will not cause thread safety issues even with threading enabled. Same for function and calculated variable handers.

If you are in threaded mode and call Particle.process() it does nothing if called from another thread, but if you call it from the application thread it will do the same thing as when using non-threaded mode.

There's little reason to ever use serial events. You're better off just reading the serial port from loop.

It's OK to read from serial and write to it using SerialLogHandler.

You should never use Serial.print, Serial.write, etc. and SerialLogHandler at the same time. They're not protected against mixing the output unpredictably, and in rare cases the device may crash with an SOS+1.

If you really need to include both log messages and custom output that's not log message you're better off creating a custom logging handler to replace SerialLogHandler that mixes the output more carefully. An example of this is in SerialCommandParserRK.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.