top of page
Search
giccenata1975

Read Serial Port In Labview: How to Use NI-VISA and NI-Serial Drivers



This is the front panel of the application that is developed in LabVIEW.It has read buffer window from where you can read the serial data, write buffer to write data on serial window. It has delay knob from where we can change the delay between read and write operation. It also has stop button to stop the VI


This board has a LED connected to PIN 0. I used Arduino IDE to upload the program. According to the logic given LED will turn ON wheb serial read =1 and it will turn OFF hen serial read =0




Read Serial Port In Labview



The following application demonstrates how LabVIEW can be used with ADR interfaces, or any ASCII based serial data acquisition and control interface. The application is a simple temperature measurement and plot using an ADR112 and an LM335 solid-state temperature sensor. It is assumed the user has a basic knowledge of LabVIEW, however, no prior experience with LabVIEW is required as long as the user manual is available to help with the generic tasks. Figure 1 shows our final operating panel for the application in operation. The panel allows adjustment of the sample rate via a rotary knob, and displays temperature vs. time in a graph format. A digital reading of present temperature is also provided. The hardware consists of an ADR112 connected to com2, interfaced to an LM335 temperature sensor connected to AN0.


The software in the loop must now be set up to send and receive ASCII data to the ADR112 via Com2. This is accomplished by using a sequencer and a number of serial port functions provided by LabVIEW. The sequence, as the name implies, allows the execution of code in a specific sequence similar to that of a PLC. The sequencer is a series of frames that code is placed into, that determines the actual execution sequence of the code. Add a sequencer to the control diagram using FUNCTIONS/STUCTSANDCONSTANTS/SEQUENCER. position the sequencer as shown in figure 6.


The first frame will contain the actual serial write function. Also added in this step is the serial port initialize function. Place the serial write function inside frame 0 by selecting it from FUNCTION/SERIAL/SERIALWRITE. Place the serial initialize function outside the while loop as shown in Figure 7 using FUNCTION/SERIAL/SERIALINITIALIZE. Use a numeric constant to set initialize the port to Com2 ( port 1) and set the port for the write operation by wiring as shown. A command string of "RD0" must be sent in the write operation and it must be followed by a carriage return for the ADR112 to respond. This is done by selecting a string constant using FUNCTIONS/STUCTSANDCONSTANTS/STRINGCONSTANT. Enter RD0 followed by a carriage return as the string constant and wire as shown in Figure 7.


A second step is to be added to the sequencer where the serial read function will be placed. this is done by right clicking on the sequencer frame indicator and selecting " ADD FRAME AFTER". The sequencer will appear as shown in Figure 8.


The data returned from the ADR112 will be read using a "serial read with timeout" vi. This vi is included with LabVIEW in the samples directory. Place it in the frame along with a "Format and Strip" function from FUNCTION/STRING/FORMATANDSTRIP. Wire as shown in Figure 9 including, a numeric constant of 5 for number of bytes to receive ( 4 plus CR ), and a string constant of "%d" to identify the incoming data as integer format. Wire the output of the " Format and Strip" function to both the " Present Temperature" display and the " Temperature Plot "


This was a simple application using only one analog input port of the ADR112 interface. Additional graphs or use of the digital ports for alarms can be facilitated simply by adding steps to the sequencer with additional write and read operations. All of the functions found on ADR interfaces including, counters, PWM, digital I/O, analog outputs, interuppts and stepper indexers can be utilized with LabVIEW. Programs can be as complex or as simple as the application requires. The people at National Instruments have done an outstanding job developing LabVIEW and it is easy to see why it has become so popular.


Data communication via serial port (or any communication for that matter) takes time. The receiver must receive, process and reply to the data send by the sender. I suggest having a look at the examples in the Example Finder, they are well documented. Search for "Simple Serial" or just "Serial".


Dear Bilal,thank for this useful tutorial. Is there is a way to use the Tx and Rx pins of the Arduino to pass serial data through Labview? What I mean is the opposite of what you did, instead of reading the COM port, I want to write to it. Thank you for your help.


IntroYou can set in LabVIEW software a number N and communicate it via serial to the Arduino board. The board read the number N and elaborate a random number n between 0 and N. Finally, the board communicate the random number n to the computer via serial and the LabVIEW software plot the data.


LabVIEW projectIn the LabVIEW project you have to auto detect the Arduino board connected to your computer. Note that you must set the right Arduino board name. You must also use the same serial port baud rate that you have set in the Arduino sketch.


