How does agent.on interact with other code?

I really enjoy the event driven aspect of the imp enviroment, however I’m not sure different event handlers interact with eachother. My imp is taking serial input from an arduino and relaying the information to a python script running on my computer. Then it will relay instructions from the python script to the arduino. Since this should all happen in the same order every time I don’t have a problem putting the imp in a loop checking for serial input after it relays instructions (see attached code). What would happen though if the imp was receiving serial input when the agent sent something? I assume that serial input that tries to come while other processing is happening is put into a buffer. Does this happen with agent input, or does it act like an interrupt? As I said, my agent won’t be sending info at the same time my imp is looking for serial, but supposing it did, how would it play out? Is there a better way for me to write this?

have a look at this example in the docs. You can have the arrival of serial data at the imp trigger a function. There is no need to stay looping on the imp or repeatedly check to see the data.

uart event

specifically, this line

arduino.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, arduinoData);

and this function reference, arduinoData

I really don’t know if there is a priority set on events versus code already running on the imp. Would you take a guess? I don’t think the event of a message from the agent will cause the imp Device to stop what it is doing. I think it will respond to that event when it has completed the present code. It is likely to read the serial port until there is no serial data in the buffer.

L-) Oops… Totally forgot there was an event handler built into uart.configure. Thanks for the help!

Serial is buffered in the OS, and event handlers cannot interrupt other event handlers, so stuff should always happen in the order you expect.

As I remember, hardware events (GPIO changes, RX data) take priority over agent messages, and both those are higher priority than wakeups. imp.onidle() is the lowest priority.