Share this

Design and Implementation of a Real-Time CAN Bus Monitor for Cigarette Rolling Machines

2026-04-06 03:13:32 · · #1
Abstract: This paper describes how to use the PCI-9810 (non-intelligent single-channel CAN card) as a hardware interface and the DELPHI software development platform to develop a user-friendly CAN bus real-time listener to achieve real-time and accurate monitoring of CAN-BUS line data and clear and easy-to-understand real-time classification display according to the needs of the staff. Keywords: Cigarette machine, CANBUS, real-time listener, DELPHI, multi-threaded database Introduction The cigarette machine in cigarette production mainly consists of two parts: the upper computer MLP, which provides operation and display devices for the control and detection systems, including an industrial PC and a monitor; and the lower computer SRP, which includes sensors, regulating devices, or detection devices. The SRP mainly includes four types of nodes: 1) SPS, 2) HIP, 3) CIS, and 4) SRM. Communication between the host computer and the slave computer nodes is frequent, involving numerous data objects and diverse data types, including parameter uploads, downloads, commands, domain data, etc. Therefore, errors are inevitable due to operator mistakes or controller malfunctions. When errors occur, they need to be analyzed, identified, and resolved as quickly as possible. Thus, a reliable error detection mechanism is needed. The CANBUS real-time monitor discussed in this article was developed to meet this need. Based on the real-time data captured and displayed by the monitor, staff can analyze which side is experiencing a problem and what type of problem it is. This plays a crucial role in safe production and accurate control. (I) Hardware Implementation In the implementation of the real-time monitor, we chose the PCI-9810 non-intelligent CAN interface card from Zhou Ligong Company as the hardware interface for receiving and capturing data transmitted on the CAN bus. As shown in the figure, the PCI-9810 non-intelligent CAN interface card is a high-performance, cost-effective CAN-bus communication adapter card that allows a PC to easily connect to the CAN bus and achieve CAN2.0B protocol communication. It is a non-intelligent CAN interface card designed with a dedicated PCI interface conversion chip, plug and play, and conforms to the PCI 2.1 specification. It adopts interrupt reception mode, which can minimize the load on the PC; it has a data buffer of up to 8 frames. In addition, we used the upgraded version of the Windows driver PCI-9810BWDM driver file provided by Zhou Ligong Company to drive it. (II) Interface Software Implementation The interface software implementation mainly includes four aspects: 1) selection of software platform, 2) use of hardware interface CAN card, 3) implementation of receiving data on CANBUS line using interface, 4) implementation of processing the received data (mainly judgment and display). <1> Selection of software platform - DELPHI system development can use a variety of programming languages, such as DELPHI, VB, VC, PB, etc., which are all object-oriented programming languages. However, compared with them, DELPHI is the only high-efficiency development environment that can be used to develop all software such as database applications, network and WEB applications at the same time. It also has many third-party controls, faster development, and more flexible interface design than VB, VC, and PB. Based on the above factors, considering the large volume and variety of data transmitted on the CANBUS line to be monitored, the relative independence yet interrelationship between information, and the necessity of excellent graphical display, we chose DELPHI as the software development platform. 〈2〉Implementation of PCI-9810 Hardware Interface Operations In the DELPHI program, we implement PCI-9810 hardware interface operations by calling the general-purpose VCI dynamic link library provided by Zhou Ligong. This dynamic link library provides the necessary code and other resources for the interface software to run under Windows, mainly including ten interface functions such as device-related functions and CAN communication-related functions, as well as the definitions of related data structures. Adding the dynamic link library folder to the project folder, and then adding the library source files to the application file unit of the program code, enables the calling of the dynamic link library, thus realizing operations such as opening, closing, starting, resetting, and sending/receiving data on the PCI-9810 card. <3> Real-time reception of data on the CANBUS line. Data on the CANBUS line is unpredictable for the CAN card, so to receive data accurately and in real-time, a function must be implemented in the program to capture data as soon as it is available on the line. Our approach is to utilize multithreading. Specifically, a dedicated thread is created in the program for listening to and receiving data on the line. Regarding multithreading, in a 32-bit Windows system, the system can run multiple processes simultaneously. An application loaded into memory and ready to execute is called a process. It consists of the program code loaded into memory, the operating system, and the application execution environment created by it. A process is a running instance of an application. Each process has its own private virtual address space and dynamically allocated memory, as well as files, threads, and other modules. Each process has a main thread, but can create other threads. Threads within a process execute in parallel. The CPU time occupied by each thread is allocated by the system; threads can be considered the basic entities through which the operating system allocates CPU time. Each process can also execute multiple threads simultaneously, with the system constantly switching between them. Although Windows provides many API functions for multithreaded design, directly using API functions is extremely inconvenient and prone to errors if used improperly. To avoid this problem, we adopted the method provided by Delphi, namely, inheriting the TThread class to create thread objects. TThread is provided by Delphi's VCL class library for thread programming. The TThread class encapsulates the API functions of the Windows thread mechanism, and the thread object generated by inheriting the TThread class represents a thread in the actual program. The thread object greatly simplifies the handling of multithreaded problems by encapsulating the content required to use the thread. In addition, in Delphi, TThread is declared in the Classes unit and is directly inherited from TObject, so it is not a component. TThread is an abstract class, so you cannot create an instance of TThread, but only an instance of its derived class. The steps to write multithreaded code using the TThread class in this program are as follows: (1) Derive a new thread class from the TThread class. That is, create a TreceiveThread. (2) Create a thread object. That is, define thread1:TreceiveThread in Types. (3) The Execute process is overridden in a new separate file automatically generated by DELPHI to save the derived class code. In this process, the data on the CAN line will be received in real time and the basic display and classification display functions for processing the received data will be called. The repeat...until statement is used in the Execute process to determine whether the process has ended. (4) If the Execute process is completed, the thread will end and the stack space occupied by the thread will be released. <4> Processing the received data Real-time processing of data includes two aspects: 1) Display the received data frames completely according to the data structure of the received data, including frame type, frame format, frame ID, frame data, etc. 2) Analyze the data in a deeper level to determine the true meaning of the data and fill it into the corresponding text box or draw the corresponding state diagram, etc. (1) For the first basic display, we use the listbox control provided by DELPHI for scrolling display. The capacity of the listbox is sufficient for the needs of this display. In addition, we also added a button control to clear the contents of the listbox at any time according to the needs of the operator. (2) For the second type of classification display. For different data, we will use different analysis and processing methods to display. According to the actual meaning of the data, it is mainly divided into 1) up and down parameters. 2) domain requests and domain data, 3) down transmission instructions and up transmission messages. The processing methods will be introduced below: 1 Display of up and down transmission parameters using the database system The parameters transmitted on the CAN line are not only nearly 200 kinds, but also have up and down transmission, so the amount to be displayed is huge. In addition, the up and down transmission parameters have the same data structure, so we use the method of querying the pre-established database to display. About the database system The database system provides us with a way to gather information closely related to our work and life. It also provides a way to store and maintain this information in a centralized place. The database system mainly consists of three parts: database management system, database application, and database. DELPHI implementation of the database system (1) Establishing the database In this project, we used Microsoft Access to establish a relational database (a database consisting of several tables). It includes a table, whose fields are id (for judging the string) and location (for the text box code to be filled in the parameter value). (2) To access the database in the application, a database engine, database access component and database control component are needed. DELPHI7 provides BDE and ADO data engine. Considering that the database application in the project is relatively simple, we chose the commonly used BDE (Borland Database Engine) to control the reading of the database. The specific operation is as follows: 1) Use BDE Administer in the DELPHI7 folder to create an alias for the database. 2) Add database access component and database control component (including components in the Data Access page and BDE page) to the form to realize the connection between the application and the database. In the project, we use the Table component to encapsulate the data table, obtain data from the database table through the BDE data engine (the text box code to be filled in the parameter value) and pass the data to the data control component TDBEdit through the DataSource component. 3) In the program, we use the Gotokey method provided by TTable to search the database and use the data in TDBEdit. This implementation allows different parameter values ​​to be filled into their unique corresponding text boxes. 2. Domain Request and Domain Data Processing Due to the diverse, variable, and uncertain nature of domain data, we cannot use a database with uniform parameters or other standardized processing methods. Therefore, in the program, we use multi-level compound selection statements to make judgments and then perform different processing based on different domain data. Domain data is uploaded based on identifiers; it only contains the data and no other judgment information. The judgment of domain data depends on the content of the domain request data. Therefore, the program first determines whether the frame is a domain request. If it is, the frame data is assigned to the corresponding variables. These variables store the judgment information for the domain data. If it is determined to be domain data based on the identifier, the corresponding processing is performed based on the information stored in the variables. In the processing of domain data, many cases require plotting curves. For this, we chose the Delphi TChart control. Using its Series property's Fast-line, the received data is correctly plotted as a curve. 3. Command and Message Processing Command and message processing is similar to domain data processing, also using multi-level compound selection statements for judgment and then making corresponding processing. Here, the corresponding processing is to fill the relevant information of the command and message into the text box. 〈5〉 Software Flowchart Data Processing Function dataprocess() Flowchart Conclusion In this project, the controller of the CAN card PCI-9810 is SJA1000. In terms of data transmission and reception, it supports two modes: normal and listen-only. In the actual operation of the listener, we chose the listen-only mode for line listening, which achieved good results. Moreover, we added a sending part in the interface design process, which facilitates the detection of the CAN card and the debugging of data reception. At this time, the normal mode needs to be selected. The innovation of this paper: Combining the specific needs of the actual situation, Delphi was reasonably selected as the software development platform. In terms of real-time performance, we chose the thread class provided by Delphi itself, instead of choosing the API functions provided by Windows as usual, thus making the program design simpler. In addition, in terms of data processing, we not only adopted the usual database methods, but also adopted other simple and feasible methods according to actual needs. The requirements were well fulfilled. In summary, by drawing on the experience of the former and adding practical innovation, we successfully designed a real-time listener and passed the actual test. The real-time listener designed in this project is very good in terms of practicality, real-time performance, accuracy and user-friendliness. References: [1] Rao Yuntao, Zou Jijun, et al., Fieldbus CAN Principle and Application Technology, Beijing University of Aeronautics and Astronautics Press, 2003 [2] Liu Ruixin, Wang Yuanzheng, et al., Delphi Programming Tutorial, Machinery Industry Press, 2001 [3] Zhang Zengqiang, Liu Cheng, et al., Delphi7 Database Development Complete Manual, Tsinghua University Press, 2003 [4] Zi Shubo, Yu Demin, et al., Design of Database Model for Data Acquisition and Management in Industrial Production, Microcomputer Information, Vol. 21, No. 7-3, 2005.
Read next

CATDOLL 135CM Laura (Customer Photos)

Crafted with attention to detail, this 135cm doll offers a well-balanced and realistic body shape that feels natural in...

Articles 2026-02-22