From: Leo Stan <leo.stanislas@qut.edu.au>
To: linux-can@vger.kernel.org
Subject: Re: kvaser leaf and SocketCAN
Date: Thu, 30 Apr 2015 06:14:35 +0000 (UTC) [thread overview]
Message-ID: <loom.20150430T080326-120@post.gmane.org> (raw)
In-Reply-To: loom.20150430T051006-395@post.gmane.org
Actually I spoke too soon...
When I try this simple code from the documentation :
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/can.h>
#include <linux/can/raw.h>
int main(void)
{
int s;
int nbytes;
struct sockaddr_can addr;
struct can_frame frame;
struct ifreq ifr;
char *ifname = "can0";
if((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
perror("Error while opening socket");
return -1;
}
strcpy(ifr.ifr_name, ifname);
ioctl(s, SIOCGIFINDEX, &ifr);
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
printf("%s at index %d\n", ifname, ifr.ifr_ifindex);
if(bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("Error in socket bind");
return -2;
}
// Reading the CAN port
nbytes=read(s,&frame,sizeof(struct can_frame));
if (nbytes < 0) {
perror("can raw socket read");
return 1;
}
/* paranoid check ... */
if (nbytes < sizeof(struct can_frame)) {
fprintf(stderr, "read: incomplete CAN frame\n");
return 1;
}
printf("dlc = %d, data = %s, %d bytes read\n",
frame.can_dlc,frame.data,nbytes);
close(s);
return 0;
}
I get this flag :
can0 at index 3
can raw socket read: Network is down
Which means that nothing has been read from the CAN I guess, however I'm
sure that data comes from it because I can see it using CANking software on
Windows.
When I run "ifconfig -a" RX and TX are also empty:
can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-
00-00-00
NOARP MTU:16 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Here are the settings of my BUS on Canking :
No init access
Speed : 500000 Bit/s
Bit timing : Q=8, S1=5,S2=3,Sampling point= 62.5%, SJW=1
DLC = 8
Any help would be really appreciated
next prev parent reply other threads:[~2015-04-30 6:14 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-22 7:31 kvaser leaf and SocketCAN max
2015-04-22 8:03 ` Marc Kleine-Budde
2015-04-29 2:01 ` Leo Stan
2015-04-29 3:50 ` Austin Schuh
2015-04-29 4:39 ` Leo Stan
2015-04-29 5:20 ` Marc Kleine-Budde
2015-04-29 6:15 ` Leo Stan
2015-04-29 6:33 ` Alexander Stein
2015-04-29 6:34 ` Marc Kleine-Budde
2015-04-29 10:45 ` Ahmed S. Darwish
2015-04-30 3:11 ` Leo Stan
2015-04-30 6:04 ` Marc Kleine-Budde
2015-04-30 6:14 ` Leo Stan [this message]
2015-04-30 6:25 ` Leo Stan
2015-04-30 6:48 ` Marc Kleine-Budde
2015-04-30 7:27 ` Oliver Hartkopp
2015-05-04 1:52 ` Leo Stan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=loom.20150430T080326-120@post.gmane.org \
--to=leo.stanislas@qut.edu.au \
--cc=linux-can@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox