10-31-2012 08:49 AM - edited 10-31-2012 08:50 AM
Hi everybody,
I have a question about the error code -2220 when using shared variables on a real time target and I was hoping to find some answers here.
I have 2 vi's that communicate with each other through a single process shared variable with real time FIFO enabled. The vi that reads from the variable executes faster than the vi that writes to it, so I need some kind of indicator to tell me if there is a new value or not. I do not want to process the same variable more than once.
I've found on the internet that you can use the shared variable error code -2220, which indicates that the FIFO is empty. But I've done some testing and it looks like there is no error code at all. The code just stays 0, no matter how many times I read out the same value.
Can somebody tell me what I do wrong, and perhaps how I should be using the shared variable to do this?
Thanks in advance,
Dries
10-31-2012 09:43 AM
Dries,
Thanks for your post. I did some work and I encountered a similar problem in a project I worked on. If you are passing data between a Windows Host and a Real Time (RT) Target then I would advise using streams to pass the data.
On your RT Target you can have a deterministic high priority loop that performs your data acquisition, and then using a shared variable pass this data inside a non-deterministic loop to a stream. You want to read the data at a faster rate than you write so that you don't miss any data but this could cause you to read an empty variable and get the error -2220 you identify in your post.
In this case use a case structure so that if this error comes, do nothing and clear the error and if there is no error then pull the data from the shared variable and write it into the stream. You can then read elements from the stream on your windows host at a (much) slower rate and process data there. You may need to have a play with some timings to count at the rate you desire.
I have attached a zipped file of the project I used so feel free to use the methods.
Regards and best wishes with your project,
10-31-2012 09:57 AM - edited 10-31-2012 10:01 AM
Hi Rob,
Thank you for the quick reply.
I only want to pass data on the real time target from one VI to another, not between host and target (forgot to mention that). But the problem is that no matter how many times I read the 'single process shared variable with RT FIFO enabled', the error code stays 0.
I write the variable in a deterministic loop at approximately 1 sample/second and I read out in a non-deter. loop much faster, but the code stays 0. Should I enable timestamps or something else? In the attachement you'll find the code in the non deterministic loop.
Btw; I can not read you're example because I run labview 11.0
With regards,
Dries
10-31-2012 11:56 AM
Dries,
Let me know if you can get the attached folder in LV v11.
When you create a variable in your library folder they can have Variable Type as Network Published or Single Process. From the screenshot you have it appears your variable, PointCounterSP, is Single Process whereas IrrCluster is Network Published.
Also when you enable RT FIFO, you can make it a Single Element or Multi Element. Can you tell me which of the two you use? I used Multi-Element and it worked for me, easy as pie, so give that a go and let me know if thats it.
Regards,
11-02-2012 08:44 AM
Hello Dries and Rob,
I you're staying on the same target and just want to communicate between two VI's, then RT FIFO's could be a great solution.
Next to being a simple and good solution, they should also be more efficient than a Shared Variable approach.
If you're wondering on how you can use them from inside different VI's, then you have to remember the following:
Just like with queues and notifiers, you can refer to them by name in the Create RT FIFO VI.
If the FIFO already exists on the target and you set the "create if not found" input to true, then you will only create it with the first call.
All the other calls to the create function (with the same name) will just return you the existing reference.
Because of the (small) delay caused by the creation of a new RT FIFO, it might be useful to do this in a sort of initialization stage.
If you would like me to make a small PoC of this, then don't hesitate to ask me.
11-05-2012 02:52 AM
Hi Rob,
Now I can open the project with LV11. Thank you for that. But it seems that you only use network published shared variables instead of single process shared variables. I only want to read from and write to the variable on the RT device so I thought I should use single process shared variable.
The PointCounterSP variable (single-element) always returns the error code '0', no matter how many times I read from it. In a deterministic VI, the variable PointCounterSP is written at a rate of 1 sample/second. In the VI from the screenshot, this variable is read much faster and written to a network published variable (IrrCluster) with RT FIFO enabled (multi-element). I only want to write to the network published variable if there is a new PointCounterSP value.
Regards,
Dries
11-05-2012 03:08 AM
Hi Thierry,
I'll try to work with the RT FIFO and I will let you know how this goes. I can use the 'RT FIFO Communication.vi' as an example.
Thanks for the help.
Dries
11-06-2012 02:54 AM
Dries,
Thank you for the update; I hope you are making progress. Is it possible for you to zip up your project and upload it so I can take a look at it please? I can only help so much without code as the error may not be the variable in this case but something else.
Regards,
04-03-2015 09:45 AM
Hi Rob,
I now have the same problem which Dries had. But I use a desktop PC communicate with a sbRIO9626. I sent a array of 5 doubles to a shared variable 'UI2RT', networked-published, RT FIFO enabled (single element, 5elements), I always read the errorcode as '0'. Please help.
Thank you in advance,
Kind regards,
Qing