Editing Easy DB Technical

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 2: Line 2:
  
 
= Overview =
 
= Overview =
 
'''THIS IS NOT ABOUT THIS APPLICATION BUT A SIMILAR ONE, WILL BE CHANGED'''
 
  
 
These notes are here so you can more easily modify the code.  Contact me Russ Hensel if you need additional help.
 
These notes are here so you can more easily modify the code.  Contact me Russ Hensel if you need additional help.
Line 24: Line 22:
  
 
* Tkinter for the GUI
 
* Tkinter for the GUI
 +
* pySerial for serial communications
 
* pyLogging for logging
 
* pyLogging for logging
 +
* SmartTerminal a model-view-controller controller with some modifications  ( '''[https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model–view–controller - Wikipedia ]'''  or perhaps closer to '''[https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter Model–view–presenter - Wikipedia ]''' )
 +
* Second thread for processing without being blocked by/blocking the GUI
 
* Global Singleton for app cohesion.  
 
* Global Singleton for app cohesion.  
  
== The Controller: App ==  
+
== The Controller: SmartTerminal ==  
  
App ( in easy_db.py )
+
SmartTerminal ( in smart_terminal .py )
  
 
This is the class you create to run the application see the code at the bottom of the file, just run the file.  Similar code is at the bottom of some of the other source files to make it convenient to run from those files, this is just to make it easier in development, the code in smart_terminal is the model for what should be used.  Sometimes the code at the bottom of the file may have code for testing objects in the file, it may not be maintained, may not work as intended.
 
This is the class you create to run the application see the code at the bottom of the file, just run the file.  Similar code is at the bottom of some of the other source files to make it convenient to run from those files, this is just to make it easier in development, the code in smart_terminal is the model for what should be used.  Sometimes the code at the bottom of the file may have code for testing objects in the file, it may not be maintained, may not work as intended.
  
The App.__init__ method is the initialization and "run" method for the application.  Much of the code that would normally be in it has been moved to App.restart which is used to restart the application when just the parameters have been changed.  See the docstring there.
+
The SmartTerminal.__init__ method is the initialization and "run" method for the application.  Much of the code that would normally be in it has been moved to SmartTerminal.restart which is used to restart the application when just the parameters have been changed.  See the docstring there.
  
 
== Global Values ==
 
== Global Values ==
  
 
Yes I know that globals are bad, but they can be useful.  For example many class instances need to access the parameter file.  This can be done using the singleton class AppGlobal.
 
Yes I know that globals are bad, but they can be useful.  For example many class instances need to access the parameter file.  This can be done using the singleton class AppGlobal.
It has values at the class level ( not instance ) that are available simply by importing the class.  Many values are defaulted to None, and are set to valid values as the application initializes.
+
It has values at the class level ( not instance ) that are available simply by importing the class.  Most values are defaulted to None, and are set to valid values as the application initializes.
  
 
== Threads ==
 
== Threads ==
  
The application is currently in one thread, which seems like the right way for this sort of application
+
The application runs two threads, one for the GUI and one where processing can occur ( HelperThread ) with out locking up the GUI.  There are 2 queues that allow the threads to communicate.
  
 
=== The Tkinker Thread ===
 
=== The Tkinker Thread ===
  
Once Tkinker is started it runs its own mainloop.  
+
Once Tkinker is started it runs its own mainloop. In order to receive however we need to check the rs232 port from time to time.  This is done in SmartTerminal.polling()  I call this thread the GUI thread or gt.  The terminal is configured to have a second thread called the Helper Thread or ht.  In some cases the receiving of data is passed to the Helper Thread so where data is processed in addition to being posted to the GUI. See the section HelperThread for more info.
 +
 
 +
=== HelperThread ===
 +
 
 +
HelperThread in smart_terminal_helper.py  This class provides the support for a second thread of execution that does not block the main thread being run by Tinker.  I call the two threads the GUI Thread (gt) and the Helper Thread ( ht ).  It can get confusing keeping track of which method is running in which thread, I sometimes annotate them with gt and ht.  The helper thread is started by running HelperThread.run() which pretty much just runs a polling task in HelperThread.polling().  HelperThread.polling() is an infinite loop, it uses sleep to set the polling rate.  When used with the green house processing module, it may call a function there that is its own infinite loop.  There are a lot of details here, I should write some more about it.
  
 
 
== Parameters ==
 
== Parameters ==
  
Line 61: Line 65:
 
Values are often set to None as a default, then later set to some other value.  Or the value may be set several times in a row ( this is an artifact of messing with the values ); only the last value set has any meaning.
 
Values are often set to None as a default, then later set to some other value.  Or the value may be set several times in a row ( this is an artifact of messing with the values ); only the last value set has any meaning.
  
For a lot more info see:  [[EasyDB Parameter Examples]]
+
If asked for in the command line you can also envoke a second parameter file.  This is handy if you want two different instances of the terminal.
 +
 
 +
For a lot more info see:  [[Smart Terminal Parameter Examples]]
 +
 
 +
== Processing Modules==
 +
 
 +
So called processing modules offer you the opportunity to put some custom automatic processing in your terminal.  Typically this is matched up with a custom microcontroller application on the other end of the com port.  These are all implemented as descandants of the class ABCProcessing.  ( so far ABCProcessing does not add much value ) A couple of examples of processing modules and the arduino code are included in the download package, but beware they are in various states of maintenance.  See: [[Writing You Own Extensions to SmartTerminal]]
 +
 
 +
== Microcontroller and Its Protocol ==
 +
 
 +
All my microcontroller projects use a simple protocol where commands are sent from the terminal and microcontroller responds, all commands and responses are in human readable encoded strings.  If we take the greeenhouse monitor code here are some of the most important commands:
 +
 
 +
*  v<cr>        microcontroller responds with the name and version of its software
 +
*  a<cr>        microcontroller aquires data and responds "ok"
 +
*  t<cr>        microcontroller responds with the aquired temperatures ex: 88.2 56.9
 +
 
 +
See [[GreenHouse Monitor Program]]
 +
 
 +
 
 +
GHProcessing( in gh_processing.py )
  
 +
== Polling ==
 +
Both threads have method that perform polling for events, events like received text, or items in their queue that may have been sent from the other thread.  More info in [[Python Smart Terminal Technical Details]]
  
 
== Logging ==
 
== Logging ==
Line 117: Line 142:
 
= See Also =
 
= See Also =
  
 +
*[[Python Smart Terminal Technical Details]] More detailed technical issues.
 +
*[[Smart Terminal GUI]] how the gui works and interfaces the user.
 +
*[[Smart Terminal Convert from 2.7 to 3.6]] converting a moderate size application.
 
* and the categories below may be useful ( click on them ).
 
* and the categories below may be useful ( click on them ).
  
[[Category:Python Easy DB]] [[category:Python]]
+
[[Category:SmartTerminal]] [[Category:Arduino/RaspberryPi]][[category:Python]]

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)