1 serial programming
In any operating system, serial debugging programs are written according to the steps of opening serial devices, initializing serial ports, and reading and writing serial ports [2].
1. 1 Open the serial port
Similar to Linux system, neokylin operating system is file-based, treating all hardware devices as files, and operating hardware devices is the operation of device files [3]. The device files of serial devices are named "/dev/ttyS0" and "/dev/ttyS 1", and "COM 1" under Windows corresponds to "/dev/ttyS0" under neokylin. To open the serial port, just call the open () function to open the device file.
1.2 Initialize the serial port
Serial port initialization settings include baud rate, data bits, parity bits, stop bits and flow control settings. There are many options when setting separately, so the switch () function is generally used for programming.
1.3 serial port read-write operation
There are two working modes of serial port: blocking mode and non-blocking mode. Blocking mode is relatively simple. When operating the serial port, if the conditions are not met, the operation will be blocked, and the operation will only be carried out when the conditions are met. The non-blocking way is to operate the serial port by polling, and a timing function can be defined when programming, and access to the serial port buffer can be realized by timing [2].
2 minicom serial debugging software
2. Introduction to1minicom
The function of minicom is similar to the super terminal under Windows system, and the computer can use this software to control external hardware devices through serial port.
2.2 minicom installation
The newly released neokylin operating system (NeoKylin3.2. 1) has integrated the rpm installation package of minicom. You only need to insert the system disk into the computer, open the terminal, run the #yum list | grep minicom command to check the version of minicom, and then use the #yum install command to install it.
2.3 minicom configuration and use
When running minicom for the first time, in order to ensure that minicom can read and write CPU correctly, it is necessary to configure the port and baud rate of minicom [4].
Enter root and enter the #minicom-s command. After confirmation, the minicom configuration interface as shown in figure 1 will pop up.
Select serial port settings to enter serial port settings, as shown in Figure 2. Set the serial name, baud rate, data bit, stop bit, parity bit and flow control according to the actual needs, and then press enter to exit the configuration interface. Select Save setup as dfl to save the configuration information, and then select Exit to exit the configuration interface and return to the minicom user interface, where you can send and receive serial data according to the prompts.
2.4 minicom control VGA8×4 matrix switcher
VGA8×4 is a matrix switch with 8 inputs and 4 outputs. It has a standard RS-232 serial communication interface, through which users can remotely control computers. Its communication control protocol: baud rate is 9 600 b/s, data bit is 8 bits, stop bit is 1 bit, and there is no parity bit and flow control bit. The format of control command is: device number+output port number+control symbol+input port number+! . Where "equipment number" and "control symbol" are both 1 characters, and "output port number" and "input port number" are both 2 digits, "!" Is a command terminator. For example, the device number is A, and the video control mode is adopted (the control symbol is ""). The third input signal is switched to 1 output, and its control command is "A0 1[03!" . If the control is successful, the four numbers "0 103" will be displayed in the status display area composed of four digital tubes on the front panel of the matrix switch, indicating that the current status of the matrix switch is 1 the output signal of the channel is input from the third channel [5].
The control experiment of using minicom control matrix switcher in video control mode has a third input and a second output, as shown in Figure 3. Figure 3 shows that the control command sent by minicom is A02[03! As can be seen from the figure below, four digital tubes on the front panel of the matrix switch display 0203, which indicates that the control experiment is successful.
?
3 Qt4 Write serial debugging program
3. Introduction to1Qt
Qt is an object-oriented C++ graphical user interface program development framework developed by Trolltech Company in Norway. Qt is famous for its cross-platform framework. It adopts the method of "write once and compile everywhere", which is convenient for developing multi-platform application software including Windows, Linux and Mac, and can also be programmed with Qt under neokylin operating system. Qt has an intuitive and powerful API, and users can quickly write applications with Qt as long as they have a certain C/C++ foundation [6].
The installation disk of NeoKylin3.2. 1 system integrates version 4.6 rpm installation package. To install Qt, just insert the system disk into the computer and install Qt4.6 on your own computer with the install command.
3.2 Qt serial port programming
So far, there is no control class defined specifically for serial port in the released version of Qt. The easiest way to write a serial debugging program with Qt is to use the Qextserialport class written by a third party [7-8]. Qextserialport inherits the base class QIODevice defined by Qt, which operates on input/output devices. A series of operations, including opening the serial port, initializing the serial port, reading and writing the serial port, are completely defined in the Qextserialport class. When writing a serial debugging program with Qextserialport class, you only need to pass the parameters related to serial operation to it, and you can complete the corresponding functions. Therefore, when writing a serial debugging program using Qextserialport class, you only need to write a little code to realize the function of serial debugging.
3.3 Qt4 Write the control program of VGA8×4 matrix switch.
Control requirements: the third output of the matrix switch is connected to a 40-inch large-screen display, and 1 is connected to four computers respectively. It is required to write a control program, and the large screen display can display four computers through four control buttons.