Virtual Instrument Design Based on Embedded System
2026-04-06 03:43:19··#1
1. Introduction The development of computer and interface technologies, along with the shortcomings exposed by traditional test and measurement instrument systems, has led to computer-based virtual instrumentation becoming increasingly dominant in the testing and measurement field. Virtual instrument systems have gained widespread industrial application due to their platform versatility, expandability, ease of upgrade, and high intelligence. The main solution in the industry is to insert PC-based (ISA, PCI) data acquisition boards into PCs and industrial control computers to form hardware systems, and to write drivers and software panels for Windows systems to implement software functions. However, in practical testing tasks in field and harsh environments, we have found that PC-based or industrial control computer-based virtual instruments exhibit many problems, such as: large size, inconvenient portability; plug-in card structure, prone to loosening and insecure connections; and poor shock resistance due to the reliance on mechanical hard drives as the primary storage medium. Embedded computing platforms, characterized by 32-bit embedded microprocessors and embedded operating systems, have ushered in the post-PC era of computing. The small size and high reliability of embedded systems can meet the needs of portable virtual instruments in field and harsh environments. Designing virtual instrument systems based on embedded computing platforms has become a new approach to building test systems. By constructing an embedded computing platform based on the PC104 bus and adding instrument cards and their functional programs, we have realized various test instruments for radar electronic equipment. The technical problems that need to be solved in constructing virtual instruments based on embedded systems are concentrated in the construction of the system platform, the design of interfaces and drivers, and the design of the soft panel. 2. Hardware System Composition The hardware system includes an embedded motherboard, instrument function boards, Flash storage media (DOC or CF card), an LCD screen, a touch screen, and signal interfaces, as shown in Figure 1. The LCD screen and touch screen enable human-computer interaction, the signal interfaces are used to couple test signals, the embedded motherboard serves as the control and computing unit, and the instrument function boards implement the functions of specific instruments. Figure 1. System Hardware Composition. The components in Figure 1, stacked in the following order, are: touch screen, LCD screen, PC104 motherboard, oscilloscope card, multimeter card. The function boards and embedded motherboard are interconnected mechanically and electrically via the PC104 bus in a stacked manner. This method has the following advantages: 1. Highly compact electrical contact. The circuit boards are deeply connected through multiple rows of pins, which is much tighter than the slot connections of ISA and PCI. 2. Robust mechanical structure. The circuit boards are tightly connected by four studs, ensuring a very secure mechanical connection between the boards and preventing any shaking. 3. The electrical characteristics of the PC104 pins are fully compatible with ISA, and the electrical characteristics of the PC104 Plus pins are fully compatible with PCI, allowing functional boards designed based on ISA or PCI buses to be reused from an electrical principle perspective, facilitating a smooth transition during system modification. Replacing hard drives with DOC or CF cards as external storage media also significantly improves the system's resistance to vibration and shock. The hardware system described above provides hardware support for small, reliable virtual instrument systems, but the resulting small system storage capacity and limited resources pose challenges to software system design. An embedded operating system must be used, and software programming must consider small size and high efficiency. 3 Software System Design We use embedded Linux as the operating system and write the instrument's driver program on the Linux platform. Tiny X and GTK+ are used as the graphical interface solution to implement the instrument's soft panel. The system's software structure is shown in Figure 2: Figure 2. System software component composition Figure 3.1. The embedded Linux system adopts the open-source Linux system and cuts off unnecessary functional modules through compilation options to obtain a kernel module of about 500K in size. Busybox is used to replace the shell, and libraries such as glibc.o are added to the system to build a 4M Linux running system. The literature [1] has a detailed introduction and guidance on the construction of the embedded Linux system. 3.2. The driver for the instrument card is implemented by port reading and writing. The methods for operating on ports under Linux are in usr/include/asm/io.h. Since the port reading and writing functions are some inline macros, when writing port reading and writing programs, you only need to add: #include No additional library files are required. In addition, due to a limitation of the gcc compiler, when writing programs that include port reading and writing code, you must either turn on the compiler optimization options (use gcc -O1 or higher options) or add: #define extern static before #include Before reading and writing the port, you must first obtain the permission to read and write the port through the ioperm() function. The function is used as follows: `ioperm(from, num, turn_on)`. If `turn_on=1`, it means acquiring read and write permissions for `num` ports starting from `from`. For example, `ioperm(0x300, 5, 1)` means acquiring read and write permissions for ports 0x300 to 0x304 (5 ports in total). The last parameter, `turn_on`, indicates whether to acquire read and write permissions (`turn_on=1` means acquire, `turn_on=0` means release). The `ioperm()` function is generally called during the hardware initialization phase of the program. The `ioperm()` function requires the program to be run as root or to have root privileges granted using `seuid`. Port reading is accomplished using the `inb(port)` and `inw(port)` functions, where `inb(port)` reads an 8-bit port and `inw(port)` reads a 16-bit port. Write operations on 8-bit and 16-bit ports are accomplished using the functions `outb(value, port)` and `outw(value, port)`, respectively. The first parameter of each function represents the value to be written, and the second parameter represents the port address. The macros `inb_p()`, `outb_p()`, `inw_p()`, and `outw_p()` function the same as the corresponding four port read/write functions mentioned above, except that they add a certain delay after the port operation to ensure reliable read/write. A delay of approximately 4 microseconds can be obtained by adding `#define REALLY_SLOW_IO` before `#include`. 3.3. Soft Panel Programming Based on TinyX and Gtk+ The design of the instrument's soft panel involves the selection and programming of a GUI under Linux. Considering the maturity of XWindows and its consistency with desktop systems, we chose the streamlined XWindows system TinyX as the underlying GUI solution. The Gtk+ 1.2 library is used as the control set to develop the instrument's soft panel program. The graphical interface development scheme based on TinyX and the Gtk+ library makes the development of the soft panel closer to the development based on GNOME in a desktop environment, and many Linux tools in the desktop environment can be used directly. The Gtk+ graphics library is the underlying foundation of the GNOME desktop system, and it contains a relatively complete set of GUI controls (GtkWidgets). Based on an object-oriented approach, GTK+ implemented an object system and message and callback mechanism in C, integrating all graphical controls into an object framework, making the control set expansion convenient. For the application needs of the virtual instrument field, control sets of common GUI units can be built. We developed panel controls for instruments such as oscilloscopes and signal generators, as well as some key GUI unit controls, in the form of GtkWidgets. These facilitate secondary development and software unit reuse for users. 4 Conclusion Based on an embedded motherboard and embedded software environment, we present a general solution for constructing virtual instruments. Simultaneously, by building a GUI environment based on TinyX and the GTK+ library, coupled with a series of panel unit controls we independently developed, we provide support for the development of virtual instrument soft panels. Based on the above solution, we developed a radar fault detector integrating the functions of an oscilloscope, multimeter, and microwave signal generator. As shown in Figure 3: Figure 3. A multifunctional virtual instrument implemented based on the proposed solution. Practice in a military field environment shows that the system has a robust mechanical structure, high reliability, and is easy to carry and use. References: [1] Zou Siyi. Embedded Linux Design and Application: Tsinghua University Press, 2002.01 [2] Kurt Wall. GNU/Linux Programming Guide: Tsinghua University Press, 2002.06 [3] Riku Saikkonen. Linux I/O port programming mini-HOWTO: http://www.linuxdoc.org/