//Return Code #define CAN_NoError 0 //No Error #define CAN_ResetError 5 //Reset Error #define CAN_ConfigError 8 //Configuration Failure #define CAN_SetACRError 9 #define CAN_SetAMRError 10 #define CAN_SetBaudRateError 11 #define CAN_InstallIrqFailure 14 #define CAN_RemoveIrqFailure 15 #define CAN_TransmitIncomplete 16 #define CAN_TransmitBufferLocked 17 #define CAN_ReceiveBufferEmpty 18 #define CAN_DataOverrun 19 #define CAN_ReceiveError 20 #define CAN_SoftBufferIsFull 21 #define CAN_SoftBufferIsEmpty 22 #define CAN_BaudNotSupport 23 #define CAN_DataLengthError 24 #define CAN_NotEnoughMemory 25 #define CAN_TypeOf7188Error 26 #define CAN_AIFreqError 40 #define CAN_AICntError 41 #define CAN_AutoBaudTimeout 50 //XSCAN Return Code #define XS_NodeIDError 100 #define XS_SlaveTimeout 101 #define XS_NoDIData 102 #define XS_NoDOData 103 #define XS_IOBitOutOfRange 104 #define XS_DataLengthError 105 //Get the library version int XSCCON_Ver(unsigned long *Ver); //Initial the XServer CCON master library int XSCCON_Init(unsigned long CANBaud, char BT0, char BT1,unsigned long AccCode,unsigned long AccMask); //Set the heartbeat of the host int XSCCON_SetHostHeartbeat(unsigned long HeartbeatTime); //Set the host heartbeat timeout value of the modules //The host heartbeat message must less than the timeout value int XSCCON_SetModuleHeartbeatTimeout(unsigned char NodeID, unsigned long HostHeartbeatTimeout); //Set the I/O channels of the modules int XSCCON_SetModuleConfig(unsigned char NodeID, unsigned char DO_TotalCh, unsigned char DI_TotalCh, unsigned char AO_TotalCh, unsigned char AI_TotalCh, unsigned char PWM_TotalCh, unsigned char Counter_TotalCh); //Set the I/O module to reply I/O data automatically int XSCCON_SetAutoRespData(unsigned char NodeID, unsigned long AutoRespTime); //The XServer CCON master service function //Put this function in Main() and call it continually void XSCCON_Main(void); //Get the status of the modules int XSCCON_ModuleStatus(unsigned char NodeID, unsigned char *Status); int XSCCON_ReadDI(unsigned char NodeID, unsigned char *TotalByteCount, unsigned char DIValue[]); int XSCCON_ReadDIO(unsigned char NodeID, unsigned char *DIByteCount, unsigned char DIValue[], unsigned char *DOByteCount, unsigned char DOValue[]); int XSCCON_WriteDO(unsigned char NodeID, unsigned char DOByteCount, unsigned char DOValue[]); //iChannel is zero-based value int XSCCON_WriteDOBit(unsigned char NodeID, int iChannel, int iBitValue); int XSCCON_ReadbackDO(unsigned char NodeID, unsigned char *DOByteCount, unsigned char DOValue[]); //iChannel is zero-based value int XSCCON_ReadbackDOBit(unsigned char NodeID, int iChannel, int *iBitValue); void XSCCON_Restore(void); void L1Off(void); void L1On(void); void L2Off(void); void L2On(void); void L3Off(void); void L3On(void); /* I refer to the WinPAC I/O API WINPAC_API bool pac_WriteDO(HANDLE hPort, int slot, int iDO_TotalCh, DWORD lDO_Value); WINPAC_API bool pac_WriteDOBit(HANDLE hPort, int slot, int iDO_TotalCh, int iChannel, int iBitValue); unsigned long i8KR_ReadbackDO(int slot); short i8KR_ReadbackDOBit(int slot,int iBitIndex ); WINPAC_API bool pac_ReadDO(HANDLE hPort, int slot,int iDO_TotalCh, DWORD *lDO_Value); WINPAC_API bool pac_ReadDI(HANDLE hPort, int slot,int iDI_TotalCh, DWORD *lDI_Value); WINPAC_API bool pac_ReadDIO(HANDLE hPort, int slot,int iDI_TotalCh,int iDO_TotalCh, DWORD* lDI_Value, DWORD* lDO_Value); WINPAC_API bool pac_ReadDILatch(HANDLE hPort, int slot, int iDI_TotalCh,int iLatchType, DWORD *lDI_Latch_Value); WINPAC_API bool pac_ClearDILatch(HANDLE hPort, int slot); WINPAC_API bool pac_ReadDIOLatch(HANDLE hPort, int slot,int iDI_TotalCh,int iDO_TotalCh,int iLatchType, DWORD *lDI_Latch_Value,DWORD *lDO_Latch_Value); WINPAC_API bool pac_ClearDIOLatch(HANDLE hPort, int slot); WINPAC_API bool pac_ReadDICNT(HANDLE hPort, int slot,int iChannel,int iDI_TotalCh, DWORD *lCounter_Value); WINPAC_API bool pac_ClearDICNT(HANDLE hPort, int slot,int iChannel,int iDI_TotalCh); WINPAC_API bool pac_WriteAO(HANDLE hPort, int slot,int iChannel,int iAO_TotalCh,float fValue); WINPAC_API bool pac_ReadAO(HANDLE hPort, int slot,int iChannel,int iAO_TotalCh,float *fValue); WINPAC_API bool pac_ReadAI(HANDLE hPort, int slot,int iChannel, int iAI_TotalCh,float *fValue); WINPAC_API bool pac_ReadAIHex(HANDLE hPort, int slot,int iChannel, int iAI_TotalCh,int *iValue); WINPAC_API bool pac_ReadAIAll(HANDLE hPort, int slot,float fValue[]); WINPAC_API bool pac_ReadAIAllHex(HANDLE hPort, int slot, int iValue[]); WINPAC_API bool pac_ReadCNT(HANDLE hPort, int slot, int iChannel, DWORD *lCounter_Value); WINPAC_API bool pac_ClearCNT(HANDLE hPort, int slot,int iChannel); WINPAC_API bool pac_ReadCNTOverflow(HANDLE hPort, int slot, int iChannel, int *iOverflow); */ //User defined function //XServer CCON master will call this function when the status of CAN is error void UserFunc_CANStatusError(unsigned char CANChip_RegisterStatus); //XServer CCON master will call this function when the I/O module is error //void UserFunc_IOModuleError(unsigned char NodeID,unsigned char ErrorCode);