Difference between revisions of "Python Smart Terminal Technical"

From OpenCircuits
Jump to navigation Jump to search
(Created page with "Python Smart Terminal Technical These notes are here so you can more easily modify the code. Contact me Russ Hensel if you need additional help. Before modifying the co...")
 
Line 1: Line 1:
 
[[Python Smart Terminal Technical]]
 
[[Python Smart Terminal Technical]]
 +
 +
= Overview =
  
 
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 15: Line 17:
 
Two other important components are called Logger ( in logger.py ) and Parameters ( in parameters.py ). The controller creates one of each, and make them available to the other components. The other components can interact with them, and uses them respectively for logging events, and getting access to parameters ( those aspects of the application that are particularly easy to change ).
 
Two other important components are called Logger ( in logger.py ) and Parameters ( in parameters.py ). The controller creates one of each, and make them available to the other components. The other components can interact with them, and uses them respectively for logging events, and getting access to parameters ( those aspects of the application that are particularly easy to change ).
  
The application is pretty much single threaded running in a Tkinter mainloop.  To make it responsive to both the GUI and its processing it uses a psedo event loop or a polling subroutine that is implemented in SmartTerminal.polling().  This is where data is received from there comm port. The frequency which it is called is set in parameters, the relatively low rate of 100 ms between calls ( .1 sec ) seems to give a perfectly responsive application in most cases.  I have run it as fast as once every 10 ms.  Have not tried to find a limit.
+
The application is pretty much single threaded running in a Tkinter mainloop.  There is also a second thread called a helper running which makes some processing much easier.  To make it responsive to both the GUI and its processing it uses a psedo event loop or a polling subroutine that is implemented in SmartTerminal.polling().  This is where data is received from there comm port. The frequency which it is called is set in parameters, the relatively low rate of 100 ms between calls ( .1 sec ) seems to give a perfectly responsive application in most cases.  I have run it as fast as once every 10 ms.  Have not tried to find a limit.
 +
 
 +
= The Controller SmartTerminal= 
 +
 
 +
SmartTerminal ( in smart_terminal.py )
 +
 
 +
= Parameters = 
 +
 
 +
Parameters ( in parameters.py )
 +
 
 +
= Processing = 
 +
 
 +
MotorProcessing( in xx_processing.py )
 +
 
 +
 
 +
= HelperThread = 
 +
 
  
The big pending development is to make the terminal interact with an Arduino to collect and log data.  This code is in place in a pre alpha stage.  I can get it to work for me, but it is still not ready for even non prime time.  I will write a document on how to use this code for those who may want to plan around with it.
+
HelperThread in smart_terminal_helper.py

Revision as of 12:02, 28 January 2017

Python Smart Terminal Technical

Overview

These notes are here so you can more easily modify the code. Contact me Russ Hensel if you need additional help.

Before modifying the code it is best to understand how it works. Here is an overview of the general plan, details can be filled out by reading the code.

The architecture is called the model view controller or MVC. The class SmartTerminal ( in smart_terminal.py ) could be viewed as the main class. To run the program run its file ( see code at end of file) SmartTerminal is the controller in MVC it is responsible for all overall control, it directly or indirectly creates all other program objects.

The view component is called GUI ( in gui.py ). It creates all the visible components, and relays user input to the controller.

The model component is the component that actually does the communication it is called RS232Driver ( in rs232driver.py ) and like the GUI is controlled by the controller.

The GUI is not allowed to directly communicate with the model and vise versa. Thus you can unplug them from the application and plug in new components. Don't like the GUI? You could modify mine, or you could make a modification and choose which one to use. This is sort of like a skin for an application. You can even set up to run with no GUI at all. The RS232Driver like the GUI easy to remove and replace in the program, its use has been parameterized in to the Parameter object, so to use SPI instead of RS232 all we have to do is write an SPI object and change the values in Parameter.

Two other important components are called Logger ( in logger.py ) and Parameters ( in parameters.py ). The controller creates one of each, and make them available to the other components. The other components can interact with them, and uses them respectively for logging events, and getting access to parameters ( those aspects of the application that are particularly easy to change ).

The application is pretty much single threaded running in a Tkinter mainloop. There is also a second thread called a helper running which makes some processing much easier. To make it responsive to both the GUI and its processing it uses a psedo event loop or a polling subroutine that is implemented in SmartTerminal.polling(). This is where data is received from there comm port. The frequency which it is called is set in parameters, the relatively low rate of 100 ms between calls ( .1 sec ) seems to give a perfectly responsive application in most cases. I have run it as fast as once every 10 ms. Have not tried to find a limit.

The Controller SmartTerminal

SmartTerminal ( in smart_terminal.py )

Parameters

Parameters ( in parameters.py )

Processing

MotorProcessing( in xx_processing.py )


HelperThread

HelperThread in smart_terminal_helper.py