From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Excute vi only one time after device power on

Solved!
Go to solution

Hello everyone,

 

I try to control flow rate by manipulating a pump speed. Before I can send command to the pump I have to initialize it, such as numbering the pump. I think this step is after the pump is on and before my main program excute. Unless the pump is off and powers on again, the vi for initialzing the pump has not to been excuted.

I considered to use the local variable as a case selector to make it. However, I cannot.

There are two vi. files. I try to combine them into one vi. And the code can detect the situation (the pump is on and pump has no number) and excute the first vi. automatically.

The manual of the pump is 

https://pim-resources.coleparmer.com/instruction-manual/mf-lns-manual-enga-1299-1127b.pdf

The communication part is in page 44-52. (section 3-30---3-38).

I find that the command \05\r is for checking the pump status once the power on, and after the pump is numbered, the command \02P01I\r is for checking the status (let's set the pump number 01). If I still send the command \05\r to the numbered pump, there will be a time out error.

In one word, how to send \05\r to the pump only one time after the pump powers on.

Please help.

 

 

Qun

 

 

 

Download All
0 Kudos
Message 1 of 10
(3,423 Views)

Not able to open your VI, Try to Save in LV2015 and share.

Hope by using proper state Machine and Making separate Case for Initializing thePump and Call this state accordingly will solve your issue

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 2 of 10
(3,391 Views)

I forgot to unload one vi. Sorry for all.

The main code looks like this.

The subvi in the red circle is for initializing the pump (subvi 1). I hope it excute only one time after the pump powers on. If it can be merged into the subvi iconed PID (subvi 2), it would be perfect for me.

And now I am thinking leaving subvi 1 where it is and using case selector to automatically decide wether run it or not.

 

 

Capture0109.PNG

 

0 Kudos
Message 3 of 10
(3,352 Views)

You should be able to use "First Call?" to run the init function first time only.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 10
(3,349 Views)

@Yamaeda wrote:

You should be able to use "First Call?" to run the init function first time only.

/Y


I don't think I've ever used "First Call".  It seems that carefully thought out dataflow avoids that issue naturally.  (Every time I thought it was finally time to use it, it turned out I didn't need it after all - i.e., some flag always gets set or something similar that I could base my decision on instead, so by the time the decision to run or not comes around again, the decision has been made naturally.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 10
(3,330 Views)

I just use "first call?" to control the dataflow, it works perfectly. Although when I read the Labviewhelp, it says "this function is useful if you want to run a subVI or a section of a block diagram within a loop or Case structure only once when the VI runs" and I didnot think it fits my problem.

So I tried to remove the "first call?" and test again(as the attached file Main PID for NI). It works as well.

And I realized that the reason I want to get rid of the problem is I thought it will pop up the timeout error if I keep send the initial command to pump. However, if I donot need to read from the VISA, the error will not bother me.

Thank you all. You guys are best.

 

Qun

0 Kudos
Message 6 of 10
(3,324 Views)

Do you want Check Power On - for pump ini.vi to run before the while loop starts executing?  Because the way you have it coded there are no data flow dependencies between them.  Basically what I'm saying is there is nothing stopping the PID while loop from running many times, before the Check Power On vi is ran.  The two things are in parallel and it cannot be determined which will run first.

0 Kudos
Message 7 of 10
(3,316 Views)
Solution
Accepted by topic author chalkwu

Yes, "first call?" is probably most useful, but it will run whenever you restart the program, not only the first time after a reboot.

 

On a side note, you need to be really careful about race conditions, for example the code you showed can allow the while loop to start even while the pump initialization has not completed yet. If this could cause problems (not sure, I have not looked at the code), you need to create a data dependency. Easiest would be to add error in/out to the initialization subVI and wire the error out to the while loop boundary to ensire correct execution order.

 

Is this a startup VI of an embedded system or are you running on a PC?

 

0 Kudos
Message 8 of 10
(3,302 Views)

Not Sure why no one insisted to use Proper State Machine?

Init (Power On)

Poll (Acquire Data)

Power Off

Exit

 

Even in the Middle He can decide Like After Power OFF Again he can Power  ON and Acquire data, which will be Modular useful for Future Updates.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 9 of 10
(3,276 Views)

Hello, 

When I search "Proper state machine" in Labview help, there is no result. So I think I can not handle it quickly. However, I search in the forum, there are others poster relating "state machine", such as https://forums.ni.com/t5/LabVIEW/how-to-use-a-event-structure-with-a-state-machine/m-p/1330568#M5419.... I download their code, and I am not sure it is just what you said and I do not know how to use it. I will learn it definetly, because its logic fits my problem perfectly. At present although my code runs without much problems, I conside it is due to some tricks.(I donot read from the Visa, so there is no timeout error which I am worrying about. While I write to Visa, if it is good time to write, the machine/device makes respond.) The only problem is as some friend posted, "race problem".  And he gives one easiest way to fix it.

When I update my code, I will post it here.

Thank you.

 

0 Kudos
Message 10 of 10
(3,250 Views)