LabVIEW PC and serial communication

Source: Internet
Author: User

LabVIEW PC and 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 on the LED display page

    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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.