Example Code

XML-RPC Client for LabVIEW

Code and Documents

Attachment

Download All

Document to share XML-RPC client VIs for LabVIEW and provide feedback, suggestions, request, etc.

What is XML-RPC?

Specification

The first VI is a very simple XML-RPC client that sends a method call with numeric parameters to a server and receives the response.

xmlrpcfp.png

xmlrpcdg.png

[1/17/2010] Added a LV 8.0 version of the code. This VI includes a custom version of the HTTP Post VI as HTTP Post didn't exist in LabVIEW 8.0.

authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  

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

Comments
James_McN
Active Participant Active Participant
Active Participant
on

This looks really useful.  My interest is that I would really like to see a Robotic Operating System (ROS) interface in LabVIEW and this is certainly the first step.

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
mrutm
Member
Member
on

Please save in LabVIEW 9.0 because it was saved in LabVIEW 10. Thanks

DAKBIAS
davekorpi
Member
Member
on

http://screencast.com/t/sxlt6HtfQKkbYahooooooooooooooooooooo!!! Except for one EEEEENY beeny thing...

Can you save in LV 8.0? Or, put the names of the sub VI's so I can build it myself??

Label these..

http://screencast.com/t/sxlt6HtfQKkb

I am doing this for this project..

I want to be able to "query" the proto board much like I explain in this video... I want to replace Portal ( or run in concurrently.. kind of sloppy..)...
Used in this wireless product..
Christian_L
Active Participant
Active Participant
on

I added a version of the code saved in LV 8.0.

authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
davekorpi
Member
Member
on

Christian:


Still trying to get the SYNAPSE system to work with LabVIEW... I know it HAS to be simple....


First, have a script running called SNAP Connect that "listens" for commands issued from LabVIEW...


Then, hook up to the serial USB... as shown below....

CONN_TYPE_USB = 2 # From the manual your LabVIEW code calls for another localhost.. I want to be able to put this on my own URL and just call something like www.example.com/labview.html  Not sure how to do that....

srv = ServerProxy("http://localhost:8080", allow_none=True) # The Python XMLRPCLib way to connect to the server

srv.connectSerial(CONN_TYPE_USB,1) # USB0 is in fact the 1st

SNAP connect takes care of connecting to the device on USB0

You do not need any additional software on the USB stick as it can route/forward rpcs without needing a script. The remote device (ie the one taking the measurements) simply requires you to define the function you want to call over the air.

Here is an example (merely an example since I do not know how you will ultimately have your HW setup). Here the raw ADC value is reported back to the client for conversion. You can add a lot to this if necessary,  like reporting a node type/version, converting the data on the node, etc…

Def getTemp():

    returnAddr = rpcSourceAddr() # or can be defined or discovered – up to you

    TEMP_ADC = 1

     tempData  = readAdc(TEMP_ADC)

     rpc(returnAddr, “reportTempData”,  nodeName, tempData)

Or

    rpc(returnAddr, “reportTempData”, loadNvParam(NV_DEVICE_NAME_ID), covnertData(tempData))

or

    “Your choice”

At issue is just getting the thing signed up...

davekorpi
Member
Member
on

Still workin'..

Can not get the USB to sign up..

I am told this..

Here is what you would put in your application if the remote node had an address of 00.81.AA:
Ex.
srv.rpc(ourAddr, Binary('\x00\x81\xaa'), 'getTemp', 0)
Then define a function that listens for the response
Ex.
listenForResponse(srv):
    eventResponse = srv.waitOnEvent(ourAddr)
     # Now parse the event response for the function that was returned
    # The manual show the event response structure

Trying to do this using Christian's XML-RPC HTTP Post.vi and trying to

ForLV.png

I need to split up the commands into two, CHR and int.. but do not have the info on the format of the protocol...

I just want to put the necessary characters in the three input locations so I can get this silly thing to work.

Aaaaaaargh!


Anyone know?

davekorpi
Member
Member
on

ANYONE: 

How do you know what to put in the header? 

In Christian's example our header looks like this... 

POST / HTTP/1.0

User-Agent: National Instruments LabVIEW

