Catalogue
Catalog
I. Preface
1.1 Socket CAN
Second, the use of Socket CAN tutorial
2.1 System environment configuration
2.2 Library file upload
2.3 Enabling vcan
2.4 Dual-channel communication of test equipment with each other
III. Questions Q&A
3.1 sudo: . /sockettscan: command not found
3.2 cannot open shared object file
I. Preface
Preface introduction
1.1 Socket CAN
SocketCAN is a CAN protocol stack maintained by the Linux kernel, and you can use the Socket API provided by the Linux kernel to read and write operations on the CAN bus. Users only need to use the C language to realize the communication with the Socket API, and then they can control the nodes on the CAN bus to realize the sending and receiving of data.
If you want to use SocketCAN to control TSCAN devices, one solution is to use the virtual SocketCAN that comes with Linux. we use libTSCANApiOnLinux.so, a Linux library provided by TOSUN, to complete a vcan server program on the local machine for interchanging the messages from SocketCAN and libTSCAN.
Configuring the baud rate of the TOSUN hardware this way, as well as viewing the information needs to be in the sockettscan program. Because vcan itself doesn't support baud rate configuration, we can't tell vcan about the statistics.
The logic diagram is shown below:
Second, the use of Socket CAN tutorial
Socket CAN Using Toturials
2.1 System environment configuration
This step can be ignored if the computer's own system is Linux.
1) Via http://releases.ubuntu.com/18.04/可以下载Ubuntu系统镜像.
2) Import mapping file in VM: VM -> Edit VM Settings -> CD/DVD -> Use ISO mapping file.
2.2. Library file upload
1) Create a new folder vcan on your desktop.
2) Upload the files in the folder to the current folder via USB flash drive.
(3) libTSCANApiOnLinux.so, libTSH.so, sockettscan, sockettscan.cpp, TSCANDef.hpp the properties of these five files to change: Permissions at the Access all select Read and write, Group select sudo, check Execute.
4) In the vcan folder, copy the library files libTSCANApiOnLinux.so and libTSH.so to the /usr/lib/ path.
2.3. Enable vcan
1) vcan command installation steps.
2) Test whether vcan is installed successfully, use the command ifconfig -a to check the information, see the information with vcan0 means the installation is successful.
3) Install can debugging tools, sudo install can-utils .
4) Run the sockettscan program.
Bind to channel 1 of device 0, baud rate 500k-2M, enable terminating resistor. This allows the message to be synchronized to the TSCAN device by calling vcan0 via socketcan. -b denotes the arbitration baud rate, -d denotes the data baud rate, -v denotes the hardware subscript (subscript starts from 0), and -c denotes the channel subscript (subscript starts from 1).
You can display help information by sudo . /sockettscan -h to display the help message
2.4, test equipment dual-channel mutual communication
1) Hardware TC1034
1-1. It is necessary to connect CAN1 and CAN2 of TC1034 through DuPont cable, and establish two channels of vcan0 and vcan1 by the above method.
Binding two channels using sockettscan: A note about the use of multiple channels is that each sockettscan is used to connect to a single TSCAN hardware. Multiple channels can be written multiple times (the vcan0 name needs to be at the top) and multiple hardware devices, which can be realized by calling sockettscan from multiple terminals.
1-2. Test the virtual can data sending and receiving by cansend and candump. Open two terminals respectively, which are responsible for data receiving and sending.
First start the receive command candump, it will block and wait for the data. Then cansend sends the data with the following effect:
2) Hardware TC1034 and TC1016P
2-1, you need to connect CAN1 of TC1034 and CAN1 of TC1016P via DuPont cable.
Bind two channels using sockettscan.
Binding channel 1.
Binding channel 2.
2-2. Test the virtual can data sending and receiving by cansend and candump. Open two terminals respectively, which are responsible for data receiving and sending.
III. Q&A
3.1 sudo: . /sockettscan: command not found
1) Select the sockettscan file to open the Properties window.
2) Select Read and write for all Access at Permissions, select sudo for Group, and check Execute.
3.2 cannot open shared object file
In the vcan folder, copy the library files libTSCANApiOnLinux.so and libTSH.so to the /usr/lib/ path.
Run the command to connect the hardware again.