LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Not Understanding Data Value References

Solved!
Go to solution

Without knowing exactly what you are trying to do, I can almost guarantee you don't need to use a global variable, can pass the wire around - or better yet, use a messaging architecture to share data between code modules. Why are you so dead set on this design?

 

0 Kudos
Message 31 of 47
(1,254 Views)

@govindsankar wrote:

you can ignore this message, Iam going to use a global variable.


Have you considered using an Action Engine?

 

They are much easier to understand, encapsulate the data and associated methods and also protect against possible race conditions when you have multiple section of code that can act on the enclosed data.

 

Just trying to help,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 32 of 47
(1,254 Views)

What I want to do is initialise CAN Bus. I have a program where I have many classes CAN Bus is the one class and other classes are some micro controller boards that pass data using this CAN bus. So I want to intialise the CAN Bus in the CAN Bus class using the CAN init subVI. Then output of that is the initalised CAN bus. I need to use this iniatilised Bus then in each microcontroller board to pass data. If I use the sub VI it will keep on initialising again and again and will show an error. I just want the value of the initialised CAN bus and I need that value without using wires. So that was what I was trying to do. Just to give you an insight, as an example I will write a C++ code.

Class Initialise

{

int Initialise::init(int a)

{

a =2;

return a;

}

int main

int a;

int b;

Initialise objectinit;

b = objectinit.init(a);

}

Now see the above code, I am initialising the value of a to 2 and then storing it in b. Now I can use this b any class as I want. But in LabVIEW I dont know how to do this. The only way I know is using a subVI instead of that init method and using the connector pane and wiring the output of that subVI to other VI functions. But then if I do that every time I run the program the value of a = 2 keeps on initialising. I dont want that, I just want it to initialise once and so far the only method I know is using global variables. 

0 Kudos
Message 33 of 47
(1,238 Views)

Hi govind,

 

I just want the value of the initialised CAN bus

Use a wire. Branch the wire to use its value in any place you need.

 

I need that value without using wires.

Why don't you obey THINK DATAFLOW?

 

Btw. reading textual code without proper indentation is quite annoying. Guess what the "insert code" icon of the forum text editor is good for?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 34 of 47
(1,234 Views)

   KNIGHT OF NI wrote : Have you considered using an Action Engine?

 

Thank You for that info. DVR was a new concept to me. So I learnt DVR to do this. Then problem started and I started this thread and kept asking doubts. Now I will learn action engine and try to do this. But I will have to warn you, if i couldnt get it right again I will start asking more doubts like this. I will be learning from youtube and google. I will try to gather as much data to learn it. If you know any good material that will help me learn this, kindly do tell me. 

0 Kudos
Message 35 of 47
(1,233 Views)
Solution
Accepted by govindsankar

What you are looking to find is a Singleton where there is guaranteed to be only one instance.

 

There are many ways to accomplish that but one way (that is not strictly LVOOPish) including an Action Engine.

 

Crate an AE that has at least two actions;

 

Create

Get

 

In the crate you crated the DVR and store the ref to the DVR in the internal cache (shift register, Feedback node) of the AE. You could get fancy if you like and use a First Call node to indicate that the DVR needs created on the first call but leave that to the side for now...

 

Now evry place in your code where you have instances of your various classes can invoke the "Get" method on the AE to pull out the reference to the single DVR that had been created and then push that reference into the private data of the class. Since all of the instances will be grabbing the exact same reference (it is just a number that can be used to find the DVR) they will all be acting on the same DVR instance.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 36 of 47
(1,231 Views)

Hi govind,

 

I will be learning from youtube and google. I will try to gather as much data to learn it. If you know any good material that will help me learn this, kindly do tell me. 

Why don't you use the Training resources offered (mostly) for free in the header of the LabVIEW board?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 37 of 47
(1,229 Views)

@govindsankar wrote:

   KNIGHT OF NI wrote : Have you considered using an Action Engine?

 

.... If you know any good material that will help me learn this, kindly do tell me. 


This forum is the best resource that you can find (without issuing a Purchase Order Smiley-wink).

 

But I think you are not making the most of it because ...

 

you are not posting complete sets of code. (The group here are volunteers and will seldom write custom code to teach someone if they don't see a true effort)

 

You should watch your code in Execution highlighting, and use probes here and there. Watching the LV code run in Execution Highlighting mode (until you can predict what will happen where and when) will help you understand "Data Flow.

 

In one of your images you shared you branched a LVOOP class wire. That "branch" resulted in a copy when the wires diverted from the branch. At that point you had two copies that were both unique so one worked and the other branch did not.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 38 of 47
(1,229 Views)

@GerdW wrote : Why don't you obey THINK DATAFLOW?

 

What do you mean by use a wire? From where should that wire come from. So I have initialised the can bus in the CAN class and now I am going to the 1st board. It takes thermal readings so its called a thermoboard. For communicating with this thermo board I will need to use an initialised CAN bus. So how can I get that value. Its in a separate class. So how do I branch that wire from the CAN class to the Thermal Class. The only way I know is using a VI in the CAN class as a subVI in the thermoboard Class. But then when I run the thermoboard class method, this subVI will get executed again which means the CAN bus will be initailised again and it will give an error. I dont want to initialise it again. I just want that final value of the subVI. I dont want that subVI to execute again. So how can I do that. At the moment, only two options are available for me that is either use a global variable or use queues. But I cannot use queues because thermo board is not the only board I have to work with, there are many boards. No of boards can increase in the future. So for every board I have to insert the initialised value inside the  queue and then dequeue it at each board. Since I dont know the number of boards, that is not a feasible solution. So only option for me now is global variable. Now you tell me please what is it that I am not obeying. I how should I use dataflow. Kindly help me understand. 

0 Kudos
Message 39 of 47
(1,226 Views)

If I have some time today I will throw together an example for you.

Message 40 of 47
(1,214 Views)