cml_io.h

来自「美国COPLEY驱动器,程序开发工具之一.」· C头文件 代码 · 共 1,236 行 · 第 1/5 页

H
1,236
字号
/************************************************************/
/*                                                          */
/*  Copley Motion Libraries                                 */
/*                                                          */
/*  Author: Stephen Glow                                    */
/*                                                          */
/*  Copyright (c) 2002-2005 Copley Controls Corp.           */
/*                          http://www.copleycontrols.com   */
/*                                                          */
/************************************************************/

/** \file 

  Standard CANopen I/O module support.

*/

#ifndef _DEF_INC_IO
#define _DEF_INC_IO

#include "CML_Settings.h"
#include "CML_Node.h"
#include "CML_PDO.h"

CML_NAMESPACE_START()

/***************************************************************************/
/**
  I/O module errors.  This class is used to represent errors that may be returned
  by a standard I/O module.
  */
/***************************************************************************/
class IOError: public NodeError
{
   public:
      static const IOError BadID;        ///< The passed digital I/O pin ID number is invalid
      static const IOError BadIOCount;   ///< The number of passed I/O ID blocks is invalid

   protected:
      /// Standard protected constructor
      IOError( uint16 id, const char *desc ): NodeError( id, desc ){}
};

/***************************************************************************/
/**
  Object dictionary ID values used on standard I/O modules.
  */
/***************************************************************************/
enum IO_OBJID
{
   IOOBJID_DIN_8_VALUE             = 0x6000,  ///<  8-bit digital input value 
   IOOBJID_DIN_8_POL               = 0x6002,  ///<  8-bit digital input polarity
   IOOBJID_DIN_8_FILT              = 0x6003,  ///<  8-bit digital input filter constant
   IOOBJID_DIN_INTENA              = 0x6005,  ///< Digital input interrupt enable
   IOOBJID_DIN_8_MASK_ANY          = 0x6006,  ///<  8-bit digital input int mask, any change
   IOOBJID_DIN_8_MASK_L2H          = 0x6007,  ///<  8-bit digital input int mask, low to high
   IOOBJID_DIN_8_MASK_H2L          = 0x6008,  ///<  8-bit digital input int mask, high to low
   IOOBJID_DIN_1_VALUE             = 0x6020,  ///<  1-bit digital input value
   IOOBJID_DIN_1_POL               = 0x6030,  ///<  1-bit digital input polarity
   IOOBJID_DIN_1_FILT              = 0x6038,  ///<  1-bit digital input filter constant
   IOOBJID_DIN_1_MASK_ANY          = 0x6050,  ///<  1-bit digital input int mask, any change
   IOOBJID_DIN_1_MASK_L2H          = 0x6060,  ///<  1-bit digital input int mask, low to high
   IOOBJID_DIN_1_MASK_H2L          = 0x6070,  ///<  1-bit digital input int mask, high to low
   IOOBJID_DIN_16_VALUE            = 0x6100,  ///< 16-bit digital input value
   IOOBJID_DIN_16_POL              = 0x6102,  ///< 16-bit digital input polarity
   IOOBJID_DIN_16_FILT             = 0x6103,  ///< 16-bit digital input filter constant
   IOOBJID_DIN_16_MASK_ANY         = 0x6106,  ///< 16-bit digital input int mask, any change
   IOOBJID_DIN_16_MASK_L2H         = 0x6107,  ///< 16-bit digital input int mask, low to high
   IOOBJID_DIN_16_MASK_H2L         = 0x6108,  ///< 16-bit digital input int mask, high to low
   IOOBJID_DIN_32_VALUE            = 0x6120,  ///< 32-bit digital input value
   IOOBJID_DIN_32_POL              = 0x6122,  ///< 32-bit digital input polarity
   IOOBJID_DIN_32_FILT             = 0x6123,  ///< 32-bit digital input filter constant
   IOOBJID_DIN_32_MASK_ANY         = 0x6126,  ///< 32-bit digital input int mask, any change
   IOOBJID_DIN_32_MASK_L2H         = 0x6127,  ///< 32-bit digital input int mask, low to high
   IOOBJID_DIN_32_MASK_H2L         = 0x6128,  ///< 32-bit digital input int mask, high to low

