Editing Python Smart Terminal
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 1: | Line 1: | ||
− | = | + | = Draft = |
+ | First beta release, with automatic mode still alpha, code at: [https://github.com/russ-hensel/python_smart_terminal GitHub] Or better yet email '''[[User:Russ_hensel]]''' | ||
+ | Unless I figure out an easier way to keep git hub up to date I will use some other repository. | ||
− | + | = What/Why = | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | = | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Almost all my Arduino and other microcontroller projects use serial communications for a least debugging. And in many cases I pair the Arduino with a Raspberry Pi for a very flexible system. A good serial monitor, or terminal program is useful in this sort of project. Because I wanted features not in most terminals and the ability to program it myself, I started one from scratch using Python. | Almost all my Arduino and other microcontroller projects use serial communications for a least debugging. And in many cases I pair the Arduino with a Raspberry Pi for a very flexible system. A good serial monitor, or terminal program is useful in this sort of project. Because I wanted features not in most terminals and the ability to program it myself, I started one from scratch using Python. | ||
− | The program is also designed to be a stand alone data logging, environmental monitoring program. In this case it will kick off and run without an operator. Data | + | The program is also designed to be a stand alone data logging, environmental monitoring program. In this case it will kick off and run without an operator. Data will be access over the web. I will largely leave a discussion of these features to another page, but probably about half the code is devoted to these features. |
− | Currently the terminal waits for a | + | Currently the terminal waits for a cr ( or lf i will check ) until it displays ( or make available for processing ) the received string. This make sense for my application, it help the processing. This may not work best for you, let me know. |
So what are the features? | So what are the features? | ||
* Free open source | * Free open source | ||
− | * Runs across OSs Linux ( inc | + | * Runs across OSs Linux ( inc Raspberry Pi ), Mac or Windows |
* Python | * Python | ||
− | |||
* Easily adjusted serial communications parameters | * Easily adjusted serial communications parameters | ||
* Multiple, preloaded with data entry fields. | * Multiple, preloaded with data entry fields. | ||
Line 110: | Line 21: | ||
* Copy all or part of receive area. | * Copy all or part of receive area. | ||
* Programmable | * Programmable | ||
− | + | * Database Interface | |
− | * Database Interface | ||
− | |||
* Easily Modified or Replaceable GUI | * Easily Modified or Replaceable GUI | ||
* Parameter file for wide range of modifications of program behavior. | * Parameter file for wide range of modifications of program behavior. | ||
Line 118: | Line 27: | ||
* Uses standard Python logging class. | * Uses standard Python logging class. | ||
* Includes some advanced data logging features in addition to database data logging. | * Includes some advanced data logging features in addition to database data logging. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
A much earlier version of this terminal was described in my instructable [[http://www.instructables.com/id/Python-Terminal-for-Cheap-Pi-Arduino-Connection/ Python Terminal for Cheap Pi Arduino Connection]] It may have some information that is useful, but the program has grown a lot since then. | A much earlier version of this terminal was described in my instructable [[http://www.instructables.com/id/Python-Terminal-for-Cheap-Pi-Arduino-Connection/ Python Terminal for Cheap Pi Arduino Connection]] It may have some information that is useful, but the program has grown a lot since then. | ||
= Installation = | = Installation = | ||
+ | |||
This program is intended for those who at least occasionally develop in Python. I expect that they already run some things in Python and will just add this as an additional project. There is no install program you just download the files, place where you keep your projects and run. A bit more later in this section. | This program is intended for those who at least occasionally develop in Python. I expect that they already run some things in Python and will just add this as an additional project. There is no install program you just download the files, place where you keep your projects and run. A bit more later in this section. | ||
− | |||
− | |||
− | |||
− | |||
Before you begin to install you should know a bit about the environment that I have used to build, test and run the terminal. If your environment differs too much you may have trouble getting it to run. | Before you begin to install you should know a bit about the environment that I have used to build, test and run the terminal. If your environment differs too much you may have trouble getting it to run. | ||
− | I run Python mostly using the install that comes with Anaconda Spyder and often use the IDE it installs. This is not necessary, it is just an nice install that downloads a lot of stuff that technical folks find useful. I have use conda | + | I run Python mostly using the install that comes with Anaconda Spyder and often use the IDE it installs. This is not necessary, it is just an nice install that downloads a lot of stuff that technical folks find useful. I have use conda an pip to add to this install and do not know offhand all that is in it. It is Python 2.7. You can look at the include statements to get some idea of what you might need to add. Or you can just keep running it and add the packages it complains about. |
− | |||
− | + | Download the files ( I have not decided just how they will be on git hub in at least one form ) Uncompress if they are compressed. The directory structure should looks like this | |
− | + | .... whatever --| | |
− | + | |-- rshlib | |
+ | | | ||
+ | |-- SmartTerminal | ||
+ | |||
+ | Actually the git hub version does not have rshlib so it should look like: | ||
.... whatever --| | .... whatever --| | ||
| | | | ||
− | |-- | + | |-- SmartTerminal |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Put them in your system making "....whatever" anything convenient for your Python. It should run ( at least to put up its GUI ) by running smart_terminal.py. Note that there may be a certain amount of left over, dead code, in the directory I am cleaning out bit by bit, someday it may be nice and neat. For now if you want to tinker look at the design info below first. | |
Run it until it stops complaining about dependencies ( in the console ), after that ( and perhaps even before ) the GUI should come up. You are installed. | Run it until it stops complaining about dependencies ( in the console ), after that ( and perhaps even before ) the GUI should come up. You are installed. | ||
+ | |||
I have run the program on both Windows 10 and Rasperian on a RPi. It should work in most OS's. Let me know about issues. | I have run the program on both Windows 10 and Rasperian on a RPi. It should work in most OS's. Let me know about issues. | ||
Line 182: | Line 78: | ||
== Command Line Arguments == | == Command Line Arguments == | ||
− | If you run with the command line parameters=paramaters_b then after the regular parameters file | + | If you run with the command line parameters=paramaters_b then after the regular parameters file run, the system looks for parameters_b.py and uses that to override values that you might want to tweak ( or completely redo. There are two examples in the directory follow the pattern in them and you should be fine ). |
This can be especially useful if you want to run two copies connected to different ports and possibly running in different modes. In this case it is also nice to change ( its in parameters ) the '''icon''' and '''color''' for each instance of the program. You can write or use the little bat file to start them ( although this leaves a dos console hanging around ) Command line arguments can also be placed in shortcuts. In either case they may take some tweaking to run in/from your file locations. | This can be especially useful if you want to run two copies connected to different ports and possibly running in different modes. In this case it is also nice to change ( its in parameters ) the '''icon''' and '''color''' for each instance of the program. You can write or use the little bat file to start them ( although this leaves a dos console hanging around ) Command line arguments can also be placed in shortcuts. In either case they may take some tweaking to run in/from your file locations. | ||
Line 190: | Line 86: | ||
== Running It == | == Running It == | ||
− | When you run it it should open a windows a lot like the picture | + | When you run it it should open a windows a lot like the picture I will upload soon. Errors may show up in your Python console or the log file ( look in parameters.py for the name of the log file, typically self.pylogging_fn = "smart_terminal.py_log" ). The most likely errors will point to missing Python modules like pyserial. You should install with pip ( or conda if using Spyder ). Let me know how it goes. |
− | Normally the terminal does not open the com port | + | Normally the terminal does not open the com port untill you press the <Open> button. The parameters are displayed in the GUI if you do not like them ( say the port open status changes to open filed ) you can shutdown, edit parameters.py and restart. There is a simpler way. |
− | *First configure parameters.py to know the name of a text editor on your system | + | *First configure parameters.py to know the name of a text editor on your system ( for mine this is one of: self.ex_editor = r"leafpad" # linux and pi |
− | + | or self.ex_editor = r"D:\apps\Notepad++\notepad++.exe" for windows. It is set up to auto switch between the two os to make copying back and forth a bit easier. | |
− | |||
− | self.ex_editor = r"leafpad" # linux and pi | ||
− | |||
− | self.ex_editor = r"D:\apps\Notepad++\notepad++.exe" | ||
− | |||
− | |||
− | |||
− | It is set up to auto switch between the two os to make copying | ||
*Now when you run it the button <Edit Parms> should let you edit the parameters.py file. Edit it and save. | *Now when you run it the button <Edit Parms> should let you edit the parameters.py file. Edit it and save. | ||
Line 218: | Line 106: | ||
= Design = | = Design = | ||
− | + | 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. 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 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. | |
= Additional Info = | = Additional Info = | ||
− | + | *[[Smart Terminal as Smart Data Logger]] | |
− | |||
− | |||
− | |||
− | *[[Smart Terminal as Smart Data Logger]] | ||
*[[Smart Terminal GUI]] | *[[Smart Terminal GUI]] | ||
− | + | *[[Smart Terminal as Smart Data Logger]] | |
− | *[[Smart Terminal | ||
− | |||
*[ https://github.com/russ-hensel/python_smart_terminal python_smart_terminal at git hub] | *[ https://github.com/russ-hensel/python_smart_terminal python_smart_terminal at git hub] | ||
*[http://www.instructables.com/id/Python-Terminal-for-Cheap-Pi-Arduino-Connection/ Python-Terminal-for-Cheap-Pi-Arduino-Connection/] Info on much earlier version may or may not be useful. | *[http://www.instructables.com/id/Python-Terminal-for-Cheap-Pi-Arduino-Connection/ Python-Terminal-for-Cheap-Pi-Arduino-Connection/] Info on much earlier version may or may not be useful. | ||
− | [[ | + | [[category:Russ]] [[Category:Draft]] [[Category:Arduino/RaspberryPi]] |