LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Not Understanding Data Value References

Solved!
Go to solution

I have attached another DVR project. Here I create a numeric DVR and then read the DVR data. This two are performed by two different operations - Create DVR data and Read DVR Data. Now this DVR data is stored in the object of the class. Now in the main program which is called numeric test, I have put this two VIs to read the Data. For the input class wire to both VIs, I have used a single Object and branched it to both. I know that branching makes a copy. But I thought since the value inside class object is a DVR, its only making a copy to the same reference. But then if that I was the case I should get the value which I entered as the output of read data DVR. But it is not happening. So what is the problem here please?DVR Data Problem.png

0 Kudos
Message 1 of 47
(3,958 Views)

The DVR is by reference, the class is still by value. So in your example you are creating two instances of the class - the second instance never gets the valid, created DVR. Wire the output of the first method to the input of the second. After creating the DVR, you can then branch the wire and each instance will have a copy of the valid reference. 

Message 2 of 47
(3,947 Views)

Ok, so DVRs are only good inside the IN Place Element structure. So there is no use of creating DVRs as data for class objects. If I branch an object it will create 2 DVRs. So then I need a help. I need to use a value which is initialized once in one VI and then use this same value at multiple VIs in the same project, but different child classes of the that single parent VI. So I need same reference to the same initialized value. How can I do this. One idea for me is using a global variable which might lead to race conditions. Other one is queues. But then I have to add this value many times to the queue and then dequeue it at each locations. Adding many times is not feasible. So what is the best way for me to initialize a value in one VI and use this value in many other VIs in the same project. 

0 Kudos
Message 3 of 47
(3,930 Views)

I think you misunderstood me - in your example image, what you are doing is no different than wiring two class constants into the methods. The class you pass into the read method doesnt have the active dvr reference! Create the DVR outside the loop. THEN branch the class wire.

Message 4 of 47
(3,924 Views)
Solution
Accepted by topic author govindsankar

I made some changes to your class - check it out. Writing in one loop, and reading in another, and using another instance to stop both loops. Again, the key is that you are branching the class after the reference has been created. 

Message 5 of 47
(3,923 Views)

That said, you seem to be convinced you 'need' this functionality - you don't. I think most LV programmers would agree that using some sort of messaging architecture is a much better way to pass data around your application than just sharing a class that has some data that is by reference. 

Message 6 of 47
(3,916 Views)

Thank You Very Much, I believe I got a handle on DVR. Will know tomorrow when I go to office and try to implement this in my project. 

0 Kudos
Message 7 of 47
(3,909 Views)

I have created a simple write and read numeric value project with these functions in 2 vis which is in one class. Now the object of this class has a DVR of a numeric value. Then I created the create DVR vi which creates the DVR. Then in the main program, I branched the create DVR to both Write and Read VI. Then when I ran it, it worked fine. The value that was written into write was read from the read vi. Now instead of branching I made a copy of the create DVR and gave the first Create DVR to write and the second to the read. But then it doesn't work: Can anyone please explain me what is the difference here.I think I know. I believe while branching I just create DVR data and giving it to many, but while I am making a copy, then I am creating two different references. I think this is the reason. If this is the reason, what can be done to achieve my second operation, because in my project, the write and read are not used in the same VI. I need to write at one VI and read in multiple VIs. So how can I achieve that.DVR Data Problem 2.png

0 Kudos
Message 8 of 47
(3,867 Views)

Did you read the proveious messages before trying to create a new thread for the same topic?

 

I need to write at one VI and read in multiple VIs. So how can I achieve that.

Use a wire and connector panes to forward the class object.

THINK DATAFLOW!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 47
(3,862 Views)

yes I read the previous messages and then I tried it on my own. I found out my previous mistake was I was not creating the dvr object. I found out I have to create dvr object and pass it to my method vis which uses that reference. But what I didnt know is I cannot copy the dvr create vi which will create two dvrs instead of reference one dvr at multiple locations. 

0 Kudos
Message 10 of 47
(3,859 Views)