LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write and Read VIs need to work at 2 locations

I have attached a project. There are 3 VIs, 2 VIs under the class Test Class, i.e Write and Read. A numeric control in write and an numeric indicator in read. Then these sub vis are then copied into the main project, which is outside the class where I wired a numeric control to the write vi and numeric indicator from the read vi. Now I run the program continuously using while loop. Now when I enter a value in write I need the read to show the values. But nothing is happen. I am doing this as a test to another project where I enter values in one point and I get the values at another point during a special case. For that to work, I need to make this work first. Also please I donot want to use functional global variables. It has to be object oriented programming and class because I am trying to understand oop. I have done a some reading and I thought i know how oop works and now I know i dont know anything. Kindly do help me. Thanks in advance. 

0 Kudos
Message 1 of 11
(1,128 Views)

I see 2 main issues:

 

1. You are not using the output of the Write.vi.  LabVIEW uses a By Value OOP.  So all that matters is the data on the wire.  Since you are reading the value of the object before the write was done, you will get the "old" value and the "new" value is never used.

 

2. You are overwriting your value in the Read.vi.  That makes absolutely NO sense.  The Read.vi should only be reading the value.


GCentral
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 Kudos
Message 2 of 11
(1,102 Views)
0 Kudos
Message 3 of 11
(1,097 Views)

write and read.pngI know about programming this way. I have done it and got the output. So what you are telling me is that I cannot use these 2 VIs in 2 different position. I need to connect the class output of write to read. So two use the same values in 2 different places, the only way possible is a functional global variable. Is that right?

0 Kudos
Message 4 of 11
(1,082 Views)

@govindsankar wrote:

I need to connect the class output of write to read. So to use the same values in 2 different places, the only way possible is a functional global variable. Is that right?


By two different places, do you mean two different loops?  If so, I would use a Data Value Reference (DVR).  A DVR uses the In Place Element Structure to access the data and prevents some types of race conditions.


GCentral
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 Kudos
Message 5 of 11
(1,064 Views)

If you'd copy this code, to a 2nd loop, you'll get 2 objects. They won't communicate with each other. That's usually the desirable effect.

 

There are tons of solutions that provide synchronous access to data:

FGV, DVR's inside the class, the class inside a DVR, normal globals, class private globals, single element queues, uninitialized shift registers, feedback nodes...

 

You can also try to avoid it. For instance, when the write loop has 'written' (is done with the object), it can send it to the read loop in a queue. This is again more restrictive (common theme) as true async access that a by reference object would provide. And that's why I like it...

0 Kudos
Message 6 of 11
(1,062 Views)

not differelent loops, different vis. I need data in one vi accessible in another VI

0 Kudos
Message 7 of 11
(1,048 Views)

@govindsankar wrote:

not differelent loops, different vis. I need data in one vi accessible in another VI


VIs within the same loop?  Does one really depend on the other?

 

It is to the point where you need to give a better example of exactly what you are trying to do.


GCentral
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 Kudos
Message 8 of 11
(1,043 Views)

loops arent important . I have two sub VIs and both these VIs work in the main VI. One VI accepts data and other VI at another position in the MAIN VI maybe in a different case need to ouptut the data that other VI accepted. But from what I have heard it is not possible. The only way to do that is to connect the first VI to the second VI, but then they cant be in 2 different cases. So can it be done by any method or this is the only way to do it.

0 Kudos
Message 9 of 11
(1,040 Views)

@govindsankar wrote:

loops arent important . I have two sub VIs and both these VIs work in the main VI. One VI accepts data and other VI at another position in the MAIN VI maybe in a different case need to ouptut the data that other VI accepted. But from what I have heard it is not possible. The only way to do that is to connect the first VI to the second VI, but then they cant be in 2 different cases. So can it be done by any method or this is the only way to do it.


What do you mean by two different cases? Case structures? If they are in the same loop, you can put the object on a shift register and pass it through each case. 

 

Important to understand that classes in LabVIEW are by value, not by reference as in most other languages. If you have two class wires that are not connected, they are completely separate instances of the class. Moving data around your application can be done in many ways - whether it is LVOOP or not doesnt really change that. As you are starting out, you can think of a class as just a special cluster.

 

To share the data, you could make your class by reference by putting the class itself in a DVR, or class data in a DVR. You could just enqueue the data to wherever it needs to go, use a user event etc. Whatever choice you make should align with the rest of you application design. What is your application doing? Where are you calling the method to acquire the data, and where does that data need to go?

 

This link may be helpful as well.

http://www.bloomy.com/support/blog/object-oriented-labview-inheritance-part-1-3-part-series

0 Kudos
Message 10 of 11
(1,034 Views)