#include <stdio.h>
#include <conio.h>
char buf[50];
buf[0] = '\0';
printf("%s: failed, stat=%d (%s)\n", id, (int)stat, buf);
exit(1);
}
}
void dumpMessageLoop(
canHandle hnd,
int channel_number){
long id;
unsigned int dlc, flags;
unsigned char msg[8];
DWORD timestamp;
printf("Listening for messages on channel %d, press any key to close\n", channel_number);
while (!_kbhit()){
stat =
canReadWait(hnd, &
id, msg, &dlc, &flags, ×tamp, 100);
printf("***ERROR FRAME RECEIVED***");
}
else {
printf("Id: %ld, Msg: %u %u %u %u %u %u %u %u length: %u Flags: %lu\n",
id, dlc, msg[0], msg[1], msg[2], msg[3], msg[4],
msg[5], msg[6], msg[7], timestamp);
}
}
Check("canRead", stat);
break;
}
}
}
void main(int argc, int* argv[]){
int channel_number = 0;
printf("Opening channel %d\n", channel_number);
if(hnd < 0){
exit(1);
}
printf("Setting bitrate and going bus on\n");
Check("canSetBusParams", stat);
Check("canBusOn", stat);
dumpMessageLoop(hnd, channel_number);
printf("Going of bus and closing channel");
Check("canBusOff", stat);
Check("canClose", stat);
}