Community Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Web Service + AJAX


Contestant Info:

User Group Affiliation:
I'm new to AZ and have not yet attended this group, but I'm looking forward to it!

Arizona

Arizona Advanced LabVIEW User Group (ALVUG)

Location:

Old Chicago’s Pizza and Pasta
1656 S. Alma School Rd.
Mesa, AZ 85210
-or-
Hometown Buffet
1312 Scottsdale Rd.
Scottsdale, AZ 85257

Contact:

Michael Bryner
michael.bryner@ni.com
480.855.5986

Meeting Details:

Quarterly meetings, 12:00 – 2:00 p.m.

User Group Website:

http://decibel.ni.com/content/groups/phoenix-arizona-user-group

Summary:

Triple Whammy!  A good LabVIEW Web Service Example, plus AJAX coding example, plus great idea for easily adding monitor and control of your LabVIEW applications WITHOUT having to write your own web services! 

Function:

With Ajax, web applications can retrieve data from the server asynchronously in the background without interfering with the display and behavior of the existing page.  This example web service opens up access to any of your network shared variables using URLs like this: 

Read --  http://localhost:8080/SharedVarWeb/read/localhost/MySharedVariables/test

Write --  http://localhost:8080/SharedVarWeb/write/localhost/MySharedVariables/test/999

The Ajax code examples show how to create an interactive web page to work with the web service.

Steps to execute code:

These steps are also provided in the included 'Readme.docx' file.

1. Make sure the LabVIEW Web server has been enabled. 

1.      a) Click ‘Tools > Options’ and select the ‘WebServer’ category. 

2.      b) Click the ‘Configure Web Application Server’button.

3.      c) Using your web browser, enable the application webserver

4.      d) Click ‘Apply’ then reboot your computer.

The Web Service in the ‘LabVIEW AJAX Demo’ project provides the ability to get and set Network Shared Variable values.

2. Deploy the Shared Variable library ‘MySharedVariables.lvlib’by right clicking and selecting ‘Deploy’. You can verify it was correctly deployed by opening Distributed SystemManager and looking for the process and ‘test’ variable under ‘localhost’.  Open and run ‘tester LabVIEW AJAX.vi’ to write some values to the test variable.

3. Next you must deploy and build the web service:   

1.      a) Right click the Build Specification entitled‘Shared Variable Web Service’ and select ‘Build’

2.      b) Right click the Build Specification entitled‘Shared Variable Web Service’ and select ‘Deploy’

4. Did it work?? :

1.      a) In the ‘Web links’ virtual folder, double-click the link entitled ‘Raw test data’ – at this point a browser should launch.

         b) If the security warning appears 'To help protect your security, Internet Explorer has restricted this webpage from running scripts... blah blah blah', click on it and select 'Allow Blocked Content'.

         c) Now you should see the ‘test’ variable value in XML format along with the timestamp it was last updated.

         d) Change the inputs in the URL if you have different shared variables deployed that you want to read.

2.      e) In the ‘Web links’ virtual folder, double-clickthe link entitled ‘Set Variable Value’ – at this point a browser should launch and you should see a ‘pass’ or ‘fail’ in XML format along with the timestamp when the web service updated the shared variable value.

         f)  Change the inputs in the URL if you havedifferent shared variables deployed that you want to write.

5. Now on to the AJAX:

To my knowledge, these only work in IE, not in Firefox(other browsers not yet tested).

1.      a) Open ‘Get Value on Button Press.htm’

2.      b) Pressing the request button will return thevalue of the specified shared variable. The value will appear without a page refresh!

3.      c) Open ‘Poll Value with Start Stop.htm’

4.      d) Set the polling interval and click ‘Start’

5.      e) Use the ‘tester LabVIEW AJAX.vi’ or a modified URL from ‘Set Variable Value’ Web link (see above) to change the shared variable value.

6.      f) Watch as the value is updated in the browser.

Screenshots:

Raw XML for 'test' Shared Variable:

LabVIEW AJAX Demo Raw XML.png

Ajax button press request:

LabVIEW AJAX Demo Button Request.png

Polling Request:

LabVIEW AJAX Demo Polling.png

Web Service block diagram:

LabVIEW AJAX Demo - web service block diagram.png

Teaser:

If I move on to future rounds of the code challenge, I plan on doing the following:

Better documentation on Ajax example code.

'Ajax code generator' to unwrap custom typedefs for use in your web code.

Example using Google Maps API to pinpoint simulated wireless sensor network nodes on a map and display values.

Web-service to provide a list of available shared network variables including those on remote machines accesible by the server.

Possibly I'll develop a full-blown "Distributed System Manager' in the web-browser.

VI attached below

Comments
G-Money
NI Employee (retired)
on

Nice! How long did it take you to code up the AJAX client?

Contributors