LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use Window's scriptcontrol eval to parse JScript response from Java Server

I've been asked to create a program to send and receive data to our Java Server. I've never worked with Java or even HTML before but there is some working code written in VB that I've been working from to get me started. I have successfully made connection to the server using IWinHttpRequest which returns a parse-able string. In the VB code they used MSScriptControl.IScriptControl to parse the returned string into an object that they could query for different parameters like 'returnStatus' and 'returnType'. This seems like a great advantage over parsing the string in LabVIEW. However, the return of this functions is a variant that seems to be just an 'object'. I am not very familiar with LVOOP or OOP in general and so I have no idea what to do with this 'object'. I've tried creating a LVObject that contained a control for all the parameters in the return string, then take the variant from the scriptcontrol and Type Set it as my LVObject and remove the parameters through the Object's cluster. But that didn't seem to work. I would like to know if this possible or should I give up and just go with the long yet sure way.

 

I am using LabVIEW 8.5.1 on an XP machine. I think this would be easier if I had 8.6 or 2009 but alas I don't.

 

Attached is my trial VI

0 Kudos
Message 1 of 9
(4,665 Views)

Hey ntaINC,

 

Here's a link about LVOOP in LabVIEW 8.5, under the resources there are links to the National Instruments developer zone that should help you work with the object you're creating from the parsed strings.

 

http://zone.ni.com/reference/en-XX/help/371361D-01/lvconcepts/front_oolv/

 

Peter W.

0 Kudos
Message 2 of 9
(4,633 Views)

Peter, Thanks for your reply. The problem is I am not creating the object, Window's ScriptControl 'eval' function (an ActiveX Invoke Node) is returning the object as a variant. I understand the general concepts of OOP which is why I think I know what the object is 'composed' of but I don't know how to get the individual parts of the object into a form I can work with within LabVIEW. Since I do think I know what data is in the object, I tried to type case the variant as a LV Object who's cluster contained a control for each piece of data with the label of the control being the name of a part of the object but it didn't seem to work.

 

For example, if the string returned from WinHttpRequest was {"returnType":"True","returnStatus":"StringArray"} and I sent this throught the 'eval' function, the returned object would have 2 parameter: a string labeled "returnType" having a value of "True" and another string labeled "returnStatus" having a value of "StringArray". I tried creating a LV Object that had two string controls labled "returnType" and "returnStatus" in it's cluster. I then created a constant of this LV Object and type cast the variant using this constant then tried to read one of the strings within the LV Object. The result was the default value of an empty string.

 

I think this should be the way to accomplish my goal but either I'm wrong or there is some nuance that I am missing.

 

Thanks for any insight provided.

Tessa

0 Kudos
Message 3 of 9
(4,626 Views)

It appears that the response is in the form of a list {"Name":"Value",...} which is easy pickings for a Regex.  Assuming the names are unique, Variants can also make life easy for you in the form of attributes which are Name,Value pairs.  Here is a LV9 snipppet showing one way to do this.  I prefer to work with variant attributes directly most times, but you can also extract string arrays or an array of clusters as I show.  LV8.5 version is attached.

 

ParseJScript.png

 

 

Message 4 of 9
(4,616 Views)

Oops.

 

ParseJScript_fix.png

0 Kudos
Message 5 of 9
(4,605 Views)

Darin, you've definitely shortened the development of my own parser for the string. I went this way today, since I have no solution to the object problem, and discovered that the return string for multiple pieces of data is not unique for the actual data. If my statement to the Java Server is to return a list of 4 strings the data portion comes back as "[{"valType":"value","value":"Dog"},{"valType":"value","value":"Cat"},....]. So for now, I've created an array of variants. I need to get more familiar with the types of data I'll be handling before deciding if and how to type the data. 

 

I will be using your solution for now but I don't want to consider this post solved since my original issue is with the object. Hopefully someone will come across this while trying to solve another problem and have an answer to my question.

 

Thanks,

Tessa

0 Kudos
Message 6 of 9
(4,582 Views)

hi

please what you are doing to create this pink scares ??

0 Kudos
Message 7 of 9
(4,428 Views)

Hello slimebdx,

 

There is a tool in LabVIEW that allows you to create a VI Snippet from a selection as follows:

 

Snippet.jpg

 

It seems as if the pink boxes were made in a third-party tool.

 

Regards,

 

Jeff L.

0 Kudos
Message 8 of 9
(4,410 Views)

thank you man

0 Kudos
Message 9 of 9
(4,407 Views)