The Python language was designed to be powerful yet have very clear syntax. It has modern features like modularity, OO, exceptions, dynamic data types, and dynamic typing. For more details, visit its homepage.
User interfaces can be easily built for python scripts using tools such as glade.
If you don't have the MatPLC shared library installed in the usual place
you'll also have to set the environment variable
LD_LIBRARY_PATH to point to the MatPLC
directory before starting python or the python script.
import matplc matplc.init("example") foo = matplc.point("foo") bar = matplc.point("bar") es_out = matplc.point("es_out") try: while 1: matplc.scan_beg() matplc.update() if foo.get(): bar.set(1) else: bar.set(0) matplc.update() matplc.scan_end() finally: es_out.set(1) matplc.update() matplc.done()
The first two and last two lines inside the loop are boiler-plate. Most programs will have them, since most programs will want a main loop. However, for instance GUI-oriented programs will not, and the interface supports that (ignore the scan_beg() and scan_end(), and just do an update() before reading points or after setting them).
The logic would presumably be more complicated than that, of course, but this is just a small example.
Note the use of the try/finally block - if there's any problem in the
main body of the program, this will ensure that the module sets the output
es_out (presumably connected to the ES circuit) before it
You can use the built-in
len(foo) function to get the
length of the point
foo in bits and
foo[0:3] to get subpoints that access particular bit(s) of the
foo.set(0), you can
Null points can be obtained using
Floating-point points (f32, as used by the DSP module) can be obtained using
$Date: 2004/12/28 05:32:11 $