Location: | Old Chicago’s Pizza and Pasta |
Contact: | Michael Bryner |
Meeting Details: | Quarterly meetings, 12:00 – 2:00 p.m. |
User Group Website: | http://decibel.ni.com/content/groups/phoenix-arizona-user-group |
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!
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.
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.
Raw XML for 'test' Shared Variable:
Ajax button press request:
Polling Request:
Web Service block diagram:
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.
Nice! How long did it take you to code up the AJAX client?