Host: localhost

Content-Type: application/x-www-form-urlencoded

Content-Length: 196 

Specifically how do you know these two: 

POST / HTTP/1.0 and  and 

User-Agent: National Instruments LabVIEW 

I am told to make the SYNAPSE system to work I must put in this header.. 

POST /RPC2 HTTP/1.0

User-Agent: Frontier/5.1.2 (WinNT)

Host: localhost Content-Type: text/xml

Content-Length: 179 

Can you tell me why they use POST /RPC2 part in there?

Does this mean we need to have some files on the patc C;/RPC2? If so what files are required in there?

Where does the RPC2 part come from? 

And the user-Agent..

Where do we learn about that?

See SYNAPSE forum..

http://forums.synapse-wireless.com/showthread.php?p=6626#post6626

davekorpi
Member
Member
on
If anyone can get this LabVIEW to work with the SYNAPSE XML-RPC protocol put your post here...
davekorpi
Member
Member
on
1
Christian_L
Active Participant
Active Participant
on
Dave,   

The following and other similar headers are the HTTP header, and not part of the XML. Basically they are what make the HTTP Post call to the HTTP server running on the device you are talking to.   

POST /server.php HTTP/1.0 
User-Agent: National Instruments LabVIEW 
Host: phpxmlrpc.sourceforge.net 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 160    

HTTP is a protocol based on top of TCP, which is based on top of IP which is based on top of Ethernet.  In short there are about five layers of nested protocols. For your application, assuming the HTTP Post function is written correctly, you should not need to worry about anything other than the XML to be sent to your device.  In the case where the header starts with the following:   

POST /RPC2 HTTP/1.0   

/RPC2 represents the location on the server where the XML-RPC engine/parser/interpreter is located. In my example this was /server.php, but it may need to be /RPC2 in your case. You specify this location as part of the URL passed to the HTTP Post function and do not need to modify the HTTP Post itself.  If your server is located at 'localhost' the URL would be 

http://localhost/RPC2

In addition the port of the HTTP server is specified in the URL. By default it is port 80. If you need to use a different port (e.g. 8080) then it becomes part of the URL like this: 

localhost:8080/RPC2

I have updated the HTTP Post function for LV 80 and will upload the new VI to this document. The previous version did not support adding a non default port to the URL.  

Addition: I just found another issue that the SNAPConnect server may be sensitive to. The HTTP header contains a field called Content-Type. For XML-RPC this should be set to text/xml. My code does not do this. My test server did not care about this field, but the SNAPConnect server may. I will need to make another update to the VIs, but don't have time to do that right now. I'll get to it later tonight or tomorrow.  Is there some documentation available online for the SNAPConnect XML-RPC interface?
authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
Christian_L
Active Participant
Active Participant
on
.
authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
davekorpi
Member
Member
on

How does a provate message get below? How do I post a VI to share?

Why is the format of answers all messed up?

I always get this message: An unexpected error has occurred. Please make sure that your session did not expire while viewing this page.
davekorpi
Member
Member
on

Christian:

See the attached file that has all the elements they tell me I need but they

do not fully understand XML-RPC...

Thanks,

Dave

Dave Korpi Engineer

Website: www.MassFlowMetersAndControllers.Com

A Division of Take 5 Inc.

405 Monterey Avenue

Pacific Grove, CA 93950

dave.korpi@gmail.com

tel: 831-455-0418

<><><><><><><><><><><>

Cheapest VOIP, get rid of your expensive Land Line and keep the number!

http://www.dpbolvw.net/click-3314891-10588036?sid=phon

Christian_L
Active Participant
Active Participant
on

There seem to be some serious issues in the comment editing fields of NI Community right now, which is causing the messed up formatting and error messages.

If you get the error message 'An unexpected error has occurred. Please make sure that your session did not expire while viewing this page.' ignore it and assume your message has been posted correctly. Refresh the page.

authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
Gasson
Member
Member
on

Hi,

I need to communicate to RPC server running on port 7700 with a username and password. How do I this in labview? Does anyone have any examples?

As the example below?

Contributors