15 KvaserCan::KvaserCan() :
18 handle = malloc(
sizeof(canHandle));
44 canHandle *h = (canHandle *)
handle;
47 if (canGetNumberOfChannels(&numChan) != canOK)
52 unsigned int serial[2];
53 unsigned int channel_number;
56 for (
int idx = 0; idx < numChan; idx++)
58 if (canGetChannelData(idx, canCHANNELDATA_CARD_SERIAL_NO, &serial,
sizeof(serial)) == canOK)
62 if (canGetChannelData(idx, canCHANNELDATA_CHAN_NO_ON_CARD, &channel_number,
sizeof(channel_number)) == canOK)
64 if (channel_number == (
unsigned int)
circuit_id)
79 *h = canOpenChannel(channel, canOPEN_ACCEPT_VIRTUAL);
89 case 125000: freq = canBITRATE_125K;
break;
90 case 250000: freq = canBITRATE_250K;
break;
91 case 500000: freq = canBITRATE_500K;
break;
92 case 1000000: freq = canBITRATE_1M;
break;
99 if (canSetBusParams(*h, freq, 0, 0, 0, 0, 0) < 0)
109 unsigned char off = 0;
110 canIoCtl(*h, canIOCTL_SET_LOCAL_TXECHO, &off, 1);
114 canSetBusOutputControl(*h, canDRIVER_NORMAL);
148 canHandle *h = (canHandle *)
handle;
151 if (canClose(*h) != canOK)
172 canHandle *h = (canHandle *)
handle;
176 unsigned int flag = 0;
180 canStatus ret = canRead(*h,
id, msg, size, &flag, time);
182 if (ret == canERR_NOTINITIALIZED)
188 else if (ret == canERR_NOMSG)
193 else if (ret != canOK)
198 else if (!(flag & 0xF9))
210 *extended = ((flag & canMSG_EXT) > 0);
218 const unsigned int& size,
219 const bool& extended)
226 canHandle *h = (canHandle *)
handle;
239 canStatus ret = canWrite(*h,
id, msg, size, flag);
return_statuses open(const int &hardware_id, const int &circuit_id, const int &bitrate, const bool &echo_on=true)
return_statuses read(long *id, unsigned char *msg, unsigned int *size, bool *extended, unsigned long *time)
return_statuses write(const long &id, unsigned char *msg, const unsigned int &size, const bool &extended)