取消
顯示結果 
搜尋替代 
您的意思是: 

Accelerate the communication Python-Labview

已解決!
前往解決方案

@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...

11 條訊息(共 18 條)
2,071 檢視

@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
12 條訊息(共 18 條)
2,066 檢視

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.

 

下載全部
0 積分
13 條訊息(共 18 條)
2,062 檢視

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 積分
14 條訊息(共 18 條)
2,046 檢視

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 積分
15 條訊息(共 18 條)
2,020 檢視

@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 積分
16 條訊息(共 18 條)
1,999 檢視

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 積分
17 條訊息(共 18 條)
1,948 檢視

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 積分
18 條訊息(共 18 條)
1,926 檢視