Editing GreenHouse Monitor Program

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 121: Line 121:
 
*process_temp_line()    takes a string ( one line ) of temperature and parses out the numbers on it ( as floats ) for saving to the csv file
 
*process_temp_line()    takes a string ( one line ) of temperature and parses out the numbers on it ( as floats ) for saving to the csv file
 
*process_humid_line()    like process_temp_line() but for humidity
 
*process_humid_line()    like process_temp_line() but for humidity
 
 
== Deeper Dive into find_and_monitor_arduino( ) ==
 
 
The functions in the GUI thread, including this one, are responsible for the receive function of the terminal when they are active.  They also need to see if the GUI needs to interrupt them.  To do this they will often poll the com port and check the queue_to_helper.  Now most of the time they are more or less sleeping waiting for the next time to acquire data.  They should not use time.sleep() as that will stop their polling.  Instead they call: check_queue_for( a_time ) in the HelperThread instance which acts like sleep() + the required polling.  All the functions called here should call this method often to keep the receive and interrupt alive.  ( there is a method for the helper to pass the receive processing back to the GUI thread, see the code for the details )  Other than this pooling the coding here is pretty straight forward.
 
 
* to find the arduino there is a method in the HelperThread instance that takes care of it, a couple of parameters control the details.
 
* set_time() is called to record the time of data acquisition
 
* the string requesting data acquisition is sent to the arduino
 
* the string requesting the temperature data is sent to the arduino, the received string is parsed by process_temp_line()
 
* the same process is repeated for the humidity.
 
* a function is called in the HelperThread instance to save the data to the csv file ( controlled in part by the parameters ).
 
* the function sleeps until it is time to repeat the cycle.
 
 
== Interrupt and Error Management in the Helper Thread ==
 
 
This is proving to be one of the more difficult aspects of the program, an I am still working on it.  I have however decided upon an approach which seems promising.  The plan, and what is implemented so far is to use various exceptions ( or exceptions with instance variables ) to unwind the code back to some recovery point.
 
 
The code for interrupting the helper thread is currently working as intended.  When the queue_to_helper is detected as being non empty during a helper function ( except the main polling one ) an exception is thrown which is caught back in HelperThread.polling.  ( interrupt is not used in the sense of suspending then returning to an activity, the function that is interrupted is over )
 
 
 
 
 
 
 
 
 
 
 
  
  

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)