==================== Programs and scripts ==================== .. _reference_init_can: init-can.sh ----------- This program is used to set up your CAN bus device. Here is the online help from the program:: $ ./init-can.sh -h init-can.sh - initialize CAN interfaces This script initializes one or several CAN interfaces. Usage: init-can.sh [OPTIONS] Known options: -h : this help -d --driver DRIVER : specify the CAN driver to use (mandatory) Known values for DRIVER are: - vcan : virtual CAN interface from standard linux kernel - none : do not load a driver, just try to initialize CAN ports named 'can' - peak : peak_pciefd driver from standard linux kernel for the PEAK PCAN-PCI Express FD card - peak-usb : peak_usb driver from standard linux kernel for the PEAK USB adapters - pcan : proprietary driver from PEAK Systems built from source You can also provide an arbitary name for DRIVER, the script will then try to load this kernel module. The script assumes that physical CAN interfaces are always named 'can0', 'can1', 'can2'... and that virtual CAN interfaces are named 'vcan0', 'vcan1', 'vcan2'... -p --ports STARTPORT [ENDPORT]: define a port range or a single port The CAN devicenames used are can or vcan. -b --bitrate BITRATE: define a bitrate, default is 1000000 -n --dry-run : show what the script would do This script requires that you have 'sudo' permissions The script can initialize physical CAN interfaces and virtual CAN interfaces. It loads the kernel module, sets the bitrate and brings up the interface. An interface is adressed just with a port number, starting with 0. Examples: Initialize virtual CAN interfaces port 0 to 3:: init-can.sh -d vcan -p 0 3 Initialize physical CAN interfaces for PEAK-PCI port 0 to 3:: init-can.sh -d peak -p 0 3 Set bitrate for port 2 to 500KBit:: init-can.sh -d peak -p 2 -b 500000 Initialize physical CAN interfaces for PEAK-USB port 0, 1MBit:: init-can.sh -d peak-usb -p 0 3 -b 1000000 .. _reference_show_can_devices: show-can-devices.sh ------------------- This script shows all CAN devices in your system. Here is the online help from the program:: $ ./show-can-devices.sh -h show-can-devices.sh - show CAN bus devices This lists CAN Bus devices if they exist. Usage: show-can-devices.sh [OPTIONS] Known options: -h : this help You usually run the program without any arguments or options, here is an example:: $ ./show-can-devices.sh 8: can0: mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/can 9: can1: mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/can can-state.sh ------------ This script shows detailed information on a CAN interface. Here is the online help from the program:: $ ./can-state.sh -h can-state.sh - Show the state of CAN devices Usage: can-state.sh [OPTIONS] Known options: -h : this help -p --ports STARTPORT [ENDPORT]: define a port range or a single port The CAN devicenames used are for physical CAN devices and vcan for virtual CAN devices. --virtual : Use device name for virtual CAN device. Here is an example:: $ ./can-state.sh -p 0 8: can0: mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0 can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 bitrate 1000000 sample-point 0.750 tq 12 prop-seg 29 phase-seg1 30 phase-seg2 20 sjw 10 brp 1 peak_canfd: tseg1 1..256 tseg2 1..128 sjw 1..128 brp 1..1024 brp_inc 1 peak_canfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..1024 dbrp_inc 1 clock 80000000 re-started bus-errors arbit-lost error-warn error-pass bus-off 0 0 0 0 0 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 gso_ipv4_max_size 65536 gro_ipv4_max_size 65536 parentbus pci parentdev 0000:05:00.0 RX: bytes packets errors dropped missed mcast 4 1 0 0 0 0 TX: bytes packets errors dropped carrier collsns 4016 1003 0 0 0 0 .. _reference_link_vcan_devices: link-vcan-devices.sh -------------------- This script creates a virtual link between two *virtual* CAN interfaces. Here is the online help from the program:: $ ./link-vcan-devices.sh -h link-vcan-devices.sh - link virtual CAN interfaces This script creates or deletes virtual connections between two virtual CAN interfaces. Usage: link-vcan-devices.sh [OPTIONS] COMMAND PORT1 PORT2 Known commands: link : link devices vcan and vcan unlink : remove link between devices vcan and vcan show : show defined cangw rules Known options: -h : this help -n --dry-run : show what the script would do This script requires that you have 'sudo' permissions .. _reference_sotest: sotest ------ .. hint:: If you just want to read or dump CAN data do also have a look at `candump `_, part of the "can-utils" package This tests the socan library. Here is the online help from the program:: $ ./sotest -h **** sotest 1.0 **** the socan test program usage: sotest {options} options: **************** Configuration***************** --interface,-i INTERFACE Use INTERFACE for CAN communication, this option can be given more than once to use more than one interface. --realtime READER-PRIORITY WRITER-PRIORITY Use given realtime priorities for reader and writer thread. --leave [SECONDS] for all functions that define CAN-objects, hold the program just before close() is performed. All CAN objects remain defined. End the program with CRTL-C in this case --trace,-t LEVEL set trace level, LEVEL is an integer 0..2 (default 0) --errprintlevel,-E LEVEL set errprint level, LEVEL is an integer 0..3 (default 1) *************** command options *************** --loop {no of loops} run read, write, readnow or readmany in loop-mode --loopdelay {delay} delay each loop by the given number of seconds. seconds may be a floating point number. --sleep {seconds} sleep a number of seconds before starting the test. seconds may be a floating point number. --quiet,-q {level} Run read, write, readnow or readmany in quiet-mode level may be 1 .. 5, meaning that each 10**(level-1) events print a single character on the screen. Level 0 means no printing at all. --timestamp Print a the timestamp for each sent or received CAN object. --stats run read, readnow or readmany in statistic mode. Print number of transmits and errors. --maxlossrate [number] print a warning when the ratio of lost CAN objects for read functions is bigger than [number]. --check check sequence in --read, (must be used together with --write in another sotest-task --size,-s [bytes] use [bytes] bytes to transfer and receive data --count [number] use [number] as initial number to write with -w --consistence send alternating 8 bytes of 0xFF or 0x00 to test data consistence --remote do remote-read or remote-write, implemented for --write and --read --ignore_old ignore the SOCAN_OLD-flag ***************data transmission commands**************** --rwtest [object1] [port1] [object2] [port2] [write-timeout] [read-timeout] make a write-object (object1,port1) and a read-object (object2,port2) with a timeout set for the 2nd object then write 8 bytes (values 1 to 8) and read the 2nd object (read immediately) and return the results --write,-w [object] [port] [timeout] write data (a running counter) --writelater [object] [port] [timeout] similar to write, but writelater returns immediately, without waiting for the actual access of the CAN-bus. Note: writelater returns only errors that are valid for the PREVIOUS writelater !!! --writelater-w [object] [port] [timeout] the same as --writelater but do silently retry to write when the driver returns a SOCAN_WAIT status. --writeinhibit [object] [port] [timeout] [inhibit-time] similar to writelater, but the CAN-object gets a timestamp when it is transmitted. Inhibit-time is the minumum time that has to pass before a new object is sent. This concerns only writeinhibit combined with the loop-command. In this case only about every [inhibit-time] microseconds new data will be sent (note that the unit for this parameter is microseconds, not milliseconds --writertr [object] [port] [timeout] Just write an RTR frame on a CAN object. --read,-r [object] [port] [timeout] read data from an object (blocking). --readnow [object] [port] [timeout] read data from an object (immediately). --queue-read [port] [timeout] [object] {[object]} read more than one object via the signal-function in conjunction with the new queue-read operation together with --remote, all objects will be remote-read objects ******************** miscellaneous tests **************** --bitrate [port] get bitrate of a port Note that you have to specify *each* can device you intend to use with option "-i". All devices get a port number in the order they are given. See also the "rwtest" example. Examples ++++++++ All examples presume that sotest is in your file search path (PATH). RW-Test: Test writing COB 0 on CAN port 0 and receiving it on CAN port 1 with a timeout of 1000ms each:: $ sotest -i can0 -i can1 --rwtest 0 0 0 1 1000 1000 opening driver : 8 bytes will be written, content of these 8 bytes: 1 2 3 4 5 6 7 8 set write-mode for object 0, port 0 ...(timeout 1000) done set read-mode for object 0, port 1 ...(timeout 1000) done now writing the data...done now reading the data...done message-content: 0: 1 2 3 4 5 6 7 8 " " closing driver... Write a single CAN object with COB 123 on port 0 and timeout 1000ms:: $ sotest -i can0 -w 123 0 1000 opening driver : defining write-object... done writing 0, 4 bytes on 123 closing driver... Do the same, but write 1000 CAN objects very fast, print a single character on the console every 100 CAN frames:: $ sotest -i can0 -w 123 0 1000 -q 3 --loop 1000 opening driver : defining write-object... done one 'O' are 100 loops! OOOOOOOOOO closing driver... Read and receive a single CAN object with COB 123 on port 0 and timeout 10s. We had another instance of sotest running that did send the CAN object:: $ sotest -i can0 -r 123 0 10000 opening driver : defining read-object... done received data: 0: 0 0 0 0 " " closing driver... Read any of the CAN objects 121, 122 or 123, stop the program after 1000 CAN frames were received. We had another instance of sotest running that did send the three CAN objects:: $ sotest -i can0 --queue-read 0 1000 121 122 123 --loop 1000 opening driver : defining read-objects... received on 121: data: 0: 0 0 0 0 " " received on 122: data: 0: 0 0 0 0 " " received on 123: data: 0: 0 0 0 0 " " scitest ------- This tests the sci library. This program has many options in common with sotest. Here is the online help from the program:: $ ./scitest -h **** scitest 1.0 **** the sci test program usage: scitest {options} options: **************** Configuration***************** --interface,-i INTERFACE Use INTERFACE for CAN communication, this option can be given more than once to use more than one interface. --realtime READER-PRIORITY WRITER-PRIORITY Use given realtime priorities for reader and writer thread. --leave for all functions that define CAN-objects, hold the program just before close() is performed. All CAN objects remain defined. End the program with CRTL-C in this case --trace,-t LEVEL set trace level, LEVEL is an integer 0..2 (default 0) --errprintlevel,-E LEVEL set errprint level, LEVEL is an integer 0..3 (default 1) *************** command options *************** --loop {no of loops} run read, write, readnow or readmany in loop-mode --sleep {seconds} sleep a number of seconds before starting the test. seconds may be a floating point number. --quiet,-q {level} run read, write, readnow or readmany in quiet-mode level may be 1 .. 5, meaning that each 10**(level-1) events print a single character on the screen. --check check sequence in --read, (must be used together with --write in another sotest-task --size,-s [bytes] use [bytes] bytes to transfer and receive data --count [number] use [number] as initial number to write with -w --consistence send alternating 8 bytes of 0xFF or 0x00 to test data consistence --remote do remote-read or remote-write, implemented for --write and --read ***************data transmission commands**************** --rwtest [object1] [port1] [object2] [port2] [write-timeout] [read-timeout] make a write-object (object1,port1) and a read-object (object2,port2) with a timeout set for the 2nd object then write 8 bytes (values 1 to 8) and read the 2nd object (read immediately) and return the results --write,-w [object] [port] [timeout] write data (a running counter), non blocking --write-w [object] [port] [timeout] the same as --write but do silently retry to write when the driver returns a SOCAN_WAIT status. --writeinhibit [object] [port] [timeout] [inhibit-time] similar to writelater, but the CAN-object gets a timestamp when it is transmitted. Inhibit-time is the minumum time that has to pass before a new object is sent. This concerns only writeinhibit combined with the loop-command. In this case only about every [inhibit-time] microseconds new data will be sent (note that the unit for this parameter is microseconds, not milliseconds --read,-r [object] [port] [timeout] read data from an object (blocking). --readnow [object] [port] [timeout] read data from an object (immediately). --queue-read [port] [timeout] [object] {[object]} read more than one object via the signal-function in conjunction with the new queue-read operation together with --remote, all objects will be remote-read objects