.

     

MPI Application Template
template.c
 

motorIo1.c -- Configure Transceiver as input or output and toggle.
/* motorIo1.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.
 */

/*

:Configure Motor I/O bit as input or output and toggle.

This sample application configures a single I/O bit, on one motor,
 for input or output.

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 "sqNodeLib.h"

#include "apputil.h"

/* User Settings */
#define MOTOR_NUMBER    (0)
#define IO_CONFIG       (MPIMotorIoTypeOUTPUT)      /* INPUT or OUTPUT  */
#define IO_ID           (MPIMotorIoConfigIndex0)    /* Index to Motor I/O. */
#define INVERT_BIT      (FALSE)


/* 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,
                 MPIMotor           *motor,
                 long                motorNumber)
{
    long    returnValue;


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

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

    /* Obtain a motor handle */
    *motor =
        mpiMotorCreate(*control, motorNumber);
    msgCHECK(mpiMotorValidate(*motor));
}


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

    /* Delete motor handle */
    returnValue =
        mpiMotorDelete(*motor);
    msgCHECK(returnValue);

    *motor = MPIHandleVOID;

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

    *control = MPIHandleVOID;
}


/* Configure Motor I/O */
void configureMotorIo(MPIMotor              motor,
                      MPIMotorIoConfigIndex ioIndex,
                      MPIMotorIoType        type,
                      long                  invert)
{
    MPIMotorConfig  motorConfigXmp;
    long returnValue;

    /* Configure selected I/O bit */
    returnValue =
        mpiMotorConfigGet(motor,
                          NULL,
                          &motorConfigXmp);
    msgCHECK(returnValue);

    motorConfigXmp.Io[IO_ID].Type = IO_CONFIG;

    returnValue =
        mpiMotorConfigSet(motor,
                          NULL,
                          &motorConfigXmp);
    msgCHECK(returnValue);
}


int main(int     argc,
         char   *argv[])
{
    MPIControl              control;
    MPIControlType          controlType;
    MPIControlAddress       controlAddress;
    MPIMotor                motor;
    MPIMotorIoConfigIndex   ioIndex     = IO_ID;
    MPIMotorIoType          type        = IO_CONFIG;
    long                    motorNumber = 0;
    long                    invert      = INVERT_BIT;


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

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

    /* Configure Motor I/O */
    configureMotorIo(motor,
                     ioIndex,
                     type,
                     invert);

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

    return MPIMessageOK;
}


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