Smart Terminal Parameter Examples

From OpenCircuits
(Difference between revisions)
Jump to: navigation, search
(What/Why the Parameter File)
Line 10: Line 10:
 
Finally I make a call to a subroutine like:  well_monitor_mode().  This is the file for an arduino project that monitors my water well pressure.  This is a pretty complicated set up, because of the database access in the well monitor.  For this documentation I will do a subroutine called tutorial_example_mode() which make the most basic changes from the default mode.
 
Finally I make a call to a subroutine like:  well_monitor_mode().  This is the file for an arduino project that monitors my water well pressure.  This is a pretty complicated set up, because of the database access in the well monitor.  For this documentation I will do a subroutine called tutorial_example_mode() which make the most basic changes from the default mode.
  
 +
= tutorial_example_mode() =
 +
 +
<pre>
 +
 +
 +
 +
    def tutorial_example_mode( self, ):
 +
        """
 +
        this mode does not do anything usefull except illustrate a simple "mode subroutine"
 +
        """
 +
        self.mode              = "TutorialExample"  # this name will appear in the title of the window
 +
                                                    # to help keep track of which mode you are using
 +
 +
        self.baudrate          = 19200              # changes the baucrate from the default to 19200
 +
 +
        # the send_ctrls is a list of 3 valued tuples
 +
        # for each item in the list you will have a "send button", a button that will send the contents of
 +
        # the data entry field to the right of it to your comm port.
 +
        # the first item of the tuple is a sting whose test will be on the button
 +
        # the second is a string with the initial or default value for the data entry field
 +
        # the third is a boolean, True make the data entry field editable, otherwise it is protected from edit
 +
        self.send_ctrls = [
 +
                # text                      cmd      can edit
 +
                ( "Send",                    "",              True ),
 +
                ( "Send",                    "",              True ),
 +
                ( "Different Title",        "default",      True ),
 +
                ( "More Different",          "yes different", True ),
 +
                ]
 +
        # you may get extra buttons with default values to fill the space
 +
 +
</pre>
  
 
= Obsolete Doc, Remove soon  =
 
= Obsolete Doc, Remove soon  =

Revision as of 07:34, 8 November 2017

Contents

What/Why the Parameter File

A lot of the behaviour of the terminal is controlled by the file parameters.py. Different projects of mine require different parameters. There are several way to achieve this. The simplest to understand might be to have a different files for each project. You can do this if you want, starting from my parameter file. You can also use a secondary parameter file that overrides the settings in the first file. But right now I am working with a somewhat different method that seems easier to manage. This is the method in the supplied parameter file and the one that I will explain here. The parameter file is heavily commented and these comments should be read if you have questions. You can also search other files for parameters.xxx where xxx is the name of the parameter you are investigating.

In the __init__ method after a couple of required lines that help hold the application there is a call to self.default_terminal_mode(). This subroutine sets a ton of parameters and this is enough to make the terminal run nicely. See the comments in the subroutine for more info.

I then have a call to a short ( so far ) subroutine self.computer_name_tweaks( ) This subroutine uses the already set parameter computername to tweak a few settings depending on the computer's name. this makes it easy for me to change the default parameters setting based on the computer I am using to run the program. Thus I can move the program around without changing the parameter file.

Finally I make a call to a subroutine like: well_monitor_mode(). This is the file for an arduino project that monitors my water well pressure. This is a pretty complicated set up, because of the database access in the well monitor. For this documentation I will do a subroutine called tutorial_example_mode() which make the most basic changes from the default mode.

tutorial_example_mode()




    def tutorial_example_mode( self, ):
        """
        this mode does not do anything usefull except illustrate a simple "mode subroutine"
        """
        self.mode              = "TutorialExample"  # this name will appear in the title of the window
                                                    # to help keep track of which mode you are using

        self.baudrate          = 19200              # changes the baucrate from the default to 19200

        # the send_ctrls is a list of 3 valued tuples
        # for each item in the list you will have a "send button", a button that will send the contents of
        # the data entry field to the right of it to your comm port.
        # the first item of the tuple is a sting whose test will be on the button
        # the second is a string with the initial or default value for the data entry field 
        # the third is a boolean, True make the data entry field editable, otherwise it is protected from edit
        self.send_ctrls = [
                # text                      cmd       can edit
                ( "Send",                    "",              True ),
                ( "Send",                    "",              True ),
                ( "Different Title",         "default",       True ),
                ( "More Different",          "yes different", True ),
                ]
        # you may get extra buttons with default values to fill the space

Obsolete Doc, Remove soon

  • Sets part of the title of the application.
  • Sets the communications parameters. Sometimes a little confusing about port names. The arduino IDE sometimes is better at finding the name, check it. Also use the <Ports> button on the GUI. On the apple we have found from <Ports> ('/dev/tty.usbmodem1411', True) and in the parameter file using self.port = "/dev/tty.usbmodem1411" gave a good connection. Sometimes a reboot will result in a change of the port name.
  • Specifies a program for file editing.
  • Sets the size of the application.
  • Defaults data to be sent.
  • Change number of send areas.
  • More see the file.

An Intermediate Difficulty Parameter Example

  • This is based on the file ..../smart_terminal/example_parms/parameters_intermediate.py.
  • The parameters include all the basic parameters plus ones to support a greenhouse arduino monitor.
  • You should also look at the arduino application and the SmartTerminal extension to support it GreenHouse Monitor Program as they are closely related.
  • Well commented read the file!

What thisParameter File Does

  • Everything the basic file does plus the following.
  • The SmartTerminal needs some additional code to support the GreenHouse arduino program. The code is gh_csv_processing.GHCSVProcessing. To cause this to be loaded we have the following:
        ....
        elif self.mode == "GreenHouseCSV":
            # this is the module and class name of another class that will be built to support
            # automatic processing of a anduino monitoring a greenhouse
            # this also adds buttons to the gui
            self.ext_processing_module      = "gh_csv_processing"
            self.ext_processing_class       = "GHCSVProcessing"

In the code above we use the "meta" parameter self.mode to make it easy to switch on/off these settings ( by changing self.mode ).

  • The parameter file can be used to customize the send buttons, for the GreenHouse adaptation I use a more advanced version of these settings:
     self.send_ctrls        = [ ( "Version", "v", False ),  ( "Help", "h", False ), "simple default text" ]

In this case instead of just changing the default values of the string to be sent, I have also changed the button text and the editablity of the send field. This is done by using a tuple for any given button in the form ( string_button_text, string_send_default, editablity

  • The terminal can probe the communications ports, find a port that opens, send a string to the arduino, and look for a particular response to verify that it is connected to the desired port. This takes the following settings:
        self.get_arduino_version    = "v"              # sent out port to get arduino version
        self.arduino_version        = "GreenHouse"     # should be part of the string the arduino responds with match with the arduino code


  • Another setting is required for the probe of communications ports. Here it is ( set up for automatic switching between operating systems )

        # used to probe around for ports
        if  self.os_win:
            self.port_list  =  [ "COM11", "COM12", "COM13", "COM14", "COM15", "COM16", "COM17", ]
        else:
            self.port_list  =  [ "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2", "/dev/ttyACM0", "/dev/ttyACM1", "/dev/ttyACM2", ]

  • Data is saved to a csv file, but what is the file name. Here is its setting:
        # for saving csv data 
        self.csv_filename   = "csv_data.csv"

even more

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox