LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Accelerate the communication Python-Labview

Solved!
Go to solution

@ziedhosni wrote:

the output of the python node is not reliable when I put the Open Python node outside the loop.

But it works properly when I put the Open node outside the loop.

 


 
 
 
 
 
 
 

hmm.png

Joking aside, it looks like running the command "%reset -f" will reset the console.

 

https://stackoverflow.com/questions/26545051/is-there-a-way-to-delete-created-variables-functions-et...

Message 11 of 18
(1,660 Views)

@ziedhosni wrote:

I just realised that the output of the python node is not reliable when I put the Open Python node outside the loop.

But it works properly when I put the Open node outside the loop.

Is there any way to avoid including the Open Python node inside the loop and flash or clean the memory in order to let the python script runs properly.


Can you describe this a bit more? My understanding from reading this is that somehow you're storing state in the Python session. 

I'd also suggest perhaps sharing your code, especially (at least the signature of, and perhaps a high-level description of) the Python code you're calling.

The whole source probably isn't necessary (although if you want to share it, that's great) but it might allow some pointers (no pun intended) on what you're seeing.

 

As I mentioned previously, you should be able to open it outside, provided the For loop isn't parallel. I'm not sure it will behave nicely if you parallelize it, and the code inside the loop isn't thread-safe at all.


GCentral
Message 12 of 18
(1,655 Views)

I attach here my code in a simplified version.

I am not sure it is easy to run it as it requires installing special libraries like rdkit.

 

 I spotted the error when I noticed that the output from the python node doesn't make lots of sense, so I thought that there is something wrong in the python script.

Normally I run the code in a loop by feeding the python script with new input data. So I took a constant input and I run it in a loop and I expected that the python node will give the same value as nothing is changing.

Indeed, when the Python node is inside, the output is constant but the moment that I put the Open node outside the while loop, I get crazy numbers which seems that Python is not controlling properly the data communication.

 

Download All
0 Kudos
Message 13 of 18
(1,651 Views)

I forgot to ask where to include

%reset -f

 in the function script.

 

I also tried to add this function in my main function but it did not solve the problem.

def clear():
os.system('cls')

clear()

 

 

 

0 Kudos
Message 14 of 18
(1,635 Views)

I think I managed to find the mistake and it is not related to labview but to a line in python where I have to specify a random seed to avoid generating new staff in each iteration.

But I am still wondering why the output was constant when I put the Open session inside the loop?

0 Kudos
Message 15 of 18
(1,609 Views)

@ziedhosni wrote:

I think I managed to find the mistake and it is not related to labview but to a line in python where I have to specify a random seed to avoid generating new staff in each iteration.

But I am still wondering why the output was constant when I put the Open session inside the loop?


Because you got the same seed? In many programming languages true randomness is very hard and it's some semi- or quasirandom function that generates numbers.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 16 of 18
(1,588 Views)

Hi ziedhosni,

 

I face the almost similar issue as yours. 

I have placed the open session and close session outside the state machine.

Every state of the state machine will send a command to DUT with specified port and get some response.

However, i found that the session input to the python node is sometimes unreliable and gives me weird output. 

I saw you mentioned about specify the random seed in python code to avoid generating new staff in each iteration. I am not so familiar with Python. Can you please advise? Thank you.

example.PNG

Best regards,

XJ

0 Kudos
Message 17 of 18
(1,537 Views)

Hello,

I would say that the random seed affects only my application where I need to start from the same point each time I run the code.

I see that you are using the same way I did to open and close the python node. This saves the time compared to including them inside the loop.

The bug that I had in the code was related to my python script.

0 Kudos
Message 18 of 18
(1,515 Views)