How to use SocketCAN to send and receive messages with Homestar hardware

How to use SocketCAN to send/receive telegrams with TOSUN Hardware

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:

How to use SocketCAN to send and receive messages with Homestar hardware

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系统镜像.

How to use SocketCAN to send and receive messages with Homestar hardware


2) Import mapping file in VM: VM -> Edit VM Settings -> CD/DVD -> Use ISO mapping file.

How to use SocketCAN to send and receive messages with Homestar hardware

2.2. Library file upload

1) Create a new folder vcan on your desktop.

How to use SocketCAN to send and receive messages with Homestar hardware

 

2) Upload the files in the folder to the current folder via USB flash drive.

How to use SocketCAN to send and receive messages with Homestar hardware

(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.

How to use SocketCAN to send and receive messages with Homestar hardware
How to use SocketCAN to send and receive messages with Homestar hardware

4) In the vcan folder, copy the library files libTSCANApiOnLinux.so and libTSH.so to the /usr/lib/ path.

How to use SocketCAN to send and receive messages with Homestar hardware

2.3. Enable vcan

1) vcan command installation steps.

How to use SocketCAN to send and receive messages with Homestar hardware
How to use SocketCAN to send and receive messages with Homestar hardware

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.

How to use SocketCAN to send and receive messages with Homestar hardware

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).

How to use SocketCAN to send and receive messages with Homestar hardware
How to use SocketCAN to send and receive messages with Homestar hardware

You can display help information by sudo . /sockettscan -h to display the help message

How to use SocketCAN to send and receive messages with Homestar hardware

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.

How to use SocketCAN to send and receive messages with Homestar hardware

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.

How to use SocketCAN to send and receive messages with Homestar hardware
How to use SocketCAN to send and receive messages with Homestar hardware

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:

How to use SocketCAN to send and receive messages with Homestar hardware

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.

How to use SocketCAN to send and receive messages with Homestar hardware
How to use SocketCAN to send and receive messages with Homestar hardware

Binding channel 2.

How to use SocketCAN to send and receive messages with Homestar hardware
How to use SocketCAN to send and receive messages with Homestar hardware

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.

How to use SocketCAN to send and receive messages with Homestar hardware

III. Q&A

3.1 sudo: . /sockettscan: command not found

How to use SocketCAN to send and receive messages with Homestar hardware

1) Select the sockettscan file to open the Properties window.

How to use SocketCAN to send and receive messages with Homestar hardware

2) Select Read and write for all Access at Permissions, select sudo for Group, and check Execute.

How to use SocketCAN to send and receive messages with Homestar hardware

3.2 cannot open shared object file

How to use SocketCAN to send and receive messages with Homestar hardware

In the vcan folder, copy the library files libTSCANApiOnLinux.so and libTSH.so to the /usr/lib/ path.

How to use SocketCAN to send and receive messages with Homestar hardware

Run the command to connect the hardware again.

How to use SocketCAN to send and receive messages with Homestar hardware
If you need demos or ask other technical questions, you can leave a message on the official website.

发表回复

en_USEnglish
×
×

产品入口: 产品添加到购物车

Download location

Please click the download button below to start experiencing the powerful TSMaster features. Thank you for your support!

Beta version updated weekly, full version updated monthly
Installation environment
  • 1
    Windows 7 SP1 or higher, supports Win10, and WIn11.

    Operating System

  • 2
    8GB

    random access memory (RAM)

  • 3
    At least 550MB of free space

    disk space

  • 4
    Dual-core (2-core) or higher

    CPU

Please ensure that your computer meets at least these requirements in order to install and run the TSMaster software successfully. If your computer does not meet these requirements, it may cause performance problems or not run the software properly. You may want to consider upgrading your hardware if you need smoother running features.
XML 地图