Serial port query, response ? #821
Replies: 3 comments
-
Posted at 2015-11-06 by @gfwilliams Hi, Rather than polling, this is where you want to use callback functions... You can call a function that will handle your serial data when it is received, for example:
It'll be much more power efficient, since the board is only waking up when it has something to do. Generally you shouldn't ever really need a Hope that helps! In the code above, it'll ask for temperature every 1 second regardless of whether there was a response - but often this is a good idea. If the temperature sensor doesn't respond (or doesn't get the data) for whatever reason, you don't want the Espruino board to stay waiting for it! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-06 by @allObjects
I assume line 8 Furthermore, I wonder about the Breaking out of or loose from the (Arduino) loop thinking, you can also easily increase the functionality of your device: Put the same event driven approach to work for a 'watch-dog' that monitors the process of getting the temperature within a defined time, for example, 10 seconds. If no reading comes in fro what so ever reason, an alarm is reaised. Lines
PS: ...actually, it is NOT THAT wrong to think in a loop... when - for the implementation - including the waiting for the interrupt as the 'closing' part of the loop, like the clasps of a 'code' bracelet. Write the code as 'the nice part of the bracelet', and close it with the setup of an interrupt / watch as the 'clasps'. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-07 by Zacker Thank you for responses |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-11-06 by Zacker
Hi,
Espruino is connected to second board over Serial1 and it sends some querys to get information from second board. After the query sent, javascript code must go idle state for receive response process. if the js code waits in a while loop for response after query, the Serial1.on("data.. event never processing. Is there any way to get response after query on single function ? I used a code similar to state machine for a solution.
Some object oriented languages uses like "doEvents", "processMessages" statements for execution event codes in busy state. Any suggestion for single function ?
Thank you
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions