Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';功能';对象没有属性';串行';在线程函数中使用时出错_Python_Multithreading_Serial Port - Fatal编程技术网

Python 属性错误:';功能';对象没有属性';串行';在线程函数中使用时出错

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

我正在尝试执行一个函数,该函数打开一个串行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/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