22 #include <sys/types.h> 60 std::string sCanDevice;
62 sCanDevice =
"/dev/pcan32";
63 }
else std::cout <<
"CAN-device path read from ini-File: " << sCanDevice << std::endl;
64 m_handle = LINUX_CAN_Open(sCanDevice.c_str(), O_RDWR);
70 std::cout <<
"Cannot open CAN-dongle on parallel port: " << strerror(errno) << std::endl;
83 ret = CAN_Init(
m_handle, CAN_BAUD_1M, CAN_INIT_TYPE_ST);
86 ret = CAN_Init(
m_handle, CAN_BAUD_500K, CAN_INIT_TYPE_ST);
89 ret = CAN_Init(
m_handle, CAN_BAUD_250K, CAN_INIT_TYPE_ST);
92 ret = CAN_Init(
m_handle, CAN_BAUD_125K, CAN_INIT_TYPE_ST);
95 ret = CAN_Init(
m_handle, CAN_BAUD_50K, CAN_INIT_TYPE_ST);
98 ret = CAN_Init(
m_handle, CAN_BAUD_20K, CAN_INIT_TYPE_ST);
101 ret = CAN_Init(
m_handle, CAN_BAUD_10K, CAN_INIT_TYPE_ST);
107 std::cout <<
"CanPeakSys::CanPeakSys(), error in init" << std::endl;
111 std::cout <<
"CanPeakSys::CanpeakSys(), init ok" << std::endl;
126 TPCMsg.ID = CMsg.
m_iID;
128 for(
int i=0; i<8; i++)
129 TPCMsg.DATA[i] = CMsg.
getAt(i);
133 iRet = CAN_Write(
m_handle, &TPCMsg);
138 std::cout <<
"CanPeakSys::transmitMsg, errorcode= " << nGetLastError() << std::endl;
151 TPCMsg.Msg.MSGTYPE = 0;
154 int iRet = CAN_ERR_OK;
160 iRet = LINUX_CAN_Read_Timeout(
m_handle, &TPCMsg, 0);
162 if (iRet == CAN_ERR_OK)
164 pCMsg->
m_iID = TPCMsg.Msg.ID;
165 pCMsg->
set(TPCMsg.Msg.DATA[0], TPCMsg.Msg.DATA[1], TPCMsg.Msg.DATA[2], TPCMsg.Msg.DATA[3],
166 TPCMsg.Msg.DATA[4], TPCMsg.Msg.DATA[5], TPCMsg.Msg.DATA[6], TPCMsg.Msg.DATA[7]);
169 else if (CAN_Status(
m_handle) != CAN_ERR_QRCVEMPTY)
171 std::cout <<
"CanPeakSys::receiveMsg ERROR: iRet = " << iRet << std::endl;
172 pCMsg->
set(0, 0, 0, 0, 0, 0, 0, 0);
177 pCMsg->
set(0, 0, 0, 0, 0, 0, 0, 0);
190 TPCMsg.Msg.MSGTYPE = 0;
201 iRet = LINUX_CAN_Read_Timeout(
m_handle, &TPCMsg, 0);
203 if(iRet == CAN_ERR_OK)
209 while(i < iNrOfRetry);
212 if(iRet != CAN_ERR_OK)
214 std::cout <<
"CanPeakSys::receiveMsgRetry: " << strerror(errno) << std::endl;
215 pCMsg->
set(0, 0, 0, 0, 0, 0, 0, 0);
220 pCMsg->
m_iID = TPCMsg.Msg.ID;
221 pCMsg->
set(TPCMsg.Msg.DATA[0], TPCMsg.Msg.DATA[1], TPCMsg.Msg.DATA[2], TPCMsg.Msg.DATA[3],
222 TPCMsg.Msg.DATA[4], TPCMsg.Msg.DATA[5], TPCMsg.Msg.DATA[6], TPCMsg.Msg.DATA[7]);
231 int iRet = CAN_ERR_OK;
235 TPCMsg.Msg.MSGTYPE = 0;
242 iRet = LINUX_CAN_Read_Timeout(
m_handle, &TPCMsg, nMicroSecTimeout);
245 if(iRet != CAN_ERR_OK)
247 std::cout <<
"CANPeakSysUSB::receiveMsgRetry, errorcode= " << nGetLastError() << std::endl;
248 pCMsg->
set(0, 0, 0, 0, 0, 0, 0, 0);
253 pCMsg->
setID(TPCMsg.Msg.ID);
255 pCMsg->
set(TPCMsg.Msg.DATA[0], TPCMsg.Msg.DATA[1], TPCMsg.Msg.DATA[2], TPCMsg.Msg.DATA[3],
256 TPCMsg.Msg.DATA[4], TPCMsg.Msg.DATA[5], TPCMsg.Msg.DATA[6], TPCMsg.Msg.DATA[7]);
bool receiveMsg(CanMsg *pCMsg)
bool transmitMsg(CanMsg CMsg, bool bBlocking=true)
bool receiveMsgTimeout(CanMsg *pCMsg, int nSecTimeout)
static const int c_iInterrupt
int GetKeyInt(const char *pSect, const char *pKey, int *pValue, bool bWarnIfNotfound=true)
bool receiveMsgRetry(CanMsg *pCMsg, int iNrOfRetry)
int SetFileName(std::string fileName, std::string strIniFileUsedBy="", bool bCreate=false)
void set(BYTE Data0=0, BYTE Data1=0, BYTE Data2=0, BYTE Data3=0, BYTE Data4=0, BYTE Data5=0, BYTE Data6=0, BYTE Data7=0)
int GetKeyString(const char *pSect, const char *pKey, std::string *pStrToRead, bool bWarnIfNotfound=true)
CanPeakSys(const char *cIniFile)