Need advice
I’m working on CAN4LINUX trying to use ruby to send and receive CAN
packet but not success.
This is my test codeine RUBY that doesn’t work
a = [0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x06, 0x10,
0x00, 0xE9, 0xED, 0xE2, 0xB6, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
0x00, 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00]
File.open("/dev/can0", ‘wb’ ) do |output|
output.write a.pack(“C*”)
end
C
uint8_t can_pkg[] = {0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x06, 0x10, 0x00, 0xE9, 0xED, 0xE2, 0xB6, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00};
canfd = open("/dev/can0", O_RDWR | O_NOCTTY | O_NONBLOCK);
ret = write(canfd, can_pkg, 1); // ! count is number of frames, not
byte
printf(“write ret = %d\n”, ret);
close(canfd);