Thanks for this code. I modified the code, so every time there is a write to the Arduino. In this case the first time that LabVIEW runs, it finds that there is no serial data. Help, I need to issue a write and immediately read it back. From what I see, I would need to issue the command twice.


I too was trying to achieve the same as Howard. Please suggest how can I check the availability of data on the serial port before attempting read.In your case, the loop runs continuously as the Arduino is sending back message continuously. However, if the Arduino is not sending message continuously, and User tries to send something through Labview and the loop is stuck unless a message is received from Arduino.


Hello, I am doing my final year project i want to view the real-time data continuously running in arduino in the labview can u reply as fast as u can. The sensor values are digital displaying in serial monitor.


I want to read a string that comes from the labview, and when I click the button (for example "ON") he makes a serial print with values??. When I click the button labview ("OFF") it stops putting data through Serial.print and wait for a new order in the "ON" button of labview.


If the description of what you want to do was not correct (that is, the Arduino should send data on every pass through loop() after receiving "ON!" until it receives "OFF!"), then the comment section merely needs to set a boolean variable to true or false, and after the if(Serial.available()) block, the Arduino should check the value of that boolean variable to decide whether or not to send data to the serial port.


4.5 Visa Bytes at Port goes inside while Loop. To activate the Reading case, it has to check if the bytes at serial port are greater than 0 using a Programming > Comparison > Grater than 0 VI. (Pict. 4)


IntroductionLabVIEW is a graphical programming tool that is used in the lab to interface with hardware and labequipment. The graphical LabVIEW program replaces traditional code, which reduces development time byusing the pre-made modules, called Virtual Instruments (VIs). LabVIEW has serial VIs that communicate tothe serial port on a PC. These serial VIs can be used to communicate with a 2-wire device using a DS3900that accepts data and commands from the serial port and converts the information to 2-wire protocol.


The DS3900 provides a way to communicate 2-wire using a PC's serial port. The DS3900 utilizes aMAX3223 RS232 transceiver to translate the serial port signal levels from 12V to voltage levels for amicroprocessor. The microprocessor is then able to communicate to the PC by using its universalasynchronous receiver transmitter (UART). The functional diagram for the DS3900 is shown in Figure 1. Formore information, refer to the DS3900 data sheet.


2-Wire ProtocolThe LabVIEW example VI (communicate_2wire.vi) communicates over the serial port using DS3900 2-wirecommands. When writing to a device, the following commands need to be sent: start, control, registeraddress, data, and stop. When reading from a device, the following commands need to be sent: start, control,register address, start (repeated), control, data, and stop. All commands are in hexadecimal. See the DS10862-Wire Example section.


Table 1. Example of Writing to Register 0x02h in the DS1086 Command 1st Byte Sent 2nd Byte Sent 1st Byte Received Notes Start 0xA0 0x00 0xB0ack 2-Wire Start Control 0xA1 0xB0 0xB1ack Device Identifier = 1011,Device Address = 000, R/W = 0 RegisterAddress 0xA1 0x02 0xB1ack Send Register Address (0x02) Data 0xA1 0xF0 0xB1ack Send Data to Write (0xF0) Stop 0xA3 0x00 0xB3ack 2-Wire Stop Table 2. Example of Reading From Register 0x02h in the DS1086 Command 1st Byte Sent 2nd Byte Sent 1st Byte Received 2nd Byte Received Notes Start 0xA0 0x00 0xB0ack 2-Wire Start Control 0xA1 0xB0 0xB1ack Device Identifier = 1011,Device Address = 000, R/W = 0 RegisterAddress 0xA1 0x02 0xB1ack Send Register Address (0x02) RepeatedStart 0xA0 0x00 0xB0ack 2-Wire Start Control 0xA1 0xB0 0xB1ack Device Identifier = 1011,Device Address = 000, R/W = 1 Data 0xA2 0x00 0xF1ack 0xB2ack Send Data to Write (0xF0) Stop 0xA3 0x00 0xB3ack 2-Wire Stop The following hardware components were used to communicate to a DS1086 with the LabVIEW VI: PC witha serial port, DS3900, and a DS1086. Figure 2 shows how to connect the DS1086 to the DS3900.


The communicate_2wire.vi performs the following actions (also see Figure 3):Prompts user for serial port settingsConfigures serial portDetermines whether to read or write to a register by user inputWrites or reads register entered by userReturns acknowledge bytesReturns value in register during a readFigure 3. Communicate_2wire.vi Flow Chart. 2ff7e9595c


0 views0 comments

Recent Posts

See All

Comments


bottom of page