2.6. Sending Commands

Accessing a Gamma program like the PID Emulator through a GUI like the Monitor or the DataHub Viewer is convenient, but what if that kind of accessibility hasn't been built in? There is another Cogent tool, gsend (and its functional equivalent, lsend) that can send commands directly to a running program.

For example, if you look at the source code for the PID Emulator in Section 5.5, “Complete program - emul.g”, near the top of the file you will see these lines:

/* Create a global variable for demonstrating gsend and lsend. */
demo_send = 1;             

Further down, at the end of the Plant Model section you will see:

newval = newval * demo_send;

The value of newval gets written to PV_001 in the datahub, and is shown by the PV scale in the Monitor. Using gsend or lsend you can send a new value for demo_send, and noticeably change the position of PV. Here's how.

  1. Start the Controller, then start the PID Emulator and the Monitor. Set the PID Loop: at the bottom of the Monitor to Good.
  2. Open a shell and give this command:
    [sh]$  gsend emul
    (Unless you are a Lisp user, we suggest using gsend instead of lsend because Gamma's C-like syntax is more familiar.) The system should display a prompt, like this:
    emul>
    At this prompt, you can send any Gamma command to the running emul.g program.
  3. Type the following command, and press Enter:
    emul> demo_send = 2;
    Notice how the PV scale is now higher than the MV scale. Try changing demo_send to different values, and see what results.
    Notice that if you switch the PID Emulator off and back on, demo_send's value gets reset to 1. Should a program stop running while you are connected to it, and you try to send a message, you will get reply like this:
    emul> demo_send = 1.5;
    emul is no longer reachable
    (disconnected)emul>
    Once the program has restarted, you will get a reply like this:
    emul> demo_send = 1.5;
    emul is no longer reachable
    <Reconnected>
    1.5
    emul>