   IOOBJID_DOUT_8_VALUE            = 0x6200,  ///<  8-bit digital output value
   IOOBJID_DOUT_8_POL              = 0x6202,  ///<  8-bit digital output polarity
   IOOBJID_DOUT_8_ERRMODE          = 0x6206,  ///<  8-bit digital output error mode
   IOOBJID_DOUT_8_ERRVAL           = 0x6207,  ///<  8-bit digital output error value
   IOOBJID_DOUT_8_FILT             = 0x6208,  ///<  8-bit digital output filter mask
   IOOBJID_DOUT_1_VALUE            = 0x6220,  ///<  1-bit digital output value
   IOOBJID_DOUT_1_POL              = 0x6240,  ///<  1-bit digital output polarity
   IOOBJID_DOUT_1_ERRMODE          = 0x6250,  ///<  1-bit digital output error mode
   IOOBJID_DOUT_1_ERRVAL           = 0x6260,  ///<  1-bit digital output error value
   IOOBJID_DOUT_1_FILT             = 0x6270,  ///<  1-bit digital output filter mask
   IOOBJID_DOUT_16_VALUE           = 0x6300,  ///< 16-bit digital output value
   IOOBJID_DOUT_16_POL             = 0x6302,  ///< 16-bit digital output polarity
   IOOBJID_DOUT_16_ERRMODE         = 0x6306,  ///< 16-bit digital output error mode
   IOOBJID_DOUT_16_ERRVAL          = 0x6307,  ///< 16-bit digital output error value
   IOOBJID_DOUT_16_FILT            = 0x6308,  ///< 16-bit digital output filter mask
   IOOBJID_DOUT_32_VALUE           = 0x6320,  ///< 32-bit digital output value
   IOOBJID_DOUT_32_POL             = 0x6322,  ///< 32-bit digital output polarity
   IOOBJID_DOUT_32_ERRMODE         = 0x6326,  ///< 32-bit digital output error mode
   IOOBJID_DOUT_32_ERRVAL          = 0x6327,  ///< 32-bit digital output error value
   IOOBJID_DOUT_32_FILT            = 0x6328,  ///< 32-bit digital output filter mask

   IOOBJID_AIN_8_VALUE             = 0x6400,  ///<  8-bit analog input value
   IOOBJID_AIN_16_VALUE            = 0x6401,  ///< 16-bit analog input value
   IOOBJID_AIN_32_VALUE            = 0x6402,  ///< 32-bit analog input value
   IOOBJID_AIN_FLT_VALUE           = 0x6403,  ///< floating point analog input value
   IOOBJID_AIN_MFG_VALUE           = 0x6404,  ///< manufacturer specific analog input value

   IOOBJID_AOUT_8_VALUE            = 0x6410,  ///<  8-bit analog output value
   IOOBJID_AOUT_16_VALUE           = 0x6411,  ///< 16-bit analog output value
   IOOBJID_AOUT_32_VALUE           = 0x6412,  ///< 32-bit analog output value
   IOOBJID_AOUT_FLT_VALUE          = 0x6413,  ///< floating point analog output value
   IOOBJID_AOUT_MFG_VALUE          = 0x6414,  ///< manufacturer specific analog output value

   IOOBJID_AIN_TRIG                = 0x6421,  ///< Analog input trigger selection
   IOOBJID_AIN_INTSRC              = 0x6422,  ///< Analog input interrupt source
   IOOBJID_AIN_INTENA              = 0x6423,  ///< Analog input interrupt enable

   IOOBJID_AIN_32_UPLIM            = 0x6424,  ///< 32-bit analog input upper limit
   IOOBJID_AIN_32_LWLIM            = 0x6425,  ///< 32-bit analog input lower limit
   IOOBJID_AIN_32_UDELTA           = 0x6426,  ///< 32-bit analog input unsigned delta
   IOOBJID_AIN_32_NDELTA           = 0x6427,  ///< 32-bit analog input negative delta
   IOOBJID_AIN_32_PDELTA           = 0x6428,  ///< 32-bit analog input positive delta

   IOOBJID_AIN_FLT_UPLIM           = 0x6429,  ///< floating point analog input upper limit
   IOOBJID_AIN_FLT_LWLIM           = 0x642A,  ///< floating point analog input lower limit
   IOOBJID_AIN_FLT_UDELTA          = 0x642B,  ///< floating point analog input unsigned delta
   IOOBJID_AIN_FLT_NDELTA          = 0x642C,  ///< floating point analog input negative delta
   IOOBJID_AIN_FLT_PDELTA          = 0x642D,  ///< floating point analog input positive delta

   IOOBJID_AIN_FLT_OFFSET          = 0x642E,  ///< floating point analog input offset
   IOOBJID_AIN_FLT_SCALE           = 0x642F,  ///< floating point analog input scaling
   IOOBJID_AIN_UNIT                = 0x6430,  ///< analog input SI Unit
   IOOBJID_AIN_32_OFFSET           = 0x6431,  ///< 32-bit analog input offset
   IOOBJID_AIN_32_SCALE            = 0x6432,  ///< 32-bit analog input scaling

