LabVIEW PC and serial communication, labview Serial Communication
Origin
When I was a freshman, the school opened a public elective course called LabVIEW programming. At that time, I certainly didn't know what LabVIEW was, but I still chose it. The instructor is an associate professor at the School of mechanical engineering. He showed us several projects using LabVIEW, such as fuel tank monitoring host computer. Later, with the study of serial port operations such as single-chip microcomputer and ARM, sometimes a beautiful host computer (especially the host computer that can display Waveforms) is very useful for users in projects. After so many years, although I have also used LabVIEW to write a simple temperature monitoring host computer, this time I picked up LabVIEW and it seems like I have forgotten the syntax!
Define communication formats and functions
Because the data is not complex, we define a simple lower-computer frame format:
Frame header (0xAA) type bytes data low 8-Bit Data High 8-bit reserved byte 1 reserved byte 2 validation byte
If the data to be transmitted is more complex, refer to the ModuleBus protocol!
Main functions include:
- Parses the type bytes in the frame and displays them on the oscilloscope through multiple channels.
- Frame Offset Correction (this is probably not done by the average person, resulting in data loss. As long as the data transmitted through the serial port is correct, it will be able to parse each frame without errors and omissions)
- Display each byte/dual byte/4 byte read in real time
- Saves signals and saves file names automatically named by time.
- Signal playback
- Parse the signal and display it with the indicator light
Interface display
Program Key point display
Although the above is simple, it is the most important part of the function, including frame header search and error frame processing programs. The error frame is sent: for example, the unique frame in the serial port does not start from the frame header but starts from the middle of the frame, as shown in figure
0x12 (data) 0x00 0x00 0x00 0xAA (frame header) 0x00
The first frame may be like this:
... 0xAA (frame header) 0x01 (type) 0x01 (data)
In this way, the data 0x12 will be lost by searching the frame header, and the actual data should be 0x02*256 + 0x01, error frame processing adds less than one frame at the end of the previous frame to the next frame, so that the next frame becomes:
0xAA (frame header) 0x01 (type) 0x01 (data) 0x12 (data) 0x00 0x00 0x00 0xAA (frame header) 0x00
The process of determining the type is simple. You can use the switch structure (if and switch are implemented in both the condition structure in LabVIEW). During programming, you must set the default branch!
I used the data table to save the file because it is indeed simple. The highlight here is that the time-based saving function is added, which is equivalent to adding the time string to the file name, in this way, it is easy to find the collected data in the future, so as to avoid confusion.
Waveform playback is to re-display the programs stored in the data table, which is relatively simple!
Please download the complete program at https://github.com/xiahouzuoxin/zxserial!
For research purposes only. Thank you!
What is the problem of receiving the host machine for serial communication between labview and single chip microcomputer?
VISA Control
How to Use labview to design a serial communication program diagram as a host computer?
Basically, four functions are used to initialize the serial function, set the serial function, read the serial function, write the serial function, and disable the serial function.
These Functions are in the Serial VIs and Functions panel.
There are related examples in labview \ examples \ instr \ smplserl. llb. You can just take a look and write it like this function.