VMS Help  —  MRD Library, mrd_request_sense, Example
    /*
     *   This is an example of using mrd_request_sense(3mrd)
     *   to see what state a medium changer is in.  The MRD
     *   implementation of Request Sense only collects the
     *   Sense Key, Additional Sense Code and Additional Sense
     *   Code Qualifier.
     *
     *   Usage:
     *
     *      mrd_request_sense robot [ more-robots... ]
     */
    #ifndef   lint
    static  char  SccsId[] = "@(#)mrd_request_sense.c   1.1 4/16/97" ;
    #endif

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <errno.h>
    #include <mrd_common.h>
    #include <mrd_message.h>

    char   *device_sense = "Sense data for %s: %s (%d,0x%x,0x%x).\n" ;
    char   *sense_failed = "Request Sense failed on %s: %s.\n" ;

    main(int argc, char *argv[])
    {
       int      rc ;      /* counter */
       int      status ;   /* return status */
       char      *robot ;   /* Robot to open */
       robot_info_t   robot_info ;   /* Robot data */
       dev_status_t   dev_status ;   /* Device status */
       char      log_info[MRD_MAX_LOG_STRING+1] ;

       /*
        *   Check that there are enough arguments.
        */
       if( argc < 2 ) {
          printf("usage: %s robot [ robot... ]\n", argv[0]) ;
          exit(1) ;
       }

       /*
        *   Initialize the channel field of the robot_info, so
        *   mrd_startup(3mrd) will actually open the robot.
        */
       robot_info.channel = BAD_CHANNEL ;

       for(rc = 1; rc < argc; rc++) {
          /*
           *   The robot for this command.
           */
          robot = argv[rc] ;

          status = mrd_startup(robot, &robot_info, log_info) ;

          if( status != MRD_STATUS_SUCCESS ) {
             printf("Startup failed on %s: %s.\n", robot,
                mrd_strstatus(status)) ;

             continue ;
          }

          memset((void *)&dev_status, 0, sizeof(dev_status)) ;

          /*
           *   mrd_request_sense(3mrd) will never return
           *   MRD_STATUS_SUCCESS.  If no Request Sense data
           *   is available, it will return MRD_STATUS_NO_SENSE.
           */
          status = mrd_request_sense(&robot_info, &dev_status,
                MRD_CHECK_SENSE) ;

          /*
           *   Print the Key/ASC/ASCQ data for device errors.
           */
          if( dev_status.valid )
             printf(device_sense, robot, mrd_strstatus(status),
                dev_status.key, dev_status.asc,
                dev_status.ascq) ;
          /*
           *   Just print the MRD error.
           */
          else
             printf(sense_failed, robot, mrd_strstatus(status)) ;

          (void)mrd_shutdown(&robot_info) ;
       }

       return 0 ;
    }
Close Help