.

     

MPI Application Template
template.c
 

SQStatus1.c -- Display SynqNet Status
/* SQStatus1.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.
 */

/*

:Display SynqNet Status

This is a simple program to demonstrate how to read the SynqNet Status.

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"

/* 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,
            MPIXmpMaxSynqNets - 1);
        exit(MPIMessageARG_INVALID);
    }

    return 0;
}


/* Create and initialize MPI objects */
void programInit(MPIControl        *control,
                 MPIControlType     controlType,
                 MPIControlAddress *controlAddress,
                 MPISynqNet        *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 =
        mpiSynqNetCreate(*control,
        synqNetNumber);
    msgCHECK(mpiSynqNetValidate(*synqNet));
}


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

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

    *synqNet = MPIHandleVOID;

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

    *control = MPIHandleVOID;
}


/* Display SynqNet Node Status */
void displaySynqNetNodeStatus(MPISqNode sqNode)
{
    MPISqNodeInfo       nodeInfo;
    MPISqNodeStatus     nodeStatus;
    long                nodeNumber;
    long                returnValue;

    returnValue =
        mpiSqNodeInfo(sqNode, &nodeInfo);
    msgCHECK(returnValue);

    returnValue =
        mpiSqNodeNumber(sqNode, &nodeNumber);
    msgCHECK(returnValue);

    printf("\n  Node %ld Information\n"
           "    Motor Count  : %d\n"
           "    Motor Offset : %d\n"
           "    Drive Count  : %d\n",
           nodeNumber,
           nodeInfo.motorCount,
           nodeInfo.motorOffset,
           nodeInfo.driveCount);

    printf("    NodeType     : 0x%8.8X\n"
           "    NodeOption   : 0x%8.8X\n"
           "    Unique Id    : %d\n"
           "    Serial Number: %s\n"
           "    Model Number : %s\n"
         "    Manufact Data: %s\n"
           "    Switch Id    : 0x%X\n"
           "    FPGA Number  : 0x%X\n"
           "    FPGA Version : 0x%X\n",
           nodeInfo.id.nodeType,
           nodeInfo.id.option,
           nodeInfo.id.unique,
           nodeInfo.id.serialNumber,
           nodeInfo.id.modelNumber,
         nodeInfo.id.manufacturerData,
         nodeInfo.id.switchId,
         nodeInfo.fpga.vendorDevice,
           nodeInfo.fpga.version);

    returnValue =
        mpiSqNodeStatus(sqNode, &nodeStatus);
    msgCHECK(returnValue);

    printf("\n  Node %ld Status\n"
           "    IoAbort Event            : %s\n"
           "    Node Disable Event       : %s\n"
           "    Node Alarm Event         : %s\n"
           "    Power Failure Event      : %s\n"
           "    User Fault Event         : %s\n"
           "    Node Failure Event       : %s\n"
           "    Up Stream Error Rate     : %d\n"
           "    Up Stream Error Count    : %d\n"
           "    Down Stream Error Rate   : %d\n"
           "    Down Stream Error Count  : %d\n"
           "    Out Port CRC Errors      : %d\n"
           "    In Port CRC Errors       : %d\n\n",
           nodeNumber,
           mpiEventMaskBitGET(nodeStatus.eventMask, MPIEventTypeSQNODE_IO_ABORT) ? "TRUE" : "FALSE",
           mpiEventMaskBitGET(nodeStatus.eventMask, MPIEventTypeSQNODE_NODE_DISABLE) ? "TRUE" : "FALSE",
           mpiEventMaskBitGET(nodeStatus.eventMask, MPIEventTypeSQNODE_NODE_ALARM) ? "TRUE" : "FALSE",
           mpiEventMaskBitGET(nodeStatus.eventMask, MPIEventTypeSQNODE_ANALOG_POWER_FAULT) ? "TRUE" : "FALSE",
           mpiEventMaskBitGET(nodeStatus.eventMask, MPIEventTypeSQNODE_USER_FAULT) ? "TRUE" : "FALSE",
           mpiEventMaskBitGET(nodeStatus.eventMask, MPIEventTypeSQNODE_NODE_FAILURE) ? "TRUE" : "FALSE",
           nodeStatus.upStreamError.rate,
           nodeStatus.upStreamError.count,
           nodeStatus.downStreamError.rate,
           nodeStatus.downStreamError.count,
           nodeStatus.crcError.port[MPINetworkPortOUT0],
           nodeStatus.crcError.port[MPINetworkPortIN0]);
}

/* Display SynqNet Status */
void displaySynqNetStatus(MPIControl control,
                          MPISynqNet synqNet)
{
    MPISynqNetInfo      netInfo;
    MPISynqNetStatus    netStatus;
    MPISqNode           sqNode;
    long                index;
    long                returnValue;

    /* Read SynqNet Info */
    returnValue =
        mpiSynqNetInfo(synqNet, &netInfo);
    msgCHECK(returnValue);

    /* Read SynqNet Status */
    returnValue =
        mpiSynqNetStatus(synqNet,
                         &netStatus);
    msgCHECK(returnValue);

    /* Display SynqNet Status */
    printf("\nSynqNet Status\n"
           "  State      : %ld\n"
           "  In Port CRC Errors : %ld\n"
           "  Out Port CRC Errors: %ld\n"
           "  Failed Node Mask   : %ld\n"
           "  Network Dead Event : %s\n"
           "  Rx Failure Event   : %s\n"
           "  Tx Failure Event   : %s\n"
           "  Node Failure Event : %s\n"
           "  Recovery Event     : %s\n\n",
           netStatus.state,
           netStatus.crcError.port[MPINetworkPortIN0],
           netStatus.crcError.port[MPINetworkPortOUT0],
           netStatus.failedNodeMask[0],
           mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_DEAD) ? "TRUE" : "FALSE",
           mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_RX_FAILURE) ? "TRUE" : "FALSE",
           mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_TX_FAILURE) ? "TRUE" : "FALSE",
           mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_NODE_FAILURE) ? "TRUE" : "FALSE",
           mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_RECOVERY) ? "TRUE" : "FALSE");

    if (netInfo.nodeCount) {
      /* Cable Lengths */
      printf("Measured Cable Lengths (meters)\n");
        for (index = 0; index < (netInfo.nodeCount + 1); index++) {
         printf("  Cable: %ld, Length: %ld\n", index, netInfo.cableLength[index]);
      }

        /* Loop over nodes */
        for (index = netInfo.nodeOffset;
             index < (netInfo.nodeOffset + netInfo.nodeCount);
             index++) {

            sqNode =
                mpiSqNodeCreate(control, index);
            msgCHECK(mpiSqNodeValidate(sqNode));

            /* Display SynqNet Node Status */
            displaySynqNetNodeStatus(sqNode);

            returnValue =
                mpiSqNodeDelete(sqNode);
            msgCHECK(returnValue);
        }
    }
    else {
        printf("No SynqNet Blocks found.\n");
    }
}


int main(int    argc,
         char   *argv[])
{
    MPIControl          control;
    MPIControlType      controlType;
    MPIControlAddress   controlAddress;
    MPISynqNet          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);

    /* Display SynqNet Status */
    displaySynqNetStatus(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