Changeset 116 in pacpussensors for trunk/CanGateway/driver/KVaserCanDriver.cpp
- Timestamp:
- Dec 16, 2015, 4:57:50 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CanGateway/driver/KVaserCanDriver.cpp
r94 r116 4 4 5 5 #include "KVaserCanDriver.h" 6 /* 6 7 #ifdef WIN32 7 8 #include "kvaser/windows/canlib.h" … … 9 10 #include "kvaser/linux/canlib.h" 10 11 #endif 12 */ 13 14 15 #include <canlib.h> 16 11 17 #include <cassert> 12 18 #include <cstdio> … … 44 50 // Check a status code and issue an error message if the code isn't canOK. 45 51 // 46 void ErrorExit( char*id, canStatus stat)52 void ErrorExit(string id, canStatus stat) 47 53 { 48 54 char buf[50]; … … 123 129 124 130 125 void KVaserCanDriver::displayHardware() 131 void KVaserCanDriver::displayHardware() 126 132 { 127 133 LOG_INFO("----------------------------------------------------------"); … … 139 145 canHandle_ = canOpenChannel(hwChannel, 0); 140 146 if (canHandle_ < 0) { 141 ErrorExit("canOpenChannel", (canStatus) canHandle_);147 ErrorExit("canOpenChannel", (canStatus) canHandle_); 142 148 } 143 else 149 else 144 150 { 145 151 int ret = 0; … … 153 159 break; 154 160 case 500000: 155 ret = canSetBusParams(canHandle_, canBITRATE_500K, 0, 0, 0, 0, 0);161 ret = canSetBusParams(canHandle_, canBITRATE_500K, 4, 3, 1, 1, 0); 156 162 break; 157 163 default: … … 166 172 if (ret < 0) { 167 173 ErrorExit("canBusOn", (canStatus)ret); 168 174 169 175 } 170 176 } … … 184 190 canInitializeLibrary(); 185 191 #endif 186 192 187 193 // open the physical CAN interface 188 194 initialize(kvaserHardwareType_, canChannel_, canBitRate_); … … 199 205 short KVaserCanDriver::cleanUpPort (void) 200 206 { 201 207 202 208 //traceXLCommand("xlCloseDriver", xlCloseDriver()); 203 209 … … 215 221 { 216 222 canStatus stat = canWrite(canHandle_, frame.id,frame.data, frame.dlc, 0); 217 if (stat == canOK ) 223 if (stat == canOK ) 218 224 { 219 225 return 0; 220 226 } else { 221 227 LOG_WARN("Kvaser driver - sendFrame method - Failed to send the CAN frame"); 222 return 1; 228 return 1; 223 229 } 224 230 } … … 236 242 //DWORD timestamp; 237 243 unsigned long timestamp; 238 244 239 245 canStatus stat = canReadWait(canHandle_, &id, msg, &dlc, &flags, ×tamp, WAIT_RECEIVING_FRAME_TIMEOUT); 240 if (stat == canOK ) 246 if (stat == canOK ) 241 247 { 242 if ((flags & canMSG_ERROR_FRAME) == 0) 248 if ((flags & canMSG_ERROR_FRAME) == 0) 243 249 { 244 250 // Get the message data … … 254 260 memcpy(frame.data, msg, frame.dlc); 255 261 return 0; 256 } 257 } 262 } 263 } 258 264 else if (stat == canERR_NOMSG ) { 259 265 // timeout occurs 260 266 LOG_WARN("Kvaser card - receiveFrame() method - TIMEOUT"); 261 267 return 1; 262 } 268 } 263 269 else { 264 270 // An error frame.
Note:
See TracChangeset
for help on using the changeset viewer.