-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcanmanager.cpp
100 lines (89 loc) · 2.42 KB
/
canmanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "canmanager.h"
CanManager::CanManager()
{
}
/**
*函数名:返回单列对象
*函数参数:NULL
*函数作用:NULL
*函数返回值:NULL
*备注:NULL
*/
CanManager *CanManager::GetInstance()
{
static CanManager cm;
return &cm;
}
/**
*函数名:打开CAN
*函数参数:NULL
*函数作用:NULL
*函数返回值:NULL
*备注:NULL
*/
int CanManager::openCan(int deviceTye,int device,int chanel)
{
int ret = RET_OK;
VCI_INIT_CONFIG initConfig;
memset(&initConfig,0,sizeof(initConfig));
initConfig.AccMask = 0xFFFFFFFF;
initConfig.Mode = 0;
initConfig.Timing0 = 0x04;
initConfig.Timing1 = 0x1C;
ret = VCI_OpenDevice(deviceTye,device,chanel);//打开设备,只需要打开一次
RET_VALUE_IF_NOT_EAQU(ret,RET_OK,RET_ERR);
if(0==chanel || 1==chanel)//初始化并开始单通道
{
ret = VCI_InitCAN(deviceTye,device,chanel,&initConfig);//初始化设备
RET_VALUE_IF_NOT_EAQU(ret,RET_OK,RET_ERR);
ret = VCI_StartCAN(deviceTye,device,chanel);//开始采集
RET_VALUE_IF_NOT_EAQU(ret,RET_OK,RET_ERR);
if(0==chanel)
{
can1.setDeviceInfo(deviceTye,device,chanel);
can1.start();
}
else if(1==chanel)
{
can2.setDeviceInfo(deviceTye,device,chanel);
can2.start();
}
}
else if(2==chanel)//初始化和开始双通道
{
ret = VCI_InitCAN(deviceTye,device,0,&initConfig);//初始化设备
RET_VALUE_IF_NOT_EAQU(ret,RET_OK,RET_ERR);
ret = VCI_StartCAN(deviceTye,device,0);//开始采集
RET_VALUE_IF_NOT_EAQU(ret,RET_OK,RET_ERR);
can1.setDeviceInfo(deviceTye,device,0);
can1.start();
ret = VCI_InitCAN(deviceTye,device,1,&initConfig);//初始化设备
RET_VALUE_IF_NOT_EAQU(ret,RET_OK,RET_ERR);
ret = VCI_StartCAN(deviceTye,device,1);//开始采集
RET_VALUE_IF_NOT_EAQU(ret,RET_OK,RET_ERR);
can2.setDeviceInfo(deviceTye,device,1);
can2.start();
}
else
{
ret = RET_ERR;
return ret;
}
return ret;
}
/**
*函数名:关闭CAN
*函数参数:NULL
*函数作用:NULL
*函数返回值:NULL
*备注:NULL
*/
int CanManager::closeCan(int deviceTye,int device)
{
int ret = RET_OK;
ret = VCI_CloseDevice(deviceTye,device);
RET_VALUE_IF_NOT_EAQU(ret,RET_OK,RET_ERR);
can1.setRcvWork(false);
can2.setRcvWork(false);
return ret;
}