Skip to content

Commit c173a2a

Browse files
author
ChenSZ
committed
modify zlg/2 openchannel 1st is can_index
1 parent a4f8756 commit c173a2a

File tree

6 files changed

+55
-26
lines changed

6 files changed

+55
-26
lines changed

CANZLG.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ CANStatus CANZLG::OpenChannel(int channel, CANRate baudRate, int type) {
1212

1313
CANStatus CANZLG::OpenChannel(int channel, CANRate baudRate, int argc,
1414
char* argv[]) {
15-
can_index = 0;
16-
device_index = channel;
15+
can_index = channel;
16+
device_index = 0;
1717
device_type = 0;
1818
if (argc > 1) {
19-
can_index = *(UINT*)argv[1];
19+
device_index = *(UINT*)argv[1];
2020
}
2121
if (argc > 0) {
2222
device_type = *(UINT*)argv[0];

CANZLG.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class CANZLG : public CANBase {
1818
CANZLG();
1919
~CANZLG();
2020
/**
21-
* @param channel Indicates device_index
21+
* @param channel Indicates can_index
2222
* @param type Indicates device_type
2323
* @see <controlcan.h>
2424
*/
2525
CANStatus OpenChannel(int channel, CANRate baudRate, int type = 0) override;
2626

2727
/**
28-
* @param channel Indicates device_index
29-
* @param argv Indicates device_type, can_index.
28+
* @param channel Indicates can_index
29+
* @param argv Indicates device_type, device_index.
3030
* Default 0.
3131
* @see <controlcan.h>
3232
*/

CANZLG2.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ CANStatus CANZLG2::OpenChannel(int channel, CANRate baudRate, int type) {
1212

1313
CANStatus CANZLG2::OpenChannel(int channel, CANRate baudRate, int argc,
1414
char* argv[]) {
15-
UINT can_index = 0;
16-
UINT device_index = channel;
15+
UINT can_index = channel;
16+
UINT device_index = 0;
1717
UINT device_type = 0;
1818
if (argc > 1) {
19-
can_index = *(UINT*)argv[1];
19+
device_index = *(UINT*)argv[1];
2020
}
2121
if (argc > 0) {
2222
device_type = *(UINT*)argv[0];

CANZLG2.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22
#ifndef __CANBase_ZLG2_H
33
#define __CANBase_ZLG2_H
4-
#include "CANBase.h"
5-
#include <thread>
64
#include <zlgcan/zlgcan.h>
5+
#include <thread>
6+
#include "CANBase.h"
77
namespace ZCANBus {
88
class CANZLG2 : public CANBase {
99
private:
@@ -16,17 +16,17 @@ class CANZLG2 : public CANBase {
1616
CANZLG2();
1717
~CANZLG2();
1818
/**
19-
* @param channel Indicates device_index
19+
* @param channel Indicates can_index
2020
* @param type Indicates device_type
21-
* @see <zlgcan.h>
21+
* @see <zlgcan.h>
2222
*/
2323
CANStatus OpenChannel(int channel, CANRate baudRate, int type = 0) override;
2424

2525
/**
26-
* @param channel Indicates device_index
27-
* @param argv Indicates device_type, can_index.
26+
* @param channel Indicates can_index
27+
* @param argv Indicates device_type, device_index.
2828
* Default 0.
29-
* @see <zlgcan.h>
29+
* @see <zlgcan.h>
3030
*/
3131
CANStatus OpenChannel(int channel, CANRate baudRate, int argc,
3232
char* argv[]) override;

CMakeLists.txt

+38-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ project(ZCANBus)
33

44
set(CMAKE_CXX_STANDARD 11)
55

6-
# set(USE_PEAK true)
6+
# set(PEAK_WANTED true)
77

8-
# set(USE_KVASER true)
8+
# set(KVASER_WANTED true)
99

10-
# set(USE_ZLG true)
10+
# set(ZLG_WANTED true)
1111

12-
# set(USE_ZLG2 true)
12+
# set(ZLG2_WANTED true)
13+
14+
# set(PEAK_UNWANTED true)
15+
16+
# set(KVASER_UNWANTED true)
17+
18+
# set(ZLG_UNWANTED true)
19+
20+
# set(ZLG2_UNWANTED true)
1321

1422
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
1523
set(_COMPILER_ARCHITECTURE x64)
@@ -22,10 +30,31 @@ set(CAN_FILE CANHandler.cpp)
2230

2331
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
2432

25-
find_package(Peak)
26-
find_package(Kvaser)
27-
find_package(ZLG)
28-
find_package(ZLG2)
33+
if(PEAK_WANTED)
34+
set(PEAK_REQUIRED REQUIRED)
35+
endif()
36+
if(KVASER_WANTED)
37+
set(KVASER_REQUIRED REQUIRED)
38+
endif()
39+
if(ZLG_WANTED)
40+
set(ZLG_REQUIRED REQUIRED)
41+
endif()
42+
if(ZLG2_WANTED)
43+
set(ZLG2_REQUIRED REQUIRED)
44+
endif()
45+
46+
if(NOT PEAK_UNWANTED)
47+
find_package(Peak ${PEAK_REQUIRED})
48+
endif()
49+
if(NOT KVASER_UNWANTED)
50+
find_package(Kvaser ${KVASER_REQUIRED})
51+
endif()
52+
if(NOT ZLG_UNWANTED)
53+
find_package(ZLG ${ZLG_REQUIRED})
54+
endif()
55+
if(NOT ZLG2_UNWANTED)
56+
find_package(ZLG2 ${ZLG2_REQUIRED})
57+
endif()
2958

3059
if(Peak_FOUND)
3160
add_definitions(-DUSE_PEAK)
@@ -59,5 +88,5 @@ if(CMAKE_HOST_UNIX)
5988
link_libraries(pthread)
6089
endif(CMAKE_HOST_UNIX)
6190

62-
set(CMAKE_DEBUG_POSTFIX _d)
91+
# set(CMAKE_DEBUG_POSTFIX _d)
6392
add_library(${PROJECT_NAME} ${CAN_FILE})

FindZLG.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ find_path(ZLG_INCLUDE_DIR controlcan.h PATH_SUFFIXES ZLG)
33
find_library(ZLG_LIBS NAMES usbcan PATH_SUFFIXES MS x64 x86 win32)
44
elseif(CMAKE_HOST_UNIX)
55
find_path(ZLG_INCLUDE_DIR NAMES controlcan.h PATH_SUFFIXES ZLG)
6-
find_library(ZLG_LIBS NAMES usbcan)
6+
find_library(ZLG_LIBS NAMES usbcan controlcan)
77
else()
88
message(FATAL_ERROR "Unsupported OS " ${CMAKE_SYSTEM_NAME})
99
endif(CMAKE_HOST_WIN32)

0 commit comments

Comments
 (0)