Serial communication experiment (forwarding)

1. Install VISA driver
VISA driver is not included in the software package, you must download it yourself.

VISA (Virtual Instrument Software
Architecture, referred to as "Visa"), the virtual instrument software structure, is
the general name of the I/O interface software standard and its specifications formulated by the VXI plug&play alliance. VISA provides a library of standard I/O functions for instrument programming, called the VISA library. The VISA function library resides in the computer system and is the standard software communication interface between the computer and the instrument, and the computer controls the instrument through it

Driver download address
http://www.ni.com/downloads/zhs/

After the download and installation are complete, you can click to open NI MAX

If the installation is successful, you can see the COM port.

Then right-click and select Instrument I/O, you can see the 4 VISA controls we will use this time.

Use the shortcut key ctrl+h to open the instant help, in the instant help we can see the description of the control. There are also detailed help information, which is very convenient for our development and application.

2. Place the controls
This is a simple sending and receiving program, the main body of the program is mainly composed of the controls mentioned above.

It is to configure the serial port first, then write, and then read. After completing these operations, close the serial port.

3. VISA configuration serial port
Next we have to configure the serial port.
Generally speaking, the main contents of the configuration are:

The name of the visa resource.
Baud rate
Data bits
Parity: check the number of code 1
Flow control
Next, I will introduce their configuration methods one by one.

1) VISA resource name

You can right-click on the terminal or create an input control.
Used to select the port number for communication with the lower computer.

2) The baud rate is the
same as the name of the visa resource, and you can also choose to create input controls and constants. These two values ​​must correspond to the lower computer.
Generally 9600, 115200 can also be customized.
Here I choose 9600.

3) Data bits
Data bits are the number of bits of input data.
Right-click to create an input control.

4) Parity check
Monitor the number of 1s in the received information for check.
Right-click to create an input control.

5) Flow control
Because the processing speed of the upper computer and the processing speed of the lower computer are inconsistent. It may cause the data of one party to be processed in the future, and the other party to continue sending, resulting in data loss.
Right-click to create an input control.
Hardware flow control and software flow control can be used in labview.

Software flow control

XON/XOFF (Continue/Stop) is a data flow control protocol between an asynchronous serially connected computer and other components. When the amount of data in the input buffer of the receiving end exceeds the set high bit, the XOFF character is sent to the data sending end, and the sending end immediately stops sending data after receiving the XOFF character; when the data amount in the input buffer of the receiving end is lower than the setting When the low bit is set, the XON character is sent to the data sending end, and the sending end immediately starts sending data after receiving the XON character.

Hardware flow control

The commonly used hardware flow control is RTS/CTS flow control. Both the sender and receiver have their own RTS and CTS, such as the communication parties A and B. Then the RTS of A is connected to the CTS of B, and the CTS of A is connected to the RTS of B. The function of RTS is to tell the other party that I can accept data, which is an output port; the function of CTS is to control sending or not generating data according to the level.

6) The stop bit is
used to indicate the last bit of a single packet. Typical values ​​are 1, 1.5 and 2 digits. Since the data is timed on the transmission line, and each device has its own clock, it is likely that there is a small out of synchronization between the two devices in the communication. Therefore, the stop bit not only indicates the end of the transmission, but also provides an opportunity for the computer to correct clock synchronization. The more the number of bits suitable for the stop bit, the greater the tolerance for synchronization of different clocks, but the slower the data transmission rate.

7) Start terminator and terminator

The default value of "terminator" is 10, and its hexadecimal is "0x0A", which is an ASCII code and a newline character.
Start terminator. The default value is true, and stop receiving when the terminator is received. Generally, when the terminator is not needed, set it to false

8) Timeout
If the timeout is not set, or the timeout is infinite, the program will be waiting for VISA to read it all the time, which will occupy the entire cpu.
If the timeout is set, the program will not be executed if the timeout period expires, and the error output will output an error.
Therefore, in general, a delay is added to the loop to prevent the program from being unable to run due to constant occupation.

9) Cluster class
After finishing the control placement, we can put all the required configuration controls in the same cluster class. Make the program more beautiful.

Select the cluster type in the front panel, and place the controls.

After putting

Block diagram

10) Configure the bottom layer of the serial port control

This serial port configuration function is not the bottom vi. Double-click the configuration serial port to open the vi at the bottom of the configuration serial port. It can be seen that the configuration serial port program is an attribute node!

Property node:
Get (read) and/or set (write) the referenced property. Obtaining or setting properties and methods of local or remote application instances, VIs or objects through property nodes can also access private data of LabVIEW classes through property nodes.

4. Write to the serial port
After the serial port configuration is completed, the next thing to do is to write to the serial port. The serial port configuration is like the key to the door, you should enter after opening the door.

Create a loop for sending

Use an event structure plus a button to send

Plus a window for sending data.
5. Read operation
After completing the write operation, start the read operation configuration.

It is best to add a feedback node here to prevent some sent data from being unreadable.

A feedback node is added in front to read the number of bits of the data sent. Can be used for verification

6. Completion After
adding some loop structures, the simple sending and receiving of the entire serial port is completed.

Guess you like

Origin blog.csdn.net/aqiuisme/article/details/106447853