// serialEvent() is invoked in the context of the current (serial) thread
// which means that serialization and atomic variables need to be used to
// guarantee reliable operation (and better not draw() etc…)
// serialAvailable() does not provide any real benefits over using
// available() and read() inside draw - but this function has no
// thread-safety issues since it’s being invoked during pre in the context
// of the Processing applet
What does that mean?
I can use available() and read() inside draw instead of serialEvent() interchangeably in most cases.
Does this suggest that that is safer to do so and avoids thread-safety issues?
serialEvent() come from a thread, so one can be worry it is asynchronous and run in parallel to draw(), (eg writing to serial in draw() while some code read from serial at same time in serialEvent())
but as it is processed during pre (i guess pre-draw() ) we can’t mess with simultaneous access to serial port.
to me, it means you’re right you can use available() and read() inside draw instead of serialEvent() interchangeably
(witch is a little bit strange, we can imagine a low framerate sketch but listening as fast as possible )
edit:
not sure, i think this is true if you still check serialAvailable() in serialEvent()
@MazeArt Could you try changing serialEvent to (the undocumented) serialAvailable, and check if this works? (If it does, then this was indeed the issue, and you might want to then move all your code inside draw and make use of available(), instead of serialEvent).