LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Incorrect data across datasocket

I have a global which contains an array of booleans.  I am publishing them over datasocket server, then I read/subscribe to them on a remote machine back into a global.  This procedure has seemed to work great except in one instance.  I will change the value of one of the booleans, the update is seen correctly on both the local and remote machine.  Then when my local machine calls a sub VI or launches a sub VI with VI server, the remote value will fail back to its original state that existed before the change.    My first instinct was to blame VI server but it also exhibits the same problem when a sub VI is called?  I'm baffled so any thoughts would be appreciated at this point. 
 
P.S.  Please don't harrass me for using globals!
0 Kudos
Message 1 of 13
(4,029 Views)

Hello gold,

The problem here is almost sure related to a sub-VI reinitializing/rewriting the value of the global.  I would recommend taking a look at all the code in your project -- make a list of all of the readers and writers of the value to make sure there are no places where the global is being updated in an unpredictable way. 

Careful use of globals does have a place in programming, so no harassment here!

Hope this helps,



Travis M
LabVIEW R&D
National Instruments
0 Kudos
Message 2 of 13
(3,998 Views)
That was the first place I looked too!  I was just sure it had to be initializing the global.  Well, I haven't seen it, yet.  There are two instances that will cause the problem. 
 First, is when I call a subVI, using vi server, the entire subVi is in two pages of a sequence.  The first page is an event structure the second is simply a close vi reference.  So the value of the global will "dissconnect" when the vi is simply waiting in the subVi event structure, with no other processing going on.  The value of the local unit retains the correct value but somehow the remote loses synch with the local, though no errors are reported, and all other datasocket values remain consistent.
 
Second is a direct call to a subVi.  Meaning that I have called it by placing the icon on the back panel vs. calling it with vi server.  This second subVi is merely a menu, so once again the disconnect occurs when no access to the global is being made.
 
I'm pretty stumped!  I can send my app but its pretty large and involved??
0 Kudos
Message 3 of 13
(3,993 Views)

Hello,

I believe that the problem is related to the nature of global variables.  When a global variable is no longer in memory, it reverts back to its default state.  All it takes to keep a Global (really just a special type of VI) a Global in memory is to have 1 VI with a reference open to it.  Your remote machine does not keep any references open to the Global since the scope of that Global is limited (right now...... 😉 ) to one machine.  It sounds like your server machine might be closing references to the Global when it is not in use -- thus resetting it to its original state.  I would try an experiment where you have a VI open on your serving machine which does nothing more than keep the Global in memory.

Thanks for posting, and please let us know if this works!

Travis M
LabVIEW R&D
National Instruments
0 Kudos
Message 4 of 13
(3,978 Views)

Currently the server side reads the status of the global continuously 4x a second.  The remote also reads the global at the same rate. So wouldn't that keep the variable constantly in memory? The only difference is that the remote global gets its data by subscribing to datasocket server, whereas the server/local gets its data from the data acquistion. 

When I open the global VI I can see the correct value on the server side, and when I open the global VI on the remote side I can see the correct value initially.  Then I can see it change when the subVI is launched. 

Another mystery is that I actually have 2 servers (both running the identical app), the remote can select between the data from server1 or server2.  I am only seeing this behaviour on #2.

IF you care here's the details of how I select between the two servers:  I have two sets of globals (on the remote), each set are identical except for the name of the vi.  They each will subscribe over datasocket server (DSS) to their server ie....globals1 to server1 and globals2 to server 2.  The remote will then display the global data from globals1 or globals2 depending on the operator selection.

gold

0 Kudos
Message 5 of 13
(3,965 Views)
Here is a chopped down version of my code....
 
[Attachment removed per customer request.  See attachment in later post.]

Message Edited by Support on 10-18-2005 12:31 PM

0 Kudos
Message 6 of 13
(3,928 Views)

For those of you who may be interested and look at my code and ask, what the heck is this.......

To see the error/problem I am having you must do the following. 

  1. Extract the drms.zip code to c:\drms  (it is in my previous post)
  2. Copy the vi datasocket reader to a remote machine
  3. change the frontpanel datasocket connection on datasocket reader.vi to subscribe to the machine which will run the main VI.  (server) 
  4. Run the datasocket reader.vi
  5. Run the drms main.vi on the "server" computer
  6. start datasocket server (on the server machine) 
  7. on the drms main.vi  select administration (F1)
  8. Select initialize DCM, initialize DCM1 by clicking initialize
  9. select initialize DCM again, Initialize DCM 2.
  10. you should be able to see on your remote datasocket reader.vi the value of the global boolean element #1,#2 turn to false.
  11. on drms main cancel the administration vi.
  12. again select administration (F1)....

FINALLY.....with no other action you will see (on the remote, datasocket reader.vi) the value of the boolean #2 revert back to its default value.  This is an unexpected behavior.   If you continue and Initialize another DCM, the value of #2 will change back to its "proper" value.  But the next time the administration is selected the remote will again revert back to default. 

I know this seems complicated, but its a problem that I have been hacking at for 2+ weeks now so anyone with ideas is welcome.  I have enlisted NI tech support so I'm not alone but we can always use more brains!

Thanks

 

0 Kudos
Message 7 of 13
(3,920 Views)

Sorry I forgot to put a wait in my administation.vi, so it will tend to hog your processor. Either add a wait ms or download this new one.

  This set has the fix

 

0 Kudos
Message 8 of 13
(3,916 Views)

Hi Gold,

It will be hard to help without beating you up about using globals Smiley Wink but I will try.

An "interesting feature" of arrays stored in globals can be observed when the array is updated from more than one chunk of code.

Here goes.

1) App starts up and writes a global array of booleans to all false.

2) The app starts running and two VI's A & B will try to set the boolean that reflects their state in the global.

3) A reads the array from the global and a copy of what was in the global gets put one of its wires for use latter. Lets say it goes first so itt find an array with all the booleans clear.

4) B wants to do the same some it reads the global and just like A gets a copy of what is in the global. Because A has not written yet, it sees all cleared booleans.

5) A does a replace array subset on the copy it read and then writes the data to the global.

6) Looking at the global at this time, everything looks OK.

7) Meanwhile B does its replace and writes to the global BUT it does not "know" that A had set its boolean. It updates the global and wipes out what A had done.

 

Semaphores can be sued to prevent this situation but there is an easier way.

If the boolean array was in a shift register of a functional global, the two VI A & B could invoke and action that sets their bit. Since the functional global is NOT re-entrant, B will be forced until A is done and the data in the shit register is updated.

Trying to help,

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 13
(3,890 Views)
Thanks Ben,
 
At this point any input is good input.  I understand the issue that you are explaining.
 
We use named semaphores to control any writes to the globals.  Not that I am discounting any possible cause at this point.
The interesting part is that the value observed on my server machine is a correct value.  The app is controlling writes and I don't seem to observe any race type conditions. 
 
The problem comes in the remote values that are received from the datasocket, they disagree with the "server" values.  In other words I can watch the values on the server and remote ends of the datasocket and see them disagree.
 
Thanks
 

Message Edited by gold on 10-18-2005 02:37 PM

0 Kudos
Message 10 of 13
(3,889 Views)