示例#1
0
//-------------------------------------------
bool CANPeakSysUSB::transmitMsg(CanMsg CMsg, bool bBlocking)
{
	TPCANMsg TPCMsg;
	bool bRet = true;

	if (m_bInitialized == false) return false;

	// copy CMsg to TPCmsg
	TPCMsg.LEN = CMsg.m_iLen;
	TPCMsg.ID = CMsg.m_iID;
	TPCMsg.MSGTYPE = CMsg.m_iType;
	for(int i=0; i<8; i++)
		TPCMsg.DATA[i] = CMsg.getAt(i);
	
	//TODO Hier stürtzt die Base ab.. verwende libpcan.h pcan.h um Fehler auszulesen, diagnostizieren, ausgeben und CAN_INIT erneut aufzurufen = neustart can-hardware. 
	
	int iRet;
	//iRet = CAN_Write(m_handle, &TPCMsg);
	iRet = LINUX_CAN_Write_Timeout(m_handle, &TPCMsg, 25); //Timeout in micrsoseconds
	
	if(iRet != CAN_ERR_OK) {
#ifdef __DEBUG__
		std::cout << "CANPeakSysUSB::transmitMsg An error occured while sending..." << iRet << std::endl;		
		outputDetailedStatus();
#endif		
		bRet = false;
	}

#ifdef __DEBUG__	
	//is this necessary? try iRet==CAN_Status(m_handle) ?
	iRet = CAN_Status(m_handle);

	if(iRet < 0)
	{
		std::cout <<  "CANPeakSysUSB::transmitMsg, system error: " << iRet << std::endl;
		bRet = false;
	} else if((iRet & CAN_ERR_BUSOFF) != 0) {
		std::cout <<  "CANPeakSysUSB::transmitMsg, BUSOFF detected" << std::endl;
		//Try to restart CAN-Device
		std::cout <<  "Trying to re-init Hardware..." << std::endl;
		bRet = initCAN();
	
	} else if((iRet & CAN_ERR_ANYBUSERR) != 0) {
		std::cout <<  "CANPeakSysUSB::transmitMsg, ANYBUSERR" << std::endl;
	
	} else if( (iRet & (~CAN_ERR_QRCVEMPTY)) != 0) {
		std::cout << "CANPeakSysUSB::transmitMsg, CAN_STATUS: " << iRet << std::endl;
		bRet = false;
	}
#endif

	return bRet;
}
示例#2
0
文件: PcanPci.cpp 项目: nixz/covise
bool PcanPci::sendFrame(TPCANMsg &msg)
{
#ifdef WIN32
    int errorcode = CAN_Write(pcanHandle, &msg);
#else
    int errorcode = LINUX_CAN_Write_Timeout(pcanHandle, &msg, 100000);
#endif
    if (errorcode == 0)
    {
        //std::cerr << "Sent "; printMsg(msg);
        return true;
    }
    else
    {
        std::cerr << "sendFrame error, code: " << std::hex << errorcode << std::endl;
        return false;
    }
}