TOC PREV NEXT INDEX

LinuxCNC.org


Handbook - Working with iosh


Adding Extra Inputs and Outputs.

The PLC is possibly the weakest part of the EMC. Right now, there are two supplied "PLCs" that control the discrete I/O (estop, lube, coolant, spindle): bridgeportio and minimillio. minimillio just controls our NIST desktop minimill that doesn't have coolant or lube, so it's a stripped-down version of bridgeportio. bridgeportion is written in C++, not a very common PLC programming language. We did this since we have in-house tools for programming hierarchical control systems using C++, which we have used for many other projects, so it made sense for us.

For EMC users, it's not a very popular choice. Bridgeportio and minimillio are slightly customizable (without resorting to C++ programming) via the .ini file, by setting the location and polarity of input/output bits and some other parameters like delays for spindle brake engage/release. Adapting them for anything else, like an automatic tool changer, means coding in C++ or replacing them with something else.

Looking at the EMC I/O controller as a black box, there are three things it must do:

1. [TOP] Create NML buffers for commands to it from the EMC task controller and status from it to the EMC task controller. This is what connects it to the EMC.

2. [MIDDLE] Read NML commands that come in from the EMC task controller (e.g., coolant on, etc.), do what's requested, and write status back (done, executing, error, and values like coolant is on/off, etc.)

3. [BOTTOM] Talk to real-world I/O points.

As an alternative to the C++-based bridgeportio, we wrote a Tcl/Tk-based PLC. Here's what we did:

1. Extended the Tcl/Tk windowing shell "wish" with EMC-specific commands, creating the "IO shell" iosh. This was done similarly to how we built the EMC shell emcsh, used for building Tcl/Tk GUIs like tkemc.tcl. iosh creates NML buffers (requirement (1) above, the TOP), and adds Tcl words "inb" and "outb" for doing PC-bus byte I/O (requirement (3) above, the BOTTOM). iosh can be thought of as the PLC engine, that can be programmed in Tcl/Tk to implement any arbitrary PLC. It doesn't have any particular PLC logic program, for say the Bridgeport. You have to write this yourself, in Tcl/Tk, as you would write a ladder logic program for another PLC.

2. Wrote a Tcl/Tk script that does the actual PLC logic (requirement (2) above, the MIDDLE). This is tkio.tcl. It implements the Bridgeport I/O controller, just like bridgeportio. It's plug-compatible with bridgeportio: you can specify "tkio" instead of "bridgeportio" in the .ini file, e.g.,

[EMCIO]
EMCIO = tkio

I tried it out a while ago and it looked like it worked, but the "plug compatibility" might not be 100% due to bugs. I'll have to check it out on our machine.

Note that since we're extending wish to build iosh, we get some GUI stuff automatically. That is, in tkio.tcl, there's some script code for popping up a window with some red and green LEDs that show IO status. So, iosh lets you program both the PLC logic and the GUI appearance in the same script. So, unlike bridgeportio, which doesn't pop anything up, iosh pops up a blank canvas that your script can populate with whatever you program. If you choose to write just a straight PLC program, the canvas is just a little annoying blank square.

If you want to use a PC as a PLC without running the EMC, you can still use iosh and your own script. The NML buffers will be created and simply ignored, and you can write your PLC and accompanying GUI for any purpose whatsoever. Or, you can take iosh.cc, strip out all the NML stuff, and just leave the inb/outb commands there for your own stripped-down shell. Or, you can use wish out of the box, write two short C programs that create "inb" and "outb" (we did this), put the in /bin, and call these within wish. This shows how a Linux box can be converted into a PLC in about 10 minutes. Of course, you program in Tcl/Tk, not ladder logic. Now, I like Tcl/Tk and if I had to write a PLC with a gun to my head I'd use wish and the /bin/{inb,outb} programs real quick-like.


TOC PREV NEXT INDEX