Support » Controlling devices with the serial port and writing graphical interfaces »
5. Adding a GUI with Tcl/Tk
<p><a href="http://www.tcl.tk/">Tcl/Tk</a> is the most convenient way to
create GUIs that will work on both Windows and Linux. Even if you
only use one system, you will benefit from the fact that Tcl/Tk is
quite easy to learn and used by a lot of people. The particular mix
of Tcl/Tk and C that we recommend here was the best solution we found;
if you know of other ways to do it, <a href="/contact">let us know</a>!</p>
<p>Now, take a look at <code>ssc-tester.tcl</code>. This program is very
simple: it contains a loop that runs 16 times to create sixteen
sliders, one for each of the servos that can be controlled by the
servo controller. The critical command is</p>
<pre>
 scale .servo$i.scale -width 20 -length 200 -orient vertical
 -from 500 -to 5500 -command "stepTo 0 $i " -showvalue 0</pre>
<p>This creates a slider with values from 500 to 5500, so that whenever
you adjust the slider, the command</p>
<pre>
stepTo 0 slider position</pre>
<p>will be run, with <em>slider</em> and <em>position</em> replaced by
the slider number and position. This command is defined in <code>ssctester.c</code> by the line</p>
<pre>
 Tcl_CreateObjCommand(interp, "stepTo", &stepToProc, NULL, NULL);</pre>
<p>The arguments are interpreted by the C function
<code>stepToProc</code> and passed on to <code>stepTo</code> in
<code>ssc.c</code>, where they are translated into commands to be sent
to the serial port. When modifying the program for your own purposes,
you will need to find the documentation for both commands in the
Tcl/Tk language and special C functions used for interacting with
Tcl. <a href="http://www.tcl.tk/man/tcl8.5/">The Tcl/Tk manual</a> will probably be your most useful reference.
<br><br></p>