⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ecinterface.h

📁 基于EthernetIP协议的应用程序,可以读取AB公司Controllogix系列Ethernetip协议PLC数据. 此软件代码可用于工业控制.
💻 H
字号:
#ifndef __ECInterface_h__
#define __ECInterface_h__

/* ! usefull macro to print out some debug information */
#ifdef DEBUG

	#define DBLN( str ) dbg_PrintLine( str, 0, "", __FILE__, __LINE__ )

	/* ! */
	#define ECASSERT(        expr, ErrorCode, ErrorText                   ) { if( !(expr) ){ dbg_PrintLine( "-->HALT: Assertion failed: ",         ErrorCode, ErrorText, __FILE__, __LINE__ ); exit(-1); } }
	#define ECASSERT_FL(     expr, ErrorCode, ErrorText, theFile, theLine ) { if( !(expr) ){ dbg_PrintLine( "-->HALT: Assertion failed: ",         ErrorCode, ErrorText,  theFile,  theLine ); exit(-1); } }
	#define ECASSERT_NO_WAY(                  ErrorText                   ) {                dbg_PrintLine( "-->HALT: Assertion failed: NO_WAY: ",         0, ErrorText, __FILE__, __LINE__ ); exit(-1);   }

	/* ! */
	void dbg_PrintLine( char *theStr, int theErrorCode, char *theMsg, char *theFile, unsigned int theLine );
	void dbg_LogLastError( char *thePreFix );
	void dbg_LogHex( char *thePrFx, void *theData, int theDataLen );

	/* ! */
	char *dbg_catint( char *theOutStr, long theValue, unsigned int theBase, int theLen );
	char *dbg_catstr( char *theOutStr, char *theInStr );
	char *dbg_ExtractFileName( char *theFullPath, char *theFileName );
	void  dbg_ThreadCreated( unsigned long theThreadId, char *theThreadName );
	void  dbg_ThreadDeleted( unsigned long theThreadId );

#else

	#define DBLN( str )

	/* ! */
	#define ECASSERT(        expr, ErrorCode, ErrorText                   )
	#define ECASSERT_FL(     expr, ErrorCode, ErrorText, theFile, theLine )
	#define ECASSERT_NO_WAY( expr                                         )

#endif


/* ! Types of UserDefinedAssemblyInstances */
typedef enum UserDefinedAssemblyInstance{ CONFIG, CONSUMER, PRODUCER, STATUSIN, STATUSOUT }e_UserDefinedAssemblyInstance;

/* ! Attribute DataType definitions */
typedef  unsigned char eci_BOOL;
typedef    signed char eci_SINT;
typedef    signed int  eci_INT;
typedef    signed long eci_DINT;
typedef  unsigned char eci_USINT;
typedef  unsigned int  eci_UINT;
typedef  unsigned long eci_UDINT;
typedef  float         eci_REAL;
typedef  double        eci_LREAL;

/* ! the User can set the TickPeriod to 2ms or 4ms or 5ms or 10ms */
/*int EC_SetTickPeriod( int theTickPeriod ); */

/* ! */
int EC_CreateUserDefinedAssembly( unsigned int theInstancesCount );
int EC_CreateUserDefinedAssemblyInstance( unsigned int theInstanceNo, e_UserDefinedAssemblyInstance theType, unsigned char **theDataPtr, unsigned int theDataByteSize );

/* ! Functions to create user defined objects */
int EC_CreateUserDefined( unsigned int theClassesCount );
int EC_CreateClass(    unsigned int theClassCode, unsigned int theAttributesCount, unsigned int theInstancesCount );
int EC_CreateInstance( unsigned int theClassCode, unsigned int theInstanceCode, unsigned int theAttributesCount );
int EC_CreateClassAttribute(    unsigned int theClassCode,                                unsigned char theAttributeCode, unsigned int theIsReadOnly, void *theDataPtr, int theDataSize );
int EC_CreateInstanceAttribute( unsigned int theClassCode, unsigned int  theInstanceCode, unsigned char theAttributeCode, unsigned int theIsReadOnly, void *theDataPtr, int theDataSize );

/* ! */
int  EC_CheckIntegrity( void );

/* ! the user application has to supply these functions: */
void EC_ResponseCB( struct sockaddr_in theAddrIn, void *theData, int theDataSize );
int  EC_UserDefinedAssemblyInstanceConfigDataCB( unsigned int theConfigInstanceNo );
int  EC_User_InitCB( void );

/*****************************************************************************
** HoR 14.02.2003 added two callback functions for user
*****************************************************************************/


/*
** start edits: September,23rd 2005, H.F.
**
** redefine EC_Run_IdleCB as the Run/Idle State is handled as
** it belongs to the Assemblies itself and not the whole device
** (i.e. Example Code)
**

void EC_Run_IdleCB( int theRun_Idle_Flag );

**
*/

void EC_Run_IdleCB( BOOL theRun_Idle_Flag, int theAssemblyInstanceNo );

/*
**
** add callback function for user
**
*/

void EC_AssemblyStateCB( int state, int theAssemblyInstanceNo );

/*
** end edits: September,23rd 2005, H.F.
*/


void EC_Get_StatusCB( int theStatus);
/*****************************************************************************/


/* ! */
void EC_BeforeSyncOfSendDataCB  ( int theAssemblyInstanceNo );
void EC_AfterSyncOfReceiveDataCB( int theAssemblyInstanceNo );


