LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

web service simple question

Solved!
Go to solution

I am using a Web Service to publish some data, and this question is, I'm sure, stemming from my limited knowledge and use of web servers.

 

I am able to set up an "add" method, pass 2 numbers to the web server, and have the web server return a value. Simple. But, I am not sure what to do when I want to get the current value of something that is being updated in a loop.

 

For example, let's say I have a VI like the one below, and the user wants to display the current loop iteration in their browser, not continuously, but only when they ask for it. I don't want to use this VI as the method to call. Instead, I'd rather this VI pass the current value to a VI designated only to return the numeric control value to the webserver. But, I have no idea how (or if) I can pass the iteration value to a method to be called. Does this make sense?

 

I have thought about using session variables, but this requires continually writing to the session variable in my code, which probably isn't a big deal, but it would be nice if it only queried the current iteration when the user asked for it (much like 2 numbers are only added when the user asks for it in the NI example). I'm looking for a way to just return the current value, only when the user asks for it. 

 

0 Kudos
Message 1 of 8
(4,141 Views)
Solution
Accepted by GregFreeman

You can do this, but it gets a little bit complicated.  The web server is its own application instance, and I don't think you can (or would want to) have a VI executing continuously inside it.  When you compile an application with web services enabled, you get two application instances - one running the application, the other inside the web server.  I assume your loop will be running in the main application instance.  Put a functional global in it that stores whatever value you want to be queried over the web, and make that VI accessible through VI server.  Then, in your web services VI, open a VI server connection to that functional global and run it, by reference, to obtain the value stored there.

Message 2 of 8
(4,128 Views)
Works very well. Thanks!
0 Kudos
Message 3 of 8
(4,108 Views)

I'm trying to do the same thing. I would like to acquire continuously with my DAQ and store the data in a FIFO-like variable and then, with a web service, get the data from the web. I can't understand your suggestion. Can you please explain a little more for me, please? I'm new to the LabVIEW web services so I don't undertand what you say about the functional global.

0 Kudos
Message 4 of 8
(4,075 Views)

You'll probably want to go through more LabVIEW basics before trying this, or consider another means of communication between your VIs such as shared variables.

 

A functional global variable is a VI that stores data in an uninitialized shift register.  The simplest implementation has a boolean input indicating whether to read or write, an input for data (when writing), and an output for data (when reading).  Search this forum for more information.  You will also see the term "Action Engine" which is a more sophisticated version of a functional global that implements additional actions that manipulate the data.

 

The LabVIEW web server runs in its own application instance - almost a separate program.  That means it cannot directly share data with the application that hosts the web server.  VI Server is a mechanism to allow one LabVIEW instance to access VIs in another instance.  In your main program, you would store the data in a functional global variable.  In the web server, use VI Server to get access to the same functional global.  You can then run that VI remotely, within the web server instance, and read data from it.  See the help and examples for VI Server.

0 Kudos
Message 5 of 8
(4,061 Views)

Hi,

 

I´ve tryed to follow your instructions but unfortunately I could´t see the data(String) from the server. The code in the image belongs to the VI "MBusServer20160407" which is the server VI

In this case the VI "MBusrespond" is the one running continuosly.

 

I would like to acces the data (String) when the client requires it but at the moment I couldn´t acomplished.

 

  

Download All
0 Kudos
Message 6 of 8
(3,657 Views)

Could you provide the actual VIs, rather than 2 small screenshots? I cannot understand how your code operates from the information you provided.

 

Have you checked the Error Out terminal after the VI Server call?

0 Kudos
Message 7 of 8
(3,629 Views)

Thanks for the response. I could solve the issue with a shared variable.

0 Kudos
Message 8 of 8
(3,580 Views)