Ni.com is currently experiencing issues that may cause some pages to fail.

Support teams are actively working on the resolution.

Example Code

Communicating with a LabVIEW Web Server using a LabVIEW Web Client

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Description

Overview

 

This program shows an example of a LabVIEW Web Client communicating to a LabVIEW Web Server to get updates using the GET method.

 

 

Description

 

A web client can exchange data with a remote LabVIEW stand-alone application over a network through LabVIEW Web services for multiple reasons:

  1. Users can invoke the Web service VIs with any HTTP-capable web client, including a standard web browser, to exchange data using a URL and standard HTTP methods such as POST and GET.
  2. Users can remotely monitor and control embedded applications using custom thin clients.
  3. You can conduct application-to-application data exchange between numerous HTTP-capable devices and software from both National Instruments and third parties.

In this example we will be using the GET Method to read a dual tone signal with varying frequency and their spectral analysis with multiple windowing techniques from teh Web Server.

The WebServer generates 2 tones with sliding frequency and calculates the spectrum after applying multiple windows. for more information refer to the Signal Generation subVI. The output is then flattened into a Jason String that is written by the server as a response stream. The client Client(Main).vi communicates with this method with its URL (the URL used is on the debugging port to run this example in the development environment) using the HTTP VIs. The received data is then unflattened from Jason to view the cluster of data as sent.

 

 

Hardware and Software Requirements

 

LabVIEW Full or Professional Development Environment 2016 (or later)

 

 

Steps to Implement or Execute Code

 

To execute this example, follow the below instructions:

  1. Open the project LV_WebServer.lvproj
  2. Expand the Webserver virtual folder, right click on WebServer and click on Publish, then click on Start
  3. Expand the Client virtual Folder, Open and run the Client(Main).vi
  4. Stop Execution
  5. Stop the WebServer
  6. To view the Method URL used in the code, right click on Signal_Generator(Main).vi(GET) method under Webserver>>Web resources and click on Show Method URL, then ensure you select 8001-Local Debugging from Available Servers.

 

Additional Information or References

 

To ensure a successful execution, make sure of the below:

  1. You have properly configured your Web Service local debugging Port. Go to Tools>> Options, click on Web Server tab and check the port configuration. It must be 8001 to run this code.
  2. Your HTTP Method VI Settings are properly configured. In your project, right-click WebServer (turn it off if it was already started), click on HTTP Method VI Settings, click on Signal_Generator(Main).vi, then check under URL Mapping that Method is GET, and that the Output Type is set to Stream with Use headers and Buffered options enabled. check below picture for more information.Method VI settings.JPG

     

The Client Front Panel would look like this:Client.JPG

 

And below are the VI Snippets of the Client VI, the Web-server Main and SubVIs respectively:

Client:Client Block Diagram.png

 

 

Signal_Generator (Main) (GET)WebServer BD VI snippet.png

 

Signal Generation SubVI:Signal Generation SubVI Snippet.png

 

 

 

 

Note: You can also use LabVIEW NXG 2.0 and the WebVI feature as a LabVIEW Client. Please refer to the GitHub forum for more information.

To learn more about creating LabVIEW Web Services, please refer to this tutorial: Creating & Accessing a LabVIEW Web Service

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.