Common: Controlling the Cascade TextLogger - send_command

Cogent Tools Demo and Tutorials: Version 4.0
Prev | Chapter 13. Log Functions | Next

# 13.8. Common: Controlling the Cascade TextLogger - `send_command`

| This function is located in the `lib/common.g` file.

This function sends commands to the Cascade TextLogger, locating it using the Gamma function `locate_task` and then sending commands using the Gamma `send` or `send_string` functions. We use the Gamma `switch` statement to allow us to choose between various options, testing for the `purpose` parameter. The Gamma function `close_task` closes the task to free up memory.

       /*--------------------------------------------------------------------
        * Function:    send_command
        * Returns:     t or nil
        * Description: Sends commands to the TextLogger.
        *------------------------------------------------------------------*/
       function send_command(widget, purpose, arg)
       {
         local tsk;
         if ((tsk = locate_task("tlog", nil)) != nil)
           {
             switch (purpose)
               {
               case "send-text":
                 send(tsk, `output(tldemoboth, @(widget.get_text())));
                 send(tsk, `output(tldemostdout, @(widget.get_text())));

The Cascade TextLogger can receive commands in either Gamma or Lisp syntax. The `"send-text"` case (above) uses Gamma syntax and the `send` function to send the output command. In Gamma syntax, the command looks like a Gamma function call, with its arguments in parentheses. (For more information on Gamma and Lisp syntax for sending commands, please refer to the Sending Commands section in the Cascade TextLogger manual.)

The `"send-cmd"` case (below) uses the `send_string` Gamma function. Since the commands for the Log program's Send Cmd text entry box are entered in Lisp syntax, it is easier to simply send them as strings. We could have just as well used Gamma syntax for those commands in the demo, and sent them using `send`, but we wanted to demonstrate Lisp syntax.

               case "send-cmd":
                 send_string(tsk, string(widget.get_text()));
               case "collect":
                         if (widget.switched_on())
                   {
                     send(tsk, `collect(@arg, tldemoboth));
                     send(tsk, `collect(@arg, tldemostdout));
                   }
               case "file-stdout":
                 if (widget.switched_on())
                   send(tsk, `enable(@arg));
                 else
                   send(tsk, `disable(@arg));
               }
             close_task(tsk);
           }
       }

Prev | Home | Next
Common: Starting and Stopping the Cascade TextLogger - `log_toggle` | Up | History Functions

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.