next up previous contents
Next: New commands Up: Defining device commands Previous: Defining device commands

Standard commands

A minimum set of standard commands should exist for all devices. These are the commands -

Examples of these commands for the AGPowerSupplyClass are -

/*======================================================================
 Function:      static long dev_state()

 Description:   return state of simulated power supply.

 Arg(s) In:     AGPowerSupply ps - object on which to execute command.
                DevVoid *argin - void.

 Arg(s) Out:    DevShort *argout - state returned as short integer
                long *error - pointer to error code (in case routine fails)
 =======================================================================*/

static long dev_state (ps, argin, argout, error)
AGPowerSupply ps;
DevVoid *argin;
DevShort *argout;
long *error;
{

/* this command can be always executed independent of the state  */

      *argout = ps->devserver.state;

      return (DS_OK);
}

/*======================================================================
 Function:      static long dev_status()

 Description:   Return the state as an ASCII string. Interprets the error
                flag as well if the status is FAULT.

 Arg(s) In:     AGPowerSupply ps - object on which to execute command.
                DevVoid *argin - void.

 Arg(s) Out:    DevString *argout - status is returned as a string.
                long *error - pointer to error code (in the case of failure)
 =======================================================================*/

static long dev_status (ps, argin, argout, error)
AGPowerSupply ps;
DevVoid *argin;
DevString *argout;
long *error;
{
      static char mess[1024];
      int fault = ps->powersupply.fault_val;
      long p_state;


      p_state = ps->devserver.state;

      switch (p_state) {

      case (DEVOFF) : sprintf(mess,"%s","Off");
                      break;

      case (DEVON) : sprintf(mess,"%s","On");
                     break;

      case (DEVLOCAL) : sprintf(mess,"%s","Local");
                        break;

      case (DEVFAULT) : sprintf(mess,"%s","Fault\n");
                        break;

      default : sprintf(mess,"%s","Unknown");
                break;
      }

/* translate fault into a string */

      if ((fault != 0) && (p_state == DEVFAULT))
      {
      if ((fault & AG_OVERTEMP) != 0) 
      {
        sprintf(mess+strlen(mess)," %s","Overtemp");
      }
      if ((fault & AG_NO_WATER) != 0)
      {
         sprintf(mess+strlen(mess)," %s","No Cooling");
      }
      if ((fault & AG_CROWBAR) != 0)
      {
         sprintf(mess+strlen(mess)," %s","Crowbar");
      }
      if ((fault & AG_RIPPLE) != 0)
      {
         sprintf(mess+strlen(mess)," %s","Ripple");
      }
      if ((fault & AG_MAINS) != 0)
      {
         sprintf(mess+strlen(mess)," %s","Mains");
      }
      if ((fault & AG_LOAD) != 0)
      {
         sprintf(mess+strlen(mess)," %s","Load");
      }
      if ((fault & AG_TRANSFORMER) != 0)
      {
         sprintf(mess+strlen(mess)," %s","Transformer");
      }
      if ((fault & AG_THYRISTOR) != 0)
      {
         sprintf(mess+strlen(mess)," %s","Thyristor");
      }
      }

      *argout = mess;

      return(DS_OK);
}

Standard commands ensure uniform behaviour of all devices and allow standard utilities to be used for interrogating and displaying device status to be developed. Subsets of standard commands exist for devices belonging to the same superclass. For example all powersupplies should implement the same minimum set of commands. The reader is referred to the Device Server Notes for a description of the major superclasses.



Andy Goetz
Tue Jan 28 13:58:13 MET 1997