.

     

MPI Application Template
template.c
 

SQcmd1.c -- How to send a service command to a SynqNet Node.
/* SQcmd1.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.
 */

/*

:This sample code demonstrates how to send a service command to a SynqNet Node.

User inputs address and data for the sqNode command, and receives a response.
The response is output to the console. 
This routine is useful for configuring node features that are not part of the 
general sqNode interface. 

    meiSqNodeCommand(MEISqNode              sqNode,
                    MEISqNodeCommand        *command,
                    MEISqNodeResponse       *response);

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"

#define NODE_NUMBER (0)

/* 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,
                 MEISqNode          *sqNode,
                 long                nodeNumber)
{
    long    returnValue;


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

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

    /* Create SynqNet Node object */
    *sqNode =
        meiSqNodeCreate(*control,
                        nodeNumber);
    msgCHECK(meiSqNodeValidate(*sqNode));
}


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

    /* Delete sqNode handle */
    returnValue =
        meiSqNodeDelete(*sqNode);
    msgCHECK(returnValue);

    *sqNode = MPIHandleVOID;

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

    *control = MPIHandleVOID;
}


/* Demonstrate how to perform a SynqNet node command */
void performNodeCommand(MEISqNode sqNode)
{
    MEISqNodeCommand        command;
    MEISqNodeResponse       response;
    long                    returnValue;

    command.address = 0x00010000;   /* READ_ID       */
    command.data    = 0x00;         /* Dev/Vendor ID */

    command.header.channel  = MEISqNodeChannelNODE;
    command.header.memory   = MEISqNodeMemoryDATA;
    command.header.size     = MEISqNodeDataSize32BIT;
    command.header.type     = MEISqNodeCmdTypeREAD;

    /* Send command and get response across SynqNet */
    returnValue =
        meiSqNodeCommand(sqNode,
                         &command,
                         &response);
    msgCHECK(returnValue);

    printf("\n Response: 0x%x\n\n", response.data);
}


int main(int    argc,
         char   *argv[])
{
    MPIControl              control;
    MPIControlType          controlType;
    MPIControlAddress       controlAddress;
    MEISqNode               sqNode;
    long                    nodeNumber = NODE_NUMBER;

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

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

    /* Demonstrate how to perform a SynqNet node command */
    performNodeCommand(sqNode);

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

    return 0;
}


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