01-30-2023 10:51 PM
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",

Is it because "import" is used in Python files?
How to solve this problem?
Solved! Go to Solution.
02-02-2023 08:54 PM
I don't have this isses with teststand 2020 by your code.
02-02-2023 09:49 PM
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"
02-03-2023 12:34 AM - edited 02-03-2023 12:38 AM
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.
Thanks,
Ricky
02-03-2023 12:48 AM - edited 02-03-2023 12:55 AM
After deleting useless statements and comments and reformatting the file, I found that functions can be detected in Teststand. Thank you very much.