/************************************************************************* ** ** Function : Display_Error ** ** Description : Display the CANline Error ** Parameters : HANDLE hResult ** Returnvalue : none ** *************************************************************************/ void Display_Error(HRESULT hResult ) { char szError[VCI_MAX_ERRSTRLEN]; if (hResult != NO_ERROR) { if (hResult == -1) hResult = GetLastError(); szError[0] = 0; vciFormatError(hResult, szError, sizeof(szError)); printf("Error Establishing CAN channel, Error Code: %s\n",szError); } }
int CANDriver::initialize() { CHAR errorBuffer[VCI_MAX_ERRSTRLEN]; HRESULT vciResult; if ( (vciResult = vciInitialize()) != VCI_OK ) { vciFormatError(vciResult, &errorBuffer[0], sizeof(errorBuffer)); emit errorOccured(errorBuffer); return 1; } HANDLE hEnum; if ( (vciResult = vciEnumDeviceOpen(&hEnum)) != VCI_OK ) { vciFormatError(vciResult, &errorBuffer[0], sizeof(errorBuffer)); emit errorOccured(errorBuffer); return 1; } vciEnum_ptr phEnum(&hEnum, vciEnumDeviceClose); VCIDEVICEINFO deviceInfo; if ( (vciResult = vciEnumDeviceNext(hEnum, &deviceInfo)) != VCI_OK ) { vciFormatError(vciResult, &errorBuffer[0], sizeof(errorBuffer)); emit errorOccured(errorBuffer); return 1; } HANDLE hDevice; if ( (vciResult = vciDeviceOpen(deviceInfo.VciObjectId, &hDevice)) != VCI_OK ) { vciFormatError(vciResult, &errorBuffer[0], sizeof(errorBuffer)); emit errorOccured(errorBuffer); return 1; } vciDevice_ptr phDevice(&hDevice, vciDeviceClose); return 0; }