LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Network Variables and repeated data being received

Hello people!
 
I use Network Variables with an Implicitly Created Variable (so there is a "single-writer" restriction).
Everytime I "publish" a data and use CNVDispose, I receive extra data (data with repeated values).
I learn from this Forum (and from CVI documentation) that this kind of think happens because the write-access attribute changes on the server.
My questions are:
Is there some way to avoid this extra data without change to Explicitly Created Variables?
And if I do not use CNVDispose at each write operation? Is there a problem?
Tipically my "write operations" are like this:
 
CNVCreateScalarDataValue (&data, CNVDouble, value);
CNVPutDataInBuffer (bufferedWriter, data, CNVDoNotWait);
CNVDisposeData (data);
 
Thanks in advance
Malafronte
 
 
 
 
 
 
0 Kudos
Message 1 of 5
(3,764 Views)
What kind of connection (CNVSubscriber, CNVBufferedSubscriber, etc) are you using to read the data?

Your code snippet does not show the CNVDispose call. Are you disposing the bufferedWriter after writing each data point? Do you really have to dispose the writer and recreate it for each write operation? If you do not dispose the writer, you should not be getting the extra item. There is not much cost to keeping the writer open until your program exits, so you should not dispose it unless you have other programs that also need to write to the same implicit network variable.

What version of CVI are you using? This problem is resolved in 8.5 with LogosXT. Also, if you have 8.5 are you disabling LogosXT by setting the HKLM\Software\National Instruments\LogosXT\DisablePSPXT registry value to TRUE? The best solution I can recommend is to use LogosXT. This is automatically available in the CVI 8.5 runtime engine.
0 Kudos
Message 2 of 5
(3,737 Views)
Mohan,
 
The kind of conection I'm using to read the data is Subscriber (using CNVCreateSubscriber) and to write is Buffered Writer (using CNVCreateBufferedWriter).
The code snippet was right, but in the last message I'd written CNVDispose, and the right function is CNVDisposeData (sorry about that!).
What I'm disposing  after each write operation is the data (CNVDisposeData) and disposing the data  in the Subscriber too (using CNVDisposeData inside the DataCallback function). I do this things like in the CVI samples (NVSubscriber.prj and NVPublisher.prj).
I only use CNVDispose at the end of the program.
I was thinking that the extra itens was a problem with the CNVDisposeData, and I do not know If the problem is in the Subscriber or BufferedWriter connection.
My CVI version is 8.1.
Any ideas?
Thanks for all!
 
 
 
0 Kudos
Message 3 of 5
(3,713 Views)
Ah! There was an issue with disposing the writer connection triggering an extra event. Are you sure it is CNVDisposeData that is causing the duplicate data? I would highly doubt that because CNVDisposeData is essentially just freeing memory in the writer program and should not affect the "connection" in any way.

It is possible that you are just getting mulitple events for each updated data point for some other reason. Check that your write call (CNVPutDataInBuffer) is not getting called twice unexpectedly. Also check the 'quality' of the data in the subscriber callback by calling CNVGetDataQuality - each time the 'quality' changes the callback is called even if the 'value' has not changed. If this is the case, then you can just ignore the event for the quality change - you should still discard the data for this event to avoid a memory leak.
0 Kudos
Message 4 of 5
(3,689 Views)

Dropping in my experience into this old thing in case it helps someone someday. I ran into a vaguely similar problem as malafronte did. In my case I was doing the following:

  • Wrote several pieces of data to an implicitly created network variable using CNVBufferedWriter very quickly
  • Tried to receive that data using a normal CNVSubscriber and the dataCallback event.

The result:

 

  • Application works during normal execution
  • During debugging the program sometimes can't Get the value from the network variable, first resulting in an error code/crash from the Get function, followed by the program resuming and receiving the latest data that was written to the variable some arbitrary number of times (I sent a string one character at a time, so I received "This is a test messagggg").
  • If I break the program, wait a minute or so, the above is more likely to happen.

I added a statusCallback event to my Subscriber, and noted that during debugging I lost contact with the network variable - resulting in a statusCallback event being triggered. I quickly regained contact again, but that seems to trigger a dataCallback event, which resulted in the last value being "caught" again. In my case I also experienced some errors due to the lost connection.

So the CNVDataCallback event seems to be triggered at network variable reconnection, and also possibly at disconnection.

In my case I switched to using CNVBufferedSubscriber instead. I still lose connection during debugging (probably has to do with the lifetime of a network variable),  but I'm at least warned by the statusCallback before trying to get any new values and getting stuck in a series of triggered events which multiplies my data.

0 Kudos
Message 5 of 5
(1,993 Views)