.

     

MPI Application Template
template.c
 

SQAlarm1.c -- Check for AMP faults and warnings on all SynqNet drives
/* SQAlarm1.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.
 */

/*

:Check for AMP faults and warnings on all SynqNet drives

This program demonstrates how to retrieve SynqNet amplifier faults 
and warnings from all motor objects on SynqNet nodes.

Not all SynqNet amplifiers support faults and warnings.  This code
catches the MEISynqNetMessageSRVC_UNSUPPORTED_FIRST thru LAST return
codes.

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 <string.h>

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

#include "sqNodeLib.h"

#include "apputil.h"

/* Parse the command line */
long parseCommandLine(int                 argc,
                      char               *argv[],
                      long               *synqNetNumber,
                      MPIControlType     *controlType,
                      MPIControlAddress  *controlAddress)
{
    long    argIndex;

    /* Command line arguments and defaults */
    Arg argList[] =
    {
        {   "-synqNet", ArgTypeLONG,    &synqNetNumber, },
        {   NULL,       ArgTypeINVALID, NULL,           }
    };


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

    /* Parse command line for application-specific arguments */
    while (argIndex < argc) {
        long    argIndexNew;

        argIndexNew = argSet(argList, argIndex, argc, argv);

        if (argIndexNew <= argIndex) {
            argIndex = argIndexNew;
            break;
        }
        else {
            argIndex = argIndexNew;
        }
    }

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

    return 0;
}


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


    /* Create motion controller object */
    *control =
        mpiControlCreate(controlType,
                         controlAddress);
    msgCHECK(mpiControlValidate(*control));

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

    /* Create SynqNet object */
    *synqNet =
        meiSynqNetCreate(*control,
                         synqNetNumber);
    msgCHECK(meiSynqNetValidate(*synqNet));
}


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

    returnValue =
        meiSynqNetDelete(*synqNet);
    msgCHECK(returnValue);

    *synqNet = MPIHandleVOID;

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

    *control = MPIHandleVOID;
}


/* Report Motor Faults */
void reportMotorFaults(MPIMotor         motor,
                       long             nodeNumber,
                       MEISqNodeInfo    sqNodeInfo)
{
    MEIMotorInfo        motorInfo;
    MEIMotorAmpFaults   faults;
    MEIMotorAmpWarnings warnings;
    long                returnValue;
    long                motorNumber;

    returnValue =
        mpiMotorNumber(motor, &motorNumber);
    msgCHECK(returnValue);

    printf("\n\n"
           "Node[%d] - %s, Motor %d\n"
           "========================================\n",
           nodeNumber,
           sqNodeInfo.id.nodeName,
           motorNumber);

    returnValue =
        meiMotorInfo(motor,
                     &motorInfo);
    msgCHECK(returnValue);

    /* read faults */
    returnValue =
        meiMotorAmpFault(motor, &faults);

    if (returnValue != MPIMessageUNSUPPORTED) {
        if (returnValue == MPIMessageOK) {

            /* display faults */
            if (faults.count != 0) {
                long nodeIndex;

                printf("Faults:\n");
                for (nodeIndex=0; nodeIndex<faults.count; nodeIndex++) {
                    printf("    code %3.3x : Msg: %s\n",
                        faults.code[nodeIndex],
                        faults.message[nodeIndex]);
                }
            }
            else {
                printf("No Faults\n");
            }
        }
    }
    else {
        printf("Fault codes not supported\n");
        returnValue = MPIMessageOK;
    }

    /* read warnings */
    returnValue =
        meiMotorAmpWarning(motor, &warnings);

    if (returnValue != MPIMessageUNSUPPORTED) {

        if (returnValue == MPIMessageOK) {
            /* display warnings */
            if (warnings.count != 0) {
                long nodeIndex;

                printf("Warnings:\n");
                for (nodeIndex=0; nodeIndex<warnings.count; nodeIndex++) {
                    printf("    code %3.3x : Msg: %s\n",
                        warnings.code[nodeIndex],
                        warnings.message[nodeIndex]);
                }
            }
            else {
                printf("No Warnings\n");
            }
        }
    }
    else {
        printf("Warning codes not supported\n");
        returnValue = MPIMessageOK;
    }

    msgCHECK(returnValue);
}


/* For each motor on a SynqNet network, call reportMotorFaults */
void forEachMotorOnSyqnNet_ReportMotorFaults(MPIControl control,
                                             MEISynqNet synqNet)
{
    MPIMotor        motor;
    MEISqNode       sqNode;
    MEISqNodeInfo   sqNodeInfo;
    MEISynqNetInfo  synqNetInfo;
    long            returnValue;
    long            nodeIndex, motorIndex;
    long            motorFirst, motorLast;

    returnValue =
        meiSynqNetInfo(synqNet,
                       &synqNetInfo);
    msgCHECK(returnValue);

    /* loop over nodes */
    for (nodeIndex=0; nodeIndex<synqNetInfo.nodeCount; nodeIndex++) {
        sqNode =
            meiSqNodeCreate(control, nodeIndex);
        msgCHECK(meiSqNodeValidate(sqNode));

        returnValue =
            meiSqNodeInfo(sqNode, &sqNodeInfo);
        msgCHECK(returnValue);

        motorFirst = sqNodeInfo.motorOffset;
        motorLast  = sqNodeInfo.motorOffset + sqNodeInfo.motorCount;

        /* loop over motors */
        for (motorIndex=motorFirst; motorIndex<motorLast; motorIndex++) {

            /* create motor */
            printf("\n  Motor[%d]\n",motorIndex);
            motor =
                mpiMotorCreate(control, motorIndex);
            msgCHECK(mpiMotorValidate(motor));

            /* Report Motor Faults */
            reportMotorFaults(motor, nodeIndex, sqNodeInfo);

            returnValue =
                mpiMotorDelete(motor);
            msgCHECK(returnValue)

        }

        returnValue =
            meiSqNodeDelete(sqNode);
        msgCHECK(returnValue)
    }
}


int main(int    argc,
         char   *argv[])
{
    MPIControl          control;
    MPIControlType      controlType;
    MPIControlAddress   controlAddress;
    MEISynqNet          synqNet;
    long                synqNetNumber = 0;
    long                returnValue;

    /* Parse command line */
    returnValue =
        parseCommandLine(argc,
                         argv,
                         &synqNetNumber,
                         &controlType,
                         &controlAddress);
    msgCHECK(returnValue);

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

    /* For each motor on a SynqNet network, call reportMotorFaults */
    forEachMotorOnSyqnNet_ReportMotorFaults(control,
                                            synqNet);

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

    return ((int)returnValue);
}


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