This example shows you how to build a native Android application for simple data monitoring.
Simple Data Monitor (LabVIEW Project).zip
Simple Data Monitor (Android Application).zip
LabVIEW VI's can share data between other VI's using shared variables. In this example, we perform a single point acquisition, plot the point to a chart, and publish it to the shared variable.
LabVIEW Web Services allow any web capable device to access data from your application through any web interface. Your measurement application continually runs in parallel with your web service VI. When the web service VI is called by a web client, it reads the value from the shared variable, generates an XML string, and writes a HTTP response with the data back to the web client.
After you create your web service VI, you must deploy it within the LabVIEW project.
It can then be invoked via URL web request.
Additional Resources:
Getting Started with Android
This code snippet contains the core functionality. It first sets up a connection to the URL, configures the XML parser, reads and parses the XML from the input stream, adds the data value to an array of all data values received, and plots the array of values on the chart.
while (!mStop)
{// First, open a connection to the machine where LabVIEW is running
URL url = new URL(mURLText.getText().toString());URLConnection connection = url.openConnection();// Set resonable timeoutsconnection.setConnectTimeout(5000);connection.setReadTimeout(5000);// Create an XML document builder with the default settingsDocumentBuilder docbuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();// Parse XML from the web service into a DOM treeDocument doc = docbuilder.parse(connection.getInputStream());// Now, pull out the value attribute of the first channel elementString value = doc.getElementsByTagName("channel").item(0).getAttributes().getNamedItem("value").getNodeValue();// Create an array of data to add to the chart. There is only one// channel of data right now, so just add one point.ArrayList<Double> data = new ArrayList<Double>();data.add(Double.parseDouble(value));// Add the data to the chart.mChart.addDataPoint(data);}
This example may not work on Windows XP. After you deploy the Web Service from the LabVIEW project you may get a message that says it was deployed successfully, but if you look in Distributed System Manager 2009, the service won't be running. This Knowledge Base article gives some insight.
http://digital.ni.com/public.nsf/allkb/6063AFA6E5D95EAB86257792006082D4
I still couldn't get it to work on XP with LV 2009, so I switched to Vista and LabVIEW 8.6 and finally got it to work.
On the android side, prepare to spend an hour or two getting your environment setup and run the "hello, world" tutorial to make sure you have everything setup correctly.
Had some problems, typing the URL is quite tricky. You have to type it like this http://XXX.XXX.XXX.XXX:8080/MobileAPI/SampleTemp. The XXX.XXX.XXX.XXX is your IP. Also you have to solve the problem with the comma to make it work in the CreateXML.vi. Use the dot.
I can´t deploy it, I'm using LabVIEW 2010 32bits, Win7 64bits and USB-6009. Error message: "Web Services Deployment Failed. You must start the NI Application Web Server before deploying a web service." but NI Application Web Server is started. Some suggestions?
Hey Burzedion, check out this thread on the NI discussion forums: http://forums.ni.com/t5/LabVIEW/Web-Service-deployment-failed/m-p/1736702?requireLogin=False. It has a few suggestions you can try.
Hi Chris, thanks for your help. I tried to repair LabVIEW 2010 and still having the same problem. I don't know how to subscribe NI Application Web Server. Some others suggestions? Thanks.
Did you try some of the other suggestions listed on the thread? It may be worth posting details about your issue on the thread so an NI applications engineer can give suggestions.
Hello!
I have only one problem. When I want to connect to WebService I got an error on my phone:
java.net.SocketTimeoutException: Connection Timed out
Do you have any idea?
It sounds like you have a networking issue. Try typing the URL into your web browser and see if the web service responds. Are you sure the URL and IP Address is correct?
Hi, I have a problem with the Webservice.
When I click to run, the labview throws this message: "Error -67301 occurred at NI_WebServices.lvlib:Error Converter (ErrCode or Status).vi"
Do somebody have any idea? The httprequestID's value is 0, its good?
Thanks for help.
Here is a list of error code: http://zone.ni.com/reference/en-XX/help/371361J-01/lverror/web_services_error_codes/. Have you deployed the web service?
How to slow down the speed that android application calls webservice?
edited*
i knew the answer after post this comment. Thank you
Cannot open document for: /SmartPhone/SampleTemp
Hi Chris
Thanks for the code. I have an application which would require me to send around 1000 points every 10 to 20 ms to display in a chart in my phone. With web services, what could be the maximum rate of data transfer?
Thanks
Arya
我想知道这个程序该如何改改呢?谢谢!
你想改Android程序或者LabVIEW Web Service吗?如果你想学怎么改Android的程序,我推荐你上Android提供的资源:http://developer.android.com/training/basics/firstapp/starting-activity.html
Thank you for your reply。我出现的问题和arithmetic一样,LabVIEW: (Hex 0xFFFEF91B) LabVIEW Web Services: Invalid Request ID.不知道是什么问题?
I can´t deploy it, with Error message: "Web Services Deployment Failed". How can I go ahead