LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Has anyone implemented JavaScript Object Notation in LabVIEW?

Hi Guys,

 

I was looking at writing an application using JSON-RPC

http://en.wikipedia.org/wiki/JSON-RPC

 

Has anyone implemented something similar, or are there any examples of this?

I was going to write it with TCP VIs, and use string parsing to work through any responses, but if anyone had some advice, it would be appreciated.

 

Cheers,

 

Anthony

0 Kudos
Message 1 of 18
(6,345 Views)

Hi Anthony,

 

I don't have any example code to offer you, but I do think you're on the right track using TCP VI's. That is often how I've seen LabVIEW implemented with HTML or Java. Are you looking to have LabVIEW passing data to a website, or set up a server/client scheme? If you post more information about your final goal, you'll likely get better advice on the forums.

 

One thing you might want to look into is LabVIEW Web Services. http://zone.ni.com/devzone/cda/tut/p/id/7350 In LabVIEW 8.6, we introduced this service, which makes it very easily to work with LabVIEW and common web languages like JavaScript. If you have 8.6, this might be an easier way to get what you need out of your program. Check it out.

Product Support Engineer
National Instruments
0 Kudos
Message 2 of 18
(6,317 Views)

Hi LaRisa,

 

I was looking at implementing JSON-RPC, JavaScript Object Notation Remote Procedure Call.

 http://en.wikipedia.org/wiki/JSON-RPC

 

I have LabVIEW 8.0, and was looking at developing something for an earlier version of LabVIEW, 7.1 for compatibility reasons.

So it is similar to a client/server scheme. 

 

I will check out the details of the Web Services in version 8.6, but I don't think there will be direct support for JSON-RPC.

 

Cheers,

 

Anthony

0 Kudos
Message 3 of 18
(6,311 Views)

Will LabVIEW be the client in your application, or the server? It is calling into your JSON webpage, or building it?

 

LabVIEW can import a web service beginning with version 8.2. LabVIEW can build a webpage beginning with Web Services in version 8.6. Outside of those functions and versions, I think you'll have a hard time getting to what you're looking for. But with more information, maybe I can help....

Product Support Engineer
National Instruments
0 Kudos
Message 4 of 18
(6,282 Views)

Anthony,

 

This sounds like a very interesting project and I would like to hear how it goes for you.

 

You can of course choose to implement a JSON-RPC system using either TCP or HTTP as the transport. TCP would give you a potentially more responsive system but you would have to implement much more of the system from scratch as it were.

 

As LaRisa_s was saying, if LabVIEW 8.6 is available to you, you can take advantage of the Web Services feature which will do a lot of the work for you. Your VI that runs as a web service would have to parse the data sent from the client to determine the correct VI to call and then convert the parameters and call the VI.

 

You are completely correct that there is no direct support for JSON-RPC. We evaluated several Web Service and RPC mechanisms before deciding on RESTful web services for LabVIEW 8.6. In fact, if you have LV8.6 and JSON-RPC isn't a hard requirement, I would strongly recommend looking at using the RESTful mechanism that is built in. If you can use it then much less work will be required of you on the server side of your application.

 

If you do need to go with JSON-RPC I would be interested to hear what factors went into the decision so we can improve LabVIEW's built in web services.

 

Either way- let us know how your project goes.

0 Kudos
Message 5 of 18
(6,279 Views)

Hi Nathan, Hi LaRisa,

 

I am trying to interface to a third party device, which uses JSON-RPC as an optional interface. So you send requests to it using JSON-RPC, which it uses to send the data back.

So I think my best way of utilising this would be using the TCP VIs. It will be a little more work, but more control and faster responses with the application.

 

I will let you know how the project goes, but it will take a while.

 

Thanks for responding.

 

Cheers,

 

Anthony

0 Kudos
Message 6 of 18
(6,269 Views)

Rats! That means my previous long-winded comment was wholly inappropriate as it was about the server code only. 🙂

 

I agree that the TCP primitives should work well for your client.

 

Nathan

0 Kudos
Message 7 of 18
(6,265 Views)

It was appreciated nonetheless.

Smiley Happy 

 

Cheers

 

Anthony

0 Kudos
Message 8 of 18
(6,262 Views)

Hello All

 

I have the same requirement as above.

 

I am connecting to a device known as the Sunny WebBox, which is pretty much a data collector with a web-based server integrated.

 

Communication with the device is RPC via HTTP. Once a connection is opened to the device a service procedure is sent to the server using JSON data format (see below)

 

{

    "version":"1.0",

    "proc":"GetDevices",

    "id":"1",

    "format":"JSON",

}

 

 

The server responds with the following:

 

{

    "version":"1.0",

    "proc":"GetDevices",

    "id":"1",

    "result":

 

    {

      "totalDeviceReturned":6,

      "device":

 

      [

 

and so on

 

I have been successful in opening a session to the server, but am having trouble writing and reading the responses from the server in this format.

 

I've spent considerable time working on this but am desperately getting lost.

 

Would anybody be able to give me a hint as to the way of going about doing this in Labview

 

I have at my use Labview 8.2, 8.6 and 2009

 

Thanks in advance.

 

regards

Ray

0 Kudos
Message 9 of 18
(5,527 Views)

Hey Ray,

 

Have you solved this issue yet? I'm also working with Sunny Webbox and communicating using RPC. However, I',m using UDP functions since it was what I was recommended to use. I'm having touble with the reading part of the program, apparenlty it times out before it reads anything. I've increased the timeout and the byte size, but I keep getting the same result.

 

Here you can see the VI  that I've built so far.

http://forums.ni.com/t5/LabVIEW/How-to-get-real-time-date-from-Sunny-Boy-Inverters-through-SMA/td-p/...

If you have any advise, please let me know. I am available to help you if you are still having trouble with the program.

 

Thanks,

 

Jose

0 Kudos
Message 10 of 18
(4,545 Views)