Hi all,
I am trying to send data from CAN0 to CAN1 in NVIDIA Jetson TX2. I have followed the following steps:
- sudo modprobe can
- sudo modprobe can_raw
- sudo modprobe can_dev
- sudo modprobe mttcan
- ifconfig
This shows CAN0 and CAN1 interfaces are up. Data is transferred successfully by terminal using command
cansend can0 123#abcdabcd. Now, I have written a small program .c program for same as follows:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<string.h>
void main()
{ char buf[20];
size_t nbytes;
ssize_t bytes_written;
int fd;
strcpy(buf, “This is a test\n”);
nbytes = strlen(buf);
bytes_written = write(fd, buf, nbytes);
printf(“%d”,bytes_written);
}
OUTPUT : -1
I don’t want the write function to return -1. what could go wrong?