How to save serial port data in labview?

Publisher:和谐共融Latest update time:2020-03-15 Source: elecfansKeywords:labview Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

LabVIEW is a development environment based on a graphical programming language. It has many similarities with traditional programming languages, such as similar data types, data flow control structures, program debugging tools, etc. However, the biggest difference between the two is that traditional programming languages ​​are programmed in text languages, while LabVIEW is programmed in graphical languages ​​(i.e. various icons, graphic symbols, connections, etc.).

The programming is simple and convenient, the interface is intuitive, and it has powerful data visualization analysis and instrument control capabilities.


Labview has a rich file operation function library that can easily read and write files. Labview can read and write text files, data report files, binary files and test files. The data read from the readbuffer end of VISAread in the main program needs to be converted into table data for saving. The data saving is divided into two stages. In the first stage, it is displayed in the main program interface in the form of a form (with a time header), which is convenient for users to intuitively check whether the test parameters have met the requirements. In the second stage, the form data is saved in an Excel file, which can be printed and queried by users. If the data does not need to be displayed intuitively on the main program interface, it can also be saved in a TXT file (which can be opened with Excel).


1. Design of data display module

The project takes full account of dynamic real-time performance. Each frame of data displayed corresponds to a different moment. The time size and time interval can be set for data display and storage functions to meet the data requirements at different test moments. Figure 1 shows the dynamic data table displayed by the display subroutine.

How to save serial port data in labview?

figure 1


Considering the frequency of reading the serial port, we propose two possibilities: ① The host computer needs to read the serial port periodically, so that the data from the serial port can also be displayed and saved periodically; ② The host computer's reading operation on the serial port is non-periodic, and the interval time is sometimes long, so that the serial port data is displayed when it comes up, and it will not be displayed if there is no data.

For the first case, Figure 2 shows the specific subroutine code. The serial port data from the main program is separated by each parameter of the StringSubset function module. Then, it is finally implemented as Table3 in Figure 1 through MergeSignals and BuildTable. From Figure 1, we can see that the data is periodically saved in the form at intervals of 3s. How to achieve this periodicity? This requires the use of the Combobox control in the While loop, and the various required saving cycles are preset for selection. It is worth noting that the data displayed by the subroutine in Figure 1 is the fixed value of the analog input.

How to save serial port data in labview?

figure 2


For the second case, you need to make some changes to the source program (Figure 2) and remove the Combobox control from the original program. In order to achieve the function of displaying only when data is available and not displaying when no data is available, you can consider adding a Case box and setting a local variable (whether there is data read from the serial port) to decide whether to display or not. The specific program can be written by the reader.


In order to display each test parameter in real time, each parameter data is connected to its own WaveformChart (real-time trend chart control), so that the waveform changes of each parameter can be displayed in real time by the trend chart. Users can intuitively judge whether the test parameters meet the requirements from the PC.

2. Save the form records displayed by the main program to a file

The serial port data in the program can be intuitively displayed on the front panel and saved, but in order to accurately analyze the experimental results, data storage is also important. Good data storage is conducive to the later processing and analysis of the data.


In the interface diagram of the real-time test main program, after the last module data is displayed in the main program form, the test setting button uses a Boolean type button "Save Data", which is a setting button used to set whether the data is saved. When it is True, all the real-time test data displayed in the form can be saved to the specified test file; when it is False, the real-time test data will not be saved. The essence is that the user selectively decides whether the data is saved through the state of the save setting button. There is such a program in the example provided by LabVIEW7.1/help/findexample. What needs to be changed is to replace the Table with the Table to be saved, create the corresponding attribute node, and select Rowheaders[] and Columnheaders[] to be effective. In this way, the form file in ⑴ can be saved to the file together with the row header and column header.

Keywords:labview Reference address:How to save serial port data in labview?

Previous article:LabVIEW reads serial port data
Next article:Labview serial data processing_labview serial communication

Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号