LabVIEW and single-chip computer serial communicationVISA is the acronym for Virtual Instrument Software architecture (that is, Vsan Instruments software Architecture), which is essentially an I/O Port Software library and its specifications. Visa is a standard i/0 application interface for instrument programming and is an industry-ready standard API (Application interface) for instrument drivers, with object-oriented programming for compatibility, extensibility, and independence. The user can use an API to control different kinds of instruments including VXI, GPIB and serial devices. It also supports multi-platform operation, multi-interface control, and is a multi-type library of functions. in LabVIEW, the Visa interface program, when the external device changes, only need to replace a few program modules can be used, simple and convenient and high development efficiency. serial communication programming with the Visa node in LabVIEW. To facilitate user use, LabVIEW makes these visa nodes a sub-module consisting of 8 nodes, respectively, to initialize the serial, serial, serial, interrupt, and close the serial port functions.
first, the basic stepsin LabVIEW, the basic steps for serial communication are divided into 3 stages:First: Serial port initialization, using ⅥSA Configure Serial port.vi node to set the port number, baud rate, stop bit, check bit, data bit. Second: Read and write the serial port, using the visa read node and the visa write node to read and write the serial port. Third: Close the serial port, stop all read and write operations.
second, the main node introductionhere is the main node of the visa serial port and its functions:
1. Serial Port configurationThis node is mainly used for the initialization of the serial port, as shown in 1.
Figure 1 Serial port configuration nodeVisa Resource Name: refers to the PC serial name, example: COML,COM2, etc. baud rate: Serial port rate, default is 9600bps. data bit: The number of bits in a frame of information, LabVIEW allows 5~8 bit data, the default is 8. Parity : Parity bit, selectable as no parity, odd check, or even parity, default is no checksum. Stop bit: The number of bits in the stop bit in a frame of information, selectable as 1-bit, 1. 5-bit or 2-bit. Flow control: Sets the type of control used by the transport mechanism, optionally none, Xon/xoff software flow control, or rts/cts hardware flow control, default is None. Terminator: Sets the Terminator of a frame of data, that is, when receiving the serial data, when the Terminator is received, the software automatically ends a frame of data connectionInbox
2, serial writingThis node is mainly used for writing serial data, as shown in 2.
Figure 2 Serial port write to the node write buffer: The content sent by the serial port.
3, serial readthe node is primarily used to read data in the string, as shown in 3.
Figure 3 Total number of serial port read bytes: The number of bytes to read. Read buffer: Data received by PC serial port. Return Number: The number of bytes actually read, the total number of bytes should be greater than or equal to the number of returns, or the number will be lost.
4, the serial port is closedThis node is mainly used to close the open serial port, release the serial port resources, so that the serial port is called by other programs, 4 shows.
Figure 4 Serial Port shutdown node
three, typical serial program block diagramAccording to the 3 basic steps of serial programming, Figure 5 and Figure 6 give two typical serial reading and writing program block diagram. Figure 5 reads the number of bytes to a fixed value, the figure is 4 bytes, if the number of data bytes in the string is not equal to 4 bytes will be an error. Figure 6 is to determine the number of bytes of data in the string, and then read it all out. In contrast, the generality of Figure 6 is better, but the probability of error will increase, because it is not known whether the data sent by the serial port is equal to the number of bytes of data we need.
Figure 5 Typical serial reading and writing program block diagram 1
Figure 6 Typical serial reading and writing program block diagram 2
LabVIEW and single-chip computer serial communication