Hello
I have connected the CAN Iot card TALON to a can viewer.
I meet a problem.
I can send 1 can message only. The next message are not sent.
Any idea ??
This is my code (using socket CAN). Very basic…
Hello message is send but not the second message…
int can_loop(void)
{
struct ifreq ifr;
struct sockaddr_can addr;
struct can_frame frame;
int s;
memset(&ifr, 0x0, sizeof(ifr));
memset(&addr, 0x0, sizeof(addr));
memset(&frame, 0x0, sizeof(frame));
/* open CAN_RAW socket /
s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
/ convert interface sting “can0” into interface index /
strcpy(ifr.ifr_name, “can0”);
ioctl(s, SIOCGIFINDEX, &ifr);
/ setup address for bind /
addr.can_ifindex = ifr.ifr_ifindex;
addr.can_family = PF_CAN;
/ bind socket to the can0 interface */
bind(s, (struct sockaddr )&addr, sizeof(addr));
/ first fill, then send the CAN frame */
frame.can_id = 0x23;
strcpy((char )frame.data, “hello”);
frame.can_dlc = 5;
write(s, &frame, sizeof(frame));
/ first fill, then send the CAN frame */
frame.can_id = 0x24;
strcpy((char *)frame.data, “iCC2012”);
frame.can_dlc = 7;
write(s, &frame, sizeof(frame));
close(s);
return 0;
}
COMPONENT_INIT
{
// Run the can-init.sh before advertising the service to ensure that the CAN device is
// available before we allow it to be used.
char line[256];
FILE* fp = popen("can_init.sh 2>&1", "r");
LE_ASSERT(fp != NULL);
while (fgets(line, sizeof(line), fp) != NULL)
{
LE_INFO("can_init.sh output: %s", line);
}
int canInitResult = pclose(fp);
LE_FATAL_IF(!WIFEXITED(canInitResult), "Could not run can_init.sh");
const int canInitExitCode = WEXITSTATUS(canInitResult);
LE_FATAL_IF(canInitExitCode != 0, "can_init.sh failed with exit code %d", canInitExitCode);
can_loop();
}