LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Web Services for a State Machine Based VI

Hello,

 

I am new to the Web Services approach but so far I have managed to build a simple VI which is used with Web Services to display a Graph and make some simple calculations.

 

However, I have a more complex application which uses a State Machine architecture to command some circuitry using the NI USB 6211 device. This program includes different states and all the action takes place inside a while loop. This loop uses shift registers to pass the states arround (the JKI State Machine).

 

My question is: Could such a program be used with the Web Services without modifying this structure?

 

In the programs that I have tried, if I place the execution inside a While structure then I get no result with the Web Services. 

 

An example of a simple program which includes a while loop and the Web Services approach would be helpful, if possible.

 

Thank you in advance.

0 Kudos
Message 1 of 12
(3,473 Views)

The web server and your application are two separate application instances, meaning you need a communication mechanism such as VI server between them.  I suggested one approach in this thread: http://forums.ni.com/t5/LabVIEW/web-service-simple-question/td-p/1828191

0 Kudos
Message 2 of 12
(3,454 Views)

The thread Nathan pointed to definitely helped me out. But, we were also trying to do something similar to what you are doing and you should really have the code running on the RT and the webservices querying it (also as nathand suggets). You don't want your webservice doing any sort of continuous running. Let me look at the code and see what was actually implemented (as I didn't end up doing much of this work, my coworker did) and get back to you. If I remember we did something with named queues, but this may be overly complex for what you're trying to do.

0 Kudos
Message 3 of 12
(3,452 Views)

Hello and thank you for the prompt reply,

 

I looked at the suggested link and I will try to implement a short program like the one presented there. 

I hope I will be able to do the following:

"  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."

 

Thank you again.

0 Kudos
Message 4 of 12
(3,440 Views)

Hello again,

 

I was trying to do what Nathand indicated.

 

1. "Put a functional global in it that stores whatever value you want to be queried over the web,"

 

So I opened a new Project and added the Index.vi just to generate the numbers continuously. This VI writes to a global variable entitled "GlobalOutput.vi".

This works as I have attached the jpg image.

 

2. "and make that VI accessible through VI server."

 

This I am not so sure I did correctly. I opened the Tools->Options->VI Server, and here at the section Exported VIs, I added the GlobalOutput.vi. I have attached the image.

 

3. "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."

 

Now I have created another VI, called ServerConnection.vi which runs the GlobalOutput.vi. I have attached the image with the error I get. Something is wrong in what I am doing. In the end I thought that I would create a Web Service for this last vi and basically be able to read the global variable.

 

As I understand it, you have a VI which runs locally, in a while loop and updates some global variables. Then another vi reads the values of those global variables.

It is this last vi that you should create a web service and interogate to find out the values of those variables. What am I missing?

 

Thank you in advance.

 

 

 

Download All
0 Kudos
Message 5 of 12
(3,434 Views)

You've confused a "functional global" with a standard global variable.  You need to create the former - which is an actual VI - and instead you've created the latter, which is basically only a front panel and cannot be run on its own.  Attempting to run a global variable as a VI causes error 1035.  A functional global is a VI that stores a value in an unitialized shift register.

 

In general it's a lot easier to help if you attach your code (if several VIs, zip them up) instead of images.

 

EDIT: Also, this may work in the development environment (or it may not), but at least in an EXE you will need to open an application reference to the correct instance, then pass that app reference to the open VI reference.  The application needs to be assigned its own port number (you can do this in the project properties) and you need to specifically connect to that port on localhost (even though it's the local machine), otherwise it will attempt to connect to the local application instance - the same one in which the VI runs - and won't work properly.

0 Kudos
Message 6 of 12
(3,412 Views)

Hello and thank you again for your reply,

 

As you indicated I have attached a zip archive of my vi's.

 

I would like to be able to read remotely, using Web Services, the values generated by the Index.vi.

 

In my project, the Index.vi writes in a global variable named StringOutputGlobal.vi.

 

This variable is read by the vi called FuncGlob.vi which I wanted to implement as a functional global variable.

 

This FuncGlob.vi is called using VI Server functions by the ServerConnection.vi. 

 

When I run it it all works fine. I create a Web Service for the ServerConnection.vi, I deploy this service and nothing. I always get empty indicators.

 

Thank you for all your help and I am sorry to bother you with this matter.

 

0 Kudos
Message 7 of 12
(3,402 Views)

What are you doing here?  The project doesn't include any of the files (when I open the project, there are no VIs listed under "My Computer").  You're trying to open a reference to "ReadGlobalVar.vi" but I don't see that VI anywhere in your ZIP.  The functional global variable should have "Initialize" and "Get" as an enumeration.  That enumeration should be a front-panel control so that you can decide when you run it which action to take.  You do not need the global variable.  Provide the functional global VI as the Type Specifier VI Refnum input to Open VI Reference, and then run the VI by reference with the action input set to "Get."  Do not use the deprecated Get Control Value method.  If you do not fully understand functional global variables (sometimes also referred to as a "LV2-style global" and see also the similar concept of an "action engine"), search this forum.  Also look at the examples provided with LabVIEW for VI server and running a VI by reference.  You may want to start with a simple example before attempting to implement this as a web service.  Also note again, as a I mentioned in my previous message, that you will need to open an application reference first, then open the VI reference.

0 Kudos
Message 8 of 12
(3,393 Views)

Hello,

 

I have attached what I have managed to do sa far. Please let me know if the archive you receive is missing some files. 

 

I have a Main.vi which writes data continuously to a Functional Global Variable.vi (I received this from Mr. Nathand). 

 

I have a Read.vi which reads data from the functional global variable asynchronously. This is a way in which I read it can be done.

 

I would like to create a Web Service which is able to present the data generated by the Main.vi.

 

What do you think?

 

Thank you in advance.

0 Kudos
Message 9 of 12
(3,381 Views)

Raul.Ionel wrote:

I have a Main.vi which writes data continuously to a Functional Global Variable.vi (I received this from Mr. Nathand).


Well, that's certainly not true.  I didn't supply the Functional Global Variable VI that you provided.

 

Did you test this at all?  What did you find?  Have you tried building it into a web service?  Why did you not also include the Project file, which would include the web service definition?

 

I do not understand why you insist on making this more complicated than it should be.  There's no need for the Start Asynchronous Call nor to set the options to 0x100.  Use Call By Reference instead.  You still have not added the "Open Application Reference" that I explained that you will need because the web service runs in a separate application instance from your main VI.

0 Kudos
Message 10 of 12
(3,374 Views)