NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

The Python file include "import xxx", but can't be found the function when be called by TestStand

Solved!
Go to solution

I want to use the serial COM, define the function in the Python, as below:

import serial


def comsendlist(p=[]):
ser = serial.Serial("COM5", 115200, timeout=None)
ser.write(p)
ser.close()
return 0

l1 = [0x67,0x65]
comsendlist(l1)

but when use the TestStand call the Python,but can not find the founction "comsendlist",
problem.png
Is it because "import" is used in Python files?
How to solve this problem?
0 Kudos
Message 1 of 5
(1,814 Views)

I don't have this isses with teststand 2020 by your code.

0 Kudos
Message 2 of 5
(1,660 Views)

Thank you for your reply.

This is the complete code.

import serial

def comsendtuple(p=()):
    ser = serial.Serial("COM5", 115200, timeout=None)
    len1 = len(p)
    for i in p:
        ser.write(i)
    ser.close()    
    return 0

def comsendlist(p=[]):
    ser = serial.Serial("COM5", 115200, timeout=None)
    ser.write(p)
    ser.close()
    return 0

# 字符g
l1 = [0x67,0x65]
t1 = ([0x67],[0x32],[0x33])
print(type(l1))
print(type(t1))


comsendlist(l1)
comsendtuple(t1)

Please try again.

I always have this problem here. I thought it was caused by using the keyword "import XXX"

0 Kudos
Message 3 of 5
(1,654 Views)
Solution
Accepted by topic author Jmknode77

It seems only interpreter the module code in python even using  if __name__ == "__main__":

Teststand seems can only interpreter the clear code.

So, only keep module code like below pic. 

 

Ricky_76_0-1675406043410.png

 

Ricky_76_0-1675406133463.png

 

 

Thanks,

Ricky

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

After deleting useless statements and comments and reformatting the file, I found that functions can be detected in Teststand. Thank you very much.

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