Python 属性错误:';功能';对象没有属性';串行';在线程函数中使用时出错
我正在尝试执行一个函数,该函数打开一个串行com并发送一条消息,然后等待重播。在线程函数之外,串行可以工作,但在其中,我遇到了以下错误:Python 属性错误:';功能';对象没有属性';串行';在线程函数中使用时出错,python,multithreading,serial-port,Python,Multithreading,Serial Port,我正在尝试执行一个函数,该函数打开一个串行com并发送一条消息,然后等待重播。在线程函数之外,串行可以工作,但在其中,我遇到了以下错误: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/l
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "MFC_Calv3_T.py", line 37, in serial
ser = serial.Serial('/dev/ttyACM0', baudrate = 9600) # setup com to serial
AttributeError: 'function' object has no attribute 'Serial'
以下是函数:
def serial():
ser = serial.Serial('/dev/ttyACM0', baudrate = 9600) # setup com to serial
ser.open()
ser.write(str.encode('$GET DQ DC\r'))
startTime = time.time()
data = ser.readline()
endTime = time.time()
ser.close
parts = data.split(",")
Writer(startTime, endTime, parts)
我的进口是:
import serial
from serial import Serial
import threading
from threading import Thread
我缺少什么?模块的名称与序列号相同
import serial
和功能
def serial():
所以函数
替换了模块
,这就产生了问题
将函数重命名为ie.
def get_serial()
,应该可以解决这个问题。不要将函数def serial()
感谢您指出这一点@furas