Moxa TC-SW04-M12-4P-T [27/43] Tc cp02 db t configuring the socket can interface

Moxa TC-SW04-M12-8P [27/43] Tc cp02 db t configuring the socket can interface
TC-6000 Series Expansion Modules Software Installation and Programming Guide
4-7
extends the Berkeley sockets API in Linux by introducing a new protocol family, PF_CAN, that coexists with
other protocol families like PF_INET for the Internet Protocol.
You can use the file control interface to read, write or control the CAN interface as a file for easy CAN
programming.
TC-CP02-DB-T: Driver Installation
The drivers for Moxa TC-SP04-DB44-T module include can.ko, can_raw.ko, can_bcm.ko, can_dev.ko,
sja1000.ko, and plx-pci.ko . These have all been pre-installed under:
/lib/modules/3.2.0-4-686-pae/updates/drivers/net/can
Some drivers will be loaded by the boot process when modules are inserted; others must be loaded manually,
using modprobe:
Moxa:~# modprobe can
Moxa:~# modprobe can_raw
Moxa:~# modprobe can_bcm
You may set modules to load automatically at boot by listing them in the /etc/modules file.
TC-CP02-DB-T: Configuring the Socket CAN Interface
After the modules have been loaded, the next step is to configure the CAN interface and start it as a standard
net interface. Heres an example with bitrate 12500:
# ip link set can0 up type can bitrate 12500
# ip link set can1 up type can bitrate 12500
The SocketCAN information is stored under /proc/net/can; you can determine what version is being used by
using the cat command:
Moxa~:# cat /proc/net/can/version
and return usage/operating statistics thus:
Moxa~:# cat /proc/net/can/stats
TC-CP02-DB-T: Sample Script for the SocketCAN API
The following code is a working example of the SocketCAN API in use; this code sends a CAN packet using the
raw interface. It is based on the notes documented in the Linux Kernel
(https://www.kernel.org/doc/Documentation/networking/can.txt).
#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;

Содержание

Скачать