Smart Terminal Parameter Examples

From OpenCircuits
Jump to navigation Jump to search

What/Why the Parameter File

A lot of the behavior of the terminal is controlled by the file parameters.py. My own files have grown to be quite complicated with modifications to match many different arduino projects, and to automatically adjust to different hardware and software environments.

Because of this complexity I am providing a set of parameter files that you can use more easily as a basis for your own. These are in a subdirectory example_parms. To use copy one over into the smart_terminal directory and rename to parameters.py. I will start by explaining the file parameters_basic.py, and later explain more powerful and complex files.

The details of each parameter are commented in the parameter files, and you may also find it helpful to search the other SmartTerminal files to find their use. If at any point you find it useful to add parameters that is ok as long as you do not use a name already in use.

A final twist in the use of the parameter file is that you can have a "second" parameter file that is run after the first. This is specified in the command line in the form: parameters=parameters_a where parameters_a.py is another specifications of parameters. This second file need not include all values, just changes after the main file runs. It is particularly useful when running 2 instances of smart terminal and you may want different communications parameter and perhaps id color. If used its use is noted in the title for the terminal.

Basic Parameter Example

  • This is based on the file ..../smart_terminal/example_parms/parameters_basic.py.
  • The parameters are all that are needed for a basic terminal application, nothing fancy but all the basics, and much more than the arduino serial monitor.
  • Well commented read the file!

What this Parameter File Does

  • Sets part of the title of the application.
  • Sets the communications parameters.
  • 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