1 # sterm - A Scriptable Terminal {#md_sterm}
3 * Author: Axel Wachtler
4 * Date: 2010/07 - 2015/03
8 While developping and debugging wireless applications, it is usefull to connect
9 two or more nodes via a serial interface with a PC in order to watch and analyze
10 the debugging output. The programm sterm.py is (yet another) terminal application
11 written in Python/TKinter, that provides this multiport feature.
15 In order to run `sterm.py` an installed version of http://www.python.org[Python]
16 (required is version 2.x but *not* 3.x) and the module `pyserial` is needed.
17 A short decription how to install and upgrade Python on your PC
19 http://uracoli.nongnu.org/gettingstarted.html#_installing_and_upgrading_python[Installing and Upgrading Python].
20 If you will use a transceiver board with an USB interface, of course the correct
21 USB driver must be loaded.
25 The program `wuart/sterm.py` is simply started by the command:
29 If the configuration file `sterm.cfg` is not found in the current directory,
30 a default version of this file is created and must be modified, to reflect your
33 With the command `python sterm.py -h` a list of available command line options
37 python sterm.py [OPTIONS]
41 show this help message
44 -c FILE, --config FILE
45 load config file, default value `sterm.cfg`
46 if FILE is not existing, an annotated version
47 is generated and the tool is exited.
49 ## Configuring sterm.py
53 The setup is configured with the file `sterm.cfg`. This file is written in
54 WIN.INI format and consists of the following sections.
57 The section name "CONFIG" is reserved for the global configuration of
60 A device section defines the serial port settings and
61 other configuration parameters. It can have a arbitary but
62 unique (within `sterm.cfg`) name.
64 A macros section defines either a text or a smart macro.
65 It can have a arbitary but unique (within `sterm.cfg`) name.
68 ### The `[sterm.py]` Section
70 The CONFIG section holds the global configuration information.
73 devices = .... list of enabled devices
74 plugins = .... list of files with smart macro functions
75 macros = .... macros enable globally for all devices
77 ### The `[Device]` Section
79 The example file `sterm.cfg` defines three devices:
80 coord, dev1, dev2, dev3. Each devices is described within a configuration
81 section, which has the following contents:
92 macros = mycommand_01 mycommand_02
95 The entries have the following meaning:
97 - type: currently only value "serial" is usefull.
98 - port: the name of the serial port, under Windows probably COMx
99 - baudrate: the serial baudrate to be used (in bit/s, e.g. 9600, 19200, 57600)
100 - logname: name of the generated logfile
101 - logmode: "a" for append to the file or "w" to write file from start
102 - log: a 1 means that writing to the logfile is enabled right at startup,
103 a 0 means that you need to click the "log" button to open the logfile.
104 - echo: 1 local terminal echo is enabled at startup
105 - connect: 1 means that the serial connection is opened at programm startup
106 - macros: list of macros for this device.
109 After defining a device, it needs to be listed in the "[CONFIG]" section in the
110 keyword "devices", e.g.
113 devices = coord dev1 dev2 dev3
116 ### The `[Macro]` Section
118 The program sterm.py provides two types of macros: a) normal text macros and b)
119 smart macros, which are implemented by python functions.
121 Here are two examples for a text macros:
124 text = The quick brown fox jumps over the lazy dog.
127 text = A wonderful bird is the pelican,
128 His bill will hold more than his belican,
129 He can take in his beak
130 Enough food for a week
131 But I'm damned if I see how the helican!
133 The "qbf" macro sends a single line to the serial device and the "peli" macro
134 sends multiple lines to the serial device.
136 Smart macros are configured by the keywords "function" and "params".
137 The "function" keyword holds the name of a function that is defined in a
138 plugin file. The "params" keyword is a python expression that creates a
139 parameter dictionary the function is called with.
143 params = dict(nbdevices = 1, channel = 0, chanpg=5, test=3)
147 The macros are buried behind the button "Macros" as a drop down list. The
148 macro assignement can be global in the "[CONFIG]" section or local in the
149 "[mydevice]" device specification section.
151 Here are two assignment examples:
154 devices = coord dev1 dev2 dev3
161 macros = mycommand_01
163 The macro "qbf" is assigned globally to all defined devices, where the macro
164 "mycommand_01" is just assinged to the device "mydevice".
166 ### Using Smart Macros
168 #### Writing Smart Macros
170 Smart Macros are implemented by a python function. Here is an example:
172 ~~~~~~~~~~~~~~~~~~~~~~{.PY}
174 def mycommand(devices, nbdevices, test, channel, chanpg, pan = 1):
175 print "test=%d, channel=%d, chanpg=%d, test=%d, pan=%d" % \
176 (test, channel, chanpg, test, pan)
177 cmd = "%02d%02d%1d%02d" % (channel, chanpg, pan, test)
178 print "Run: %s" % cmd
179 devices['coord'].write("Sc%s" % cmd)
182 devices['dev1'].write("S1%s" % cmd)
185 devices['dev2'].write("S2%s" % cmd)
188 devices['dev3'].write("S3%s" % cmd)
189 ~~~~~~~~~~~~~~~~~~~~~~
191 The first parameter "devices" of the function `mycommand()` holds a dictionary of
192 all defined serial devices. By means of the device function "write" the smart
193 macro function can send data to all available devices. All other parameters
194 (e.g. nbdevices, test, channel, chanpg, pan = 1) are function specific and given
195 by the `params` keyword in the configuration file.
197 #### Loading Smart Macros
199 Smart macros are loaded in the "[sterm.py]" section of the config file just by
200 writing the file name (with a path component) behind the keywords "plugins".