/* ! possible Errors */
enum e_ECIError{
	ECI_E_SUCCESS                        =  0,
	ECI_E_CREATEUSERDEFINED_CALL_MISSING =  1,
	ECI_E_OUT_OF_MEMORY                  =  2,
	ECI_E_CLASS_NOT_FOUND                =  3,
	ECI_E_INSTANCE_NOT_FOUND             =  4,
	ECI_E_ATTRIBUTE_NOT_FOUND            =  5,
	ECI_E_USERDEFINED_IS_NULL            =  6,
	ECI_E_CLASS_IS_NULL                  =  7,
	ECI_E_CLASSCODE_IS_EMPTY             =  8,
	ECI_E_ATTRIBUTE_IS_NULL              =  9,
	ECI_E_ATTRIBUTECODE_IS_EMPTY         = 10,
	ECI_E_DATASIZE_IS_0                  = 11,
	ECI_E_DATAPTR_IS_NULL                = 12,
	ECI_E_INSTANCE_IS_NULL               = 13,
	ECI_E_INSTANCECODE_IS_EMPTY          = 14,
	ECI_E_INVALID_TICKPERIOD             = 15,
	ECI_E_USERDEFINEDASSEMBLY_IS_EMPTY   = 16,
	ECI_E_MAX_USER_DEFINED_CLASSES       = 17,
	ECI_E_SEND_SOME_DATA_FAILED          = 18

};
extern enum e_ECIError gECIError;
char *EC_ErrorText( enum e_ECIError theECIError );



#ifndef __EtherNetIPExampleCode_h__
#define __EtherNetIPExampleCode_h__

/* The following ifdef block is the standard way of creating macros which make exporting 
** from a DLL simpler. All files within this DLL are compiled with the ETHERNETIPEXAMPLECODE_EXPORTS
** symbol defined on the command line. this symbol should not be defined on any project
** that uses this DLL. This way any other project whose source files include this file see 
** ETHERNETIPEXAMPLECODE_API functions as being imported from a DLL, wheras this DLL sees symbols
** defined with this macro as being exported.
*/

#include "fd.h"

#ifdef ETHERNETIPEXAMPLECODE_EXPORTS
	#define ETHERNETIPEXAMPLECODE_API __declspec(dllexport)
#else
	#define ETHERNETIPEXAMPLECODE_API __declspec(dllimport)
#endif

#ifdef __cplusplus
		#define EXTFUNC extern "C"
	#else
		#define EXTFUNC extern
#endif

typedef struct s_InstDataDscr{
	int    itsInstanceNo;
	char **itsPtr; 
	int   *itsSize; /* Size in Bytes */
}t_InstDataDscr;

/* ! */
EXTFUNC ETHERNETIPEXAMPLECODE_API unsigned char *gAssembly_ConData_101; EXTFUNC ETHERNETIPEXAMPLECODE_API unsigned int gAssembly_ConDataSize_101;
EXTFUNC ETHERNETIPEXAMPLECODE_API unsigned char *gAssembly_ProData_102; EXTFUNC ETHERNETIPEXAMPLECODE_API unsigned int gAssembly_ProDataSize_102;
EXTFUNC ETHERNETIPEXAMPLECODE_API unsigned char *gAssembly_ConData_111; EXTFUNC ETHERNETIPEXAMPLECODE_API unsigned int gAssembly_ConDataSize_111;
EXTFUNC ETHERNETIPEXAMPLECODE_API unsigned char *gAssembly_ProData_112; EXTFUNC ETHERNETIPEXAMPLECODE_API unsigned int gAssembly_ProDataSize_112;

EXTFUNC ETHERNETIPEXAMPLECODE_API struct sockaddr_in gResponseAddrIn;
EXTFUNC ETHERNETIPEXAMPLECODE_API unsigned char      gResponseData[];
EXTFUNC ETHERNETIPEXAMPLECODE_API unsigned int       gResponseDataSize;

/* ! */
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 RunIdleStat;

/*
** start edits: September,23rd 2005, H.F.
*/

EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_101;
EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_102;
EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_103;
EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_104;
EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_105;

EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_111;
EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_112;
EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_113;

EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_121;
EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_122;
EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_123;

EXTFUNC ETHERNETIPEXAMPLECODE_API BOOL RunIdleStat_Heartbeat;


EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_101;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_102;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_103;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_104;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_105;

EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_111;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_112;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_113;

EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_121;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_122;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_123;

EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 AssemblyStat_Heartbeat;

/*
** end edits: September,23rd 2005, H.F.
*/

EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 CON_FLAG;

/* ! */
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 EC_Status;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 EC_ProductCode;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 EC_ProductType;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT32 EC_SerialNumber;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 EC_VendorId;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT8  EC_MajorRev;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT8  EC_MinorRev;
EXTFUNC ETHERNETIPEXAMPLECODE_API UINT8  EC_ProductName[];

/*
** start edits: August,29th 2005, H.F.
*/

EXTFUNC ETHERNETIPEXAMPLECODE_API UINT16 SY_HEARTBEAT_INSTANCE;

/*
** end edits: August,29th 2005, H.F.
*/


/* ! */
EXTFUNC ETHERNETIPEXAMPLECODE_API void EC_main( void );
EXTFUNC ETHERNETIPEXAMPLECODE_API int EC_Request( char *theHostName, unsigned char *theData, int theDataLen );


/*
** start edits: September,26th 2005, H.F.
*/

EXTFUNC ETHERNETIPEXAMPLECODE_API void EC_UpdateRunIdleStateOfProducerAssembly( BOOL theRun_Idle_Flag, int theAssemblyInstanceNo );

/*
** end edits: September,26th 2005, H.F.
*/

#endif


#endif

⌨️ 快捷键说明

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