- viewthread_userinfo_credits
- 12
|
Trying to set up the USB-CAN Interface Adapter on Rasbian using C++.
Installed Rasppi Extend on rasbian. Running runme_en.sh works fine. The software sends and receives CAN messages to and from my laptop.
Using GNU C Compiler. Used viewtools code from Git. Running the code, I can connect to the Gingko USB-CAN Interface Adapter, but when I try to initialze it, it errors out.
Here is the code:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ControlCAN.h"
#include <stdio.h>
#define
CAN_MODE_LOOP_BACK
0
#define
CAN_SEND_DATA
1
#define CAN_GET_BOARD_INFO
1
#define CAN_READ_DATA
1
#define CAN_CALLBACK_READ_DATA
0
#define CAN_GET_STATUS
1
int main(void)
{
int DevNum,Status;
//Scan device
DevNum = VCI_ScanDevice(1);
if(DevNum > 0){
printf("Have %d device connected!\n",DevNum);
}else{
printf("No device connected!\n");
return 0;
}
VCI_INIT_CONFIG_EX
CAN_InitEx;
VCI_ERR_INFO ErrInfo;
//Config device
//CAN_InitEx.CAN_ABOM = 0;
CAN_InitEx.CAN_ABOM = 1;
#if CAN_MODE_LOOP_BACK
CAN_InitEx.CAN_Mode = 1;
#else
CAN_InitEx.CAN_Mode = 0;
#endif
//1Mbps
CAN_InitEx.CAN_BRP = 6;//9;//6;
CAN_InitEx.CAN_BS1 = 3;//2;//3;
CAN_InitEx.CAN_BS2 = 2;//1;//2;
CAN_InitEx.CAN_SJW = 1;
CAN_InitEx.CAN_NART = 0;
CAN_InitEx.CAN_RFLM = 1;
CAN_InitEx.CAN_TXFP = 1;
CAN_InitEx.CAN_RELAY = 0;
Status = VCI_InitCANEx(VCI_USBCAN2,0,0,&CAN_InitEx);
if(Status==STATUS_ERR){
printf("1. Init device failed!\n");
Status = VCI_ReadErrInfo(VCI_USBCAN2,0,0,&ErrInfo);
printf("Error Code: %d\n", ErrInfo.ErrCode);
return 0;
}else{
printf("Init device success!\n");
}
}
Here are the results:
pi@raspberrypi:~/projects/LCE_CAN_Test1 $ sudo ./runme.sh
/home/pi/projects/LCE_CAN_Test1/lib:
Have 1 device connected!
1. Init device failed!
Error Code: 1024
What is error 1024?
Any suggestions to make this work?
|
|