   IOOBJID_AOUT_FLT_OFFSET         = 0x6441,  ///< floating point analog output offset
   IOOBJID_AOUT_FLT_SCALE          = 0x6442,  ///< floating point analog output scaling
   IOOBJID_AOUT_ERRMODE            = 0x6443,  ///< analog output error mode
   IOOBJID_AOUT_32_ERRVAL          = 0x6444,  ///< 32-bit analog output error value
   IOOBJID_AOUT_FLT_ERRVAL         = 0x6445,  ///< floating point analog output error value
   IOOBJID_AOUT_32_OFFSET          = 0x6446,  ///< 32-bit analog output offset
   IOOBJID_AOUT_32_SCALE           = 0x6447,  ///< 32-bit analog output scaling
   IOOBJID_AOUT_UNIT               = 0x6450   ///< analog output SI Unit
};

/***************************************************************************/
/**
  This enumeration is used to define the types of events that may cause an
  analog input to generate an interrupt event.
  */
/***************************************************************************/
enum IO_AIN_TRIG_TYPE
{
   IOAINTRIG_UPPER_LIM             = 0x0001, ///< Input above upper limit 
   IOAINTRIG_LOWER_LIM             = 0x0002, ///< Input below lower limit
   IOAINTRIG_UDELTA                = 0x0004, ///< Input changed by more then the unsigned delta amount
   IOAINTRIG_NDELTA                = 0x0008, ///< Input reduced by more then the negative delta amount
   IOAINTRIG_PDELTA                = 0x0010  ///< Input increased by more then the positive delta
};

/***************************************************************************/
/**
  This enumeration gives the various events that can be waited on.  The default
  events are simply the reception of one of the standard transmit PDO objects.
  */
/***************************************************************************/
enum IOMODULE_EVENTS
{
   /// Digital input PDO 0 was received.  By default, this PDO is
   /// transmitted by the module when any of the first 64 digital
   /// inputs changes state.
   IOEVENT_DIN_PDO0                = 0x00000001,

   /// Analog input PDO 0 was received.  By default, this PDO is
   /// transmitted by the module when any of the first 4 16-bit
   /// analog inputs generates an event.
   ///
   /// There are many different types of events that are programmable
   /// for analog inputs, however not all I/O module manufacturers 
   /// support all (or any) of these events.  The function 
   /// IOmodule::AinSetTrigType can be used to set the type of event
   /// associated with an analog input.
   ///
   /// Consult the documentation provided with the I/O module to determine
   /// what types of analog input events are available for your module.
   IOEVENT_AIN_PDO0                = 0x00010000,

   /// Analog input PDO 1 was received.  This PDO is similar to analog input
   /// PDO 0, however it maps the second group of 4 16-bit analog inputs.
   IOEVENT_AIN_PDO1                = 0x00020000,

   /// Analog input PDO 2 was received.  This PDO is similar to analog input
   /// PDO 0, however it maps the third group of 4 16-bit analog inputs.
   IOEVENT_AIN_PDO2                = 0x00040000
};

/***************************************************************************/
/**
  Standard CANopen I/O module settings.  This structure may be passed to an
  I/O module object during initialization.  It allows custom settings to be
  assigned to the module.
  */
/***************************************************************************/
struct IOModuleSettings
{
   /// The CANopen heartbeat protocol is one of two standard methods used
   /// to constantly watch for network or device problems.  
   /// When the heartbeat protocol is used, each device on the CANopen
   /// network transmits a 'heartbeat' message at a specified interval.
   /// The network master watches for these messages, and is able to 
   /// detect a device error if it's heartbeat message is not received
   /// within the expected time.
   ///
   /// This parameter configures the heartbeat period (milliseconds)
   /// that will be used by this module to transmit it's heartbeat
   /// message.
   ///
   /// If this parameter is set to zero, then the heartbeat protocol
   /// is disabled on this node.
   ///
   /// Default: zero (not used)
   uint16 heartbeatPeriod;

   /// Additional time to wait before generating a heartbeat error (milliseconds)
   /// If the heartbeat protocol is used, then this value, combined with the
   /// heartbeatTime will determine how long the network master waits for the
   /// node's heartbeat message before it generates a heartbeat error.
   ///
   /// Note that setting this to zero does not disable the heartbeat protocol.
   /// set the heartbeatPeriod value to zero to disable heartbeat.
   ///
   /// Default 100 (ms)
   uint16 heartbeatTimeout;

   /// Node guarding guard time (milliseconds)
   ///
   /// The CANopen node guarding protocol is a second method (the first being the
   /// heartbeat protocol) for devices on the network to watch for network problems.
   /// In this protocol, the master controller sends a request message out to the 
   /// slave device at a specified interval.  The slave device responds to this 
   /// request with a message indicating it's state.
   ///
   /// The main difference between this protocol and the heartbeat protocol is that
   /// both the slave node and the master are able to recognize network errors.
   /// With the heartbeat protocol only the network master is able to identify 
   /// network problems.
   ///
   /// Note that only one of these two protocols can be active in a node device at
   /// any time.  If the heartbeat period is non-zero, then the heartbeat protocol
   /// will be used.
   ///
   /// This parameter gives the node guarding period for use with this node.  This

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?