20 #include "../include/ntcan.h" 22 #if defined(__LINUX__) 26 #include "../include/ntcan_qnx.h" 60 warning(
"NTCAN_ID_NOT_ENABLED");
66 warning(
"NTCAN_INVALID_HANDLE");
71 warning(
"NTCAN_INVALID_HARDWARE");
76 warning(
"NTCAN_INVALID_PARAMETER");
159 iRetVal =
canIdAdd(m_hDevice, uiMessageId);
162 warning(
"can add ID failed Errorcode: %d", iRetVal);
173 int32_t iNumberOfMessages = 1;
174 static CMSG clESDProtocolMessage;
178 iRetVal =
canRead(m_hDevice, &clESDProtocolMessage, &iNumberOfMessages, NULL);
179 }
while( ! ( ( iNumberOfMessages == 0 ) && ( iRetVal ==
NTCAN_SUCCESS ) ) );
190 warning(
"device not initialized");
212 warning(
"can close failed Errorcode: %d", iRetVal);
219 warning(
"can close failed Errorcode: %d", iRetVal);
234 warning(
"can open failed Errorcode: %d", iRetVal);
264 warning(
"can add ID failed Errorcode: %d", iRetVal);
272 warning(
"can add ID failed Errorcode: %d", iRetVal);
284 warning(
"can add ID failed Errorcode: %d", iRetVal);
290 iRetVal =
canIdAdd(m_hDevice, (0x180 + i));
293 warning(
"can add ID failed Errorcode: %d", iRetVal);
305 warning(
"can add ID failed Errorcode: %d", iRetVal);
315 warning(
"can add ID failed Errorcode: %d", iRetVal);
335 int32_t iNumberOfMessages = 1;
336 CMSG clESDProtocolMessage;
339 #if defined ( _WIN32 ) 341 double dFrequency = 0;
342 LARGE_INTEGER liTime, liTimeStart, liTimeEnd;
344 QueryPerformanceFrequency( &liTime );
345 dFrequency = liTime.LowPart;
347 QueryPerformanceCounter( &liTimeStart );
350 iNumberOfMessages = 1;
351 iRetVal =
canTake( m_hDevice, &clESDProtocolMessage, &iNumberOfMessages );
354 warning(
"can read failed Errorcode: %d", iRetVal);
358 QueryPerformanceCounter( &liTimeEnd );
359 fTimeDiff = (float)(liTimeEnd.LowPart - liTimeStart.LowPart) / (float)dFrequency * 1000;
367 }
while( iNumberOfMessages == 0 );
369 iRetVal =
canRead(m_hDevice, &clESDProtocolMessage, &iNumberOfMessages, NULL);
372 warning(
"can read failed Errorcode: %d", iRetVal);
389 int32_t iNumberOfMessages = 1;
390 CMSG clESDProtocolMessage;
399 clESDProtocolMessage.
len |= 0x10;
401 iRetVal =
canWrite(m_hDevice, &clESDProtocolMessage, &iNumberOfMessages, NULL);
405 warning(
"can send failed Errorcode: %d", iRetVal);
426 error(-1,
"Sorry constructor is not implemented");
442 error(-1,
"Sorry operator= is not implemented");
494 warning(
"device already initialized");
501 strncpy(acString,acInitString,128);
502 pcToken = strtok( acString,
":" );
507 if( strcmp( pcToken,
"ESD" ) != 0 )
511 pcToken = strtok( NULL,
"," );
518 pcToken = strtok( NULL,
"," );
525 #if defined(__LINUX__) 559 warning(
"can open failed Errorcode: %d", iRetVal);
574 warning(
"can open failed Errorcode: %d", iRetVal);
582 warning(
"init ESD device failed no library found");
592 warning(
"can add ID failed Errorcode: %d", iRetVal);
600 warning(
"can add ID failed Errorcode: %d", iRetVal);
612 warning(
"can add ID failed Errorcode: %d", iRetVal);
618 iRetVal =
canIdAdd(m_hDevice, (0x180 + i));
621 warning(
"can add ID failed Errorcode: %d", iRetVal);
626 iRetVal =
canIdAdd(m_hDevice, (0x600 + i));
629 warning(
"can add ID failed Errorcode: %d", iRetVal);
641 warning(
"can add ID failed Errorcode: %d", iRetVal);
651 warning(
"can add ID failed Errorcode: %d", iRetVal);
678 warning(
"device not initialized");
686 warning(
"can close failed Errorcode: %d", iRetVal);
693 warning(
"can close failed Errorcode: %d", iRetVal);
706 bool bRecieved =
false;
707 int32_t iNumberOfMessages = 1;
708 CMSG clESDProtocolMessage;
713 iRetVal =
canRead(m_hSyncDevice, &clESDProtocolMessage, &iNumberOfMessages, NULL);
716 warning(
"can read failed Errorcode: %d", iRetVal);
723 debug(1,
"received CAN-ID %x, expected %x", clESDProtocolMessage.
id,
MSGID_ALL);
728 debug(1,
"wrong command ID");
void setQueueSize(unsigned short uiQueueSize)
#define ERRID_DEV_BADINITSTRING
unsigned short m_uiQueueSize
#define NTCAN_MESSAGE_LOST
#define NTCAN_ID_NOT_ENABLED
#define MSGID_SCHUNK_RECV
unsigned char m_aucMessageData[8]
int waitForStartMotionAll()
int initMessage(const char *pcClassName, int iDebuglevel=0, bool bDebug=true, bool bDebugFile=false)
EXPORT NTCAN_RESULT CALLTYPE canWrite(NTCAN_HANDLE handle, CMSG *cmsg, int32_t *len, OVERLAPPED *ovrlppd)
CRITICAL_SECTION m_csDevice
EXPORT NTCAN_RESULT CALLTYPE canTake(NTCAN_HANDLE handle, CMSG *cmsg, int32_t *len)
int writeDevice(CProtocolMessage &rclProtocolMessage)
#define ERRID_DEV_ISINITIALIZED
void error(const int iErrorCode, const char *pcErrorMessage,...) const
#define ERRID_DEV_WRITEERROR
void setTimeOut(unsigned long uiTimeOut)
#define ERRID_DEV_NOTINITIALIZED
#define ERRID_DEV_READTIMEOUT
#define BAUDRATEID_MOD_CAN_250K
unsigned char m_ucMessageLength
int printMessage(CProtocolMessage &rclProtocolMessage, bool read)
#define NTCAN_CONTR_OFF_BUS
#define NTCAN_INVALID_PARAMETER
unsigned long m_uiBaudRate
#define NTCAN_NO_ID_ENABLED
unsigned long m_uiMessageId
CESDDevice & operator=(const CESDDevice &rclESDDevice)
#define ERRID_DEV_WRITETIMEOUT
void warning(const char *pcWarningMessage,...) const
int reinit(unsigned char ucBaudRateId)
EXPORT NTCAN_RESULT CALLTYPE canOpen(int32_t net, uint32_t flags, int32_t txqueuesize, int32_t rxqueuesize, int32_t txtimeout, int32_t rxtimeout, NTCAN_HANDLE *handle)
#define ERRID_DEV_INITERROR
int setMessageId(unsigned long uiMessageId)
#define NTCAN_INVALID_HARDWARE
EXPORT NTCAN_RESULT CALLTYPE canClose(NTCAN_HANDLE handle)
#define ERRID_DEV_EXITERROR
void debug(const int iDebugLevel, const char *pcDebugMessage,...) const
int getDeviceError(int iErrorState)
#define ERRID_DEV_NOLIBRARY
EXPORT NTCAN_RESULT CALLTYPE canRead(NTCAN_HANDLE handle, CMSG *cmsg, int32_t *len, OVERLAPPED *ovrlppd)
#define BAUDRATEID_MOD_CAN_125K
#define NTCAN_INVALID_HANDLE
#define ERRID_DEV_READERROR
#define BAUDRATEID_MOD_CAN_1000K
virtual ~CESDDevice()
destructor
CESDDevice()
default constructor
EXPORT NTCAN_RESULT CALLTYPE canIdAdd(NTCAN_HANDLE handle, int32_t id)
EXPORT NTCAN_RESULT CALLTYPE canSetBaudrate(NTCAN_HANDLE handle, uint32_t baud)
unsigned long m_uiTimeOut
#define NTCAN_NET_NOT_FOUND
int readDevice(CProtocolMessage &rclProtocolMessage)
#define BAUDRATEID_MOD_CAN_500K