LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

python call in labview with DAQmx write

Hi, I am pretty new to calling python scripts in Labview. In this program I want to run my python function simultaneously with a while loop which has analog write function as shown in the picture. I am not able to do that even after using sequence functions. Is there any way to do that? currently the python call happens before the while loop runs. Thanks in advancepython.JPG

0 Kudos
Message 1 of 5
(1,305 Views)

Hi hishivam,

 


@hishivam wrote:

In this program I want to run my python function simultaneously with a while loop which has analog write function as shown in the picture. I am not able to do that even after using sequence functions. Is there any way to do that? currently the python call happens before the while loop runs.

Your VI will execute the while loop and your Python call in parallel (due to THINK DATAFLOW!).

This does not mean they will start at exectly the same time!

The loop will run until you press this Stop button, so I assume it will run at the same time as your python script is executing.

 

How do you know the Python script is executed first?

 

Btw. using the AutoCleanup tool would improve your block diagram! (Usually this is a bad sign for your code quality.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(1,269 Views)

Hi Gerd,

Thanks a lot for the answer. To provide some supplemental information, I want to run the while loop with the python call but the python call runs first as i saw from the  HIGHLIGHT mode (attached picture for reference). I am really stuck on how to work with this since the while loop executes much later on. Any suggestions are welcome. new_python.JPG

0 Kudos
Message 3 of 5
(1,249 Views)

In general, with highlight execution running

- The code runs much slower (always)

- Possibly runs in another order (than without highlight execution) since the dataflow has to be visualized.

 

LabVIEW is based on data flow and the two processes are already running in parallel even though it may not seem like it in highlight execution. 

 

 

0 Kudos
Message 4 of 5
(1,239 Views)

To add some extra context to the previous answer:

 

Humans are bad in processing things in parallel. So in highlight mode LabVIEW serializes the code execution (otherwise different icons would flash in parallel and completly distract and likely confuse the programmer who is trying to debug the code in this way). It's already distracting enough that in a somewhat more complex program LabVIEW highlighting springs randomly between different nodes on the diagram with each highlight execution step if they have no dataflow dependency between them. Adding to this visualization of parallel execution would not help at all to make it clearer.

 

This means that the execution order you see in highlight mode is DEFINITELY not how LabVIEW normally executes the code. Trying to deduce execution order of parallel independent nodes in LabVIEW in normal operation is an exercise in vain, since there is no guarantee that a certain order that you observe at some point will be the same one on a different computer, or with a recompile or in fact even without any code changes at all in a following execution. It's likely that the order will mostly stay the same as long as you don't change the code or other parameters such as the system it runs on, but there are simply no guarantees. For all practical purposes you have to consider this random.

 

If that is not desired (because you do want a specific execution order) you need to introduce some dependency in your diagram that clearly enforces a specific execution order through dataflow.

 

That all said, you want parallel execution but there is no real synchronization between the DAQmx task and your Python script. You do start the DAQmx task before the script can run. Loading and executing the script will take some time so you will likely have aquired a few samples from the DAQmx task before the Python script even starts executing. And you do not have any timing in the DAQmx loop so the sampling distance will be somewhat random.

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 5
(1,207 Views)