.

     

MPI Application Template
template.c
 

EventReport.c -- Enable controller event reporting
/* EventReport.c */

/* Copyright(c) 1991-2006 by Motion Engineering, Inc.  All rights reserved.
 *
 * This software  contains proprietary and  confidential information  of
 * Motion Engineering Inc., and its suppliers.  Except as may be set forth
 * in the license agreement under which  this software is supplied, use,
 * disclosure, or  reproduction is prohibited without the prior express
 * written consent of Motion Engineering, Inc.
 */

/*

:Enable controller event reporting

Enables event reporting for all enabled objects on a controller except for
 program sequencers.  Creating a program sequencer requires allocating
 controller memory for its program, so it's not possible to create (and thus
 not possible to configure) a program sequencer without interfering with other
 applications.  This is ok though, because if a program sequencer uses events,
 it should be already configured to report them.

Warning!  This is a sample program to assist in the integration of an
 MEI motion controller with your application.  It may not contain all
 of the logic and safety features that your application requires.

The msgCHECK(...) macros used in the following sample code are intended
 to convey our strong belief that ALL error return codes should be checked.
 Actual application code should use specific error handling techniques (other
 than msgCHECKs) best suited to your internal error recovery methods.

*/

#include <stdlib.h>
#include <stdio.h>

#include "stdmpi.h"
#include "stdmei.h"

#include "apputil.h"

/* Perform basic command line parsing. (-control -server -port -trace) */
void basicParsing(int                    argc,
                  char                  *argv[],
                  MPIControlType        *controlType,
                  MPIControlAddress     *controlAddress)
{
    long argIndex;

    /* Parse command line for Control type and address */
    argIndex = argControl(argc, argv, controlType, controlAddress);

    /* Check for unknown/invalid command line arguments */
    if (argIndex < argc) {
        fprintf(stderr,"usage: %s %s\n", argv[0], ArgUSAGE);
        exit(MPIMessageARG_INVALID);
    }
}


/* Create and initialize MPI objects */
void programInit(MPIControl         *control,
                 MPIControlType      controlType,
                 MPIControlAddress  *controlAddress)
{
    long    returnValue;


    /* Obtain a control handle */
    *control =
        mpiControlCreate(controlType, controlAddress);
    msgCHECK(mpiControlValidate(*control));

    /* Initialize the controller */
    returnValue =
        mpiControlInit(*control);
    msgCHECK(returnValue);
}


/* Perform certain cleanup actions and delete MPI objects */
void programCleanup(MPIControl *control)
{
    long    returnValue;

    /* Delete control handle */
    returnValue =
        mpiControlDelete(*control);
    msgCHECK(returnValue);

    *control = MPIHandleVOID;
}


/* Enable Events */
void enableEventReporting(MPIControl control)
{
    MPIControlConfig    controlConfig;
    MPIMotion           motion;
    MPIAxis             axis;
    MPIMotor            motor;
    MPIRecorder         recorder;
    MPIEventMask        eventMask;

    long    index;
    long    returnValue;


    mpiEventMaskCLEAR(eventMask);
    mpiEventMaskALL(eventMask);
    mpiEventMaskALL(eventMask);

    returnValue =
        mpiControlConfigGet(control,
                            &controlConfig,
                            NULL);
    msgCHECK(returnValue);

    for (index = 0; index < controlConfig.motionCount; ++index)
    {
        motion =
            mpiMotionCreate(control,
                            index,
                            MPIHandleVOID);
        msgCHECK(mpiMotionValidate(motion));

        returnValue =
            mpiMotionEventNotifySet(motion,
                                    eventMask,
                                    NULL);
        msgCHECK(returnValue);

        returnValue =
            mpiMotionDelete(motion);
        msgCHECK(returnValue);
    }

    for (index = 0; index < controlConfig.axisCount; ++index)
    {
        axis =
            mpiAxisCreate(control,
                            index);
        msgCHECK(mpiAxisValidate(axis));

        returnValue =
            mpiAxisEventNotifySet(axis,
                                  eventMask,
                                  NULL);
        msgCHECK(returnValue);

        returnValue =
            mpiAxisDelete(axis);
        msgCHECK(returnValue);
    }

    for (index = 0; index < controlConfig.motorCount; ++index)
    {
        motor =
            mpiMotorCreate(control,
                            index);
        msgCHECK(mpiMotorValidate(motor));

        returnValue =
            mpiMotorEventNotifySet(motor,
                                   eventMask,
                                   NULL);
        msgCHECK(returnValue);

        returnValue =
            mpiMotorDelete(motor);
        msgCHECK(returnValue);
    }

    recorder =
        mpiRecorderCreate(control,
                    -1);   /* next available recorder number */
    msgCHECK(mpiRecorderValidate(recorder));

    returnValue =
        mpiRecorderEventNotifySet(recorder,
                                  eventMask,
                                  NULL);
    msgCHECK(returnValue);

    returnValue =
        mpiRecorderDelete(recorder);
    msgCHECK(returnValue);
}


int main(int     argc,
         char   *argv[])
{
    MPIControl          control;
    MPIControlType      controlType;
    MPIControlAddress   controlAddress;


    /* Perform basic command line parsing. (-control -server -port -trace) */
    basicParsing(argc,
                 argv,
                 &controlType,
                 &controlAddress);

    /* Create and initialize MPI objects */
    programInit(&control,
                controlType,
                &controlAddress);

    /* Enable Events */
    enableEventReporting(control);

    /* Perform certain cleanup actions and delete MPI objects */
    programCleanup(&control);

    return MPIMessageOK;
}


      
       Legal Notice  |  Tech Email  |  Feedback
      
Copyright ©
2001-2009 Motion Engineering