ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

取消
显示结果 
搜索替代 
您的意思是: 

Shared Variable notification speed - GUI separation

已解决!
转到解答

Hello,

 

I am currently developing a LabView application that heavily relies on shared variables to separate the GUI from the core logic of the software. Some of the variables are used as triggers, meaning they are booleans which are checked by the server (core application) side for "true". If that is found, they are reset to false and some action is performed (like enqueuing a message to an internal queue).

 

The attached image shows such a situation where the checking of the boolean trigger is done in a loop. Now, what I found is that the same message gets enqueued multiple times. The "Save Thermal Calibration" SV is read in the loop, reset to false and read again in the next loop iteration. But apparently the SV server is too slow to notify the accessor about the changed value before the next loop iteration.

 

I encountered similar behaviour on some other positions in the code and so far solved them by adding a "Wait (ms)" for approx. 200 ms. However this feels quite ugly and I am wondering if this could break if at some point the load on the server app increases and the SV server becomes even slower.

Also, I am wondering if there is a way to speed up the SV server communication, especially when writing values and notifying other SV accessors about changes.

0 项奖励
1 条消息(共 9 条)
4,987 次查看
解答
已被主题作者 ehrlich 接受

Network Published Shared Variables are slow.  There is no real way around it.  And, yes, when you write a value that value is not really in the variable until the NSV Server handles it.  And when the value actually gets sent to the server can be in the 100 ms range.

 

If you are actually talking to another computer, I recommend changing to using a Network Stream or TCP/IP.  This way you have actual messages commanding the server what to do.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
2 条消息(共 9 条)
4,964 次查看

Thanks for the quick reply. I guess I have to live with the waiting then.

 

Currently, I am not really talking to another machine but I want to keep that option for the future (have some kind of control-app with more decision taking running somewhere else). But also, I would like to be able to "connect" multiple GUIs, controllers etc. at the same time so network streams would make everything much more complicated. Shared variables look like the best option to me.

0 项奖励
3 条消息(共 9 条)
4,942 次查看

Hi Ehrlich,

 

You have a calssic "Race Condition" that can be corrected using an Action Engine, or a a DVR.

 

The Nugget I linked includes an example using normal global variables. Action Engines and DVR when properly designed and used, will prevent the race condition.

 

SO you do NOT have to live with the limition you found nor do you need teh artificial delays that as you obesrved, only work up to a point and them you will have to fix it again.

 

I hope that helps,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 项奖励
4 条消息(共 9 条)
4,889 次查看

Hello Ben,

 

thank's for hinting me to that, it was definitley an interesting read and a new concept for me. I'll play around with it.

 

Thanks!

0 项奖励
5 条消息(共 9 条)
4,850 次查看

So the way I see it, I would loose the option to have the GUI running on another machine since the VI of the Action Engine is part of the server and the client has to sit on the same machine. Or am I mistaken here?

0 项奖励
6 条消息(共 9 条)
4,812 次查看

It depends on how you want to implement it.

 

The code doing the serving on the server side can use the AE OR the Action Engine could be invoked using VI Server where the proper action can be invoked by the client side using the served AE on the server side.

 

Or you could work out your own method to prevent the race condition using semaphres if you want.

 

Ben 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 项奖励
7 条消息(共 9 条)
4,786 次查看

Just to wrap this up and in case anyone else is having a similar problem: I solved one part of it in a rather bruther force way: The specific case of writing to a Shared Variable and reading it immediately after that. So usually, the SVE is too slow to return the new value then which is the main cause of my race conditions. The "solution" is a Sub VI that takes the new value, writes it and reads the SV until it returns the new value (The code has a few more steps for the case that the exact same value should be written).

 

Thanks for all the comments!

0 项奖励
8 条消息(共 9 条)
4,751 次查看

@ehrlich wrote:

Just to wrap this up and in case anyone else is having a similar problem: I solved one part of it in a rather bruther force way: The specific case of writing to a Shared Variable and reading it immediately after that. So usually, the SVE is too slow to return the new value then which is the main cause of my race conditions. The "solution" is a Sub VI that takes the new value, writes it and reads the SV until it returns the new value (The code has a few more steps for the case that the exact same value should be written).

 

Thanks for all the comments!


I would recommend changing that While Loop to a FOR loop.  That way you can limit how many times to try instead of possibly being stuck in an endless loop.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 项奖励
9 条消息(共 9 条)
4,743 次查看