[英]How do I fix this syntax error with Python serial?
This is the error: 这是错误:
AttributeError: module 'serial' has no attribute 'Serial'
AttributeError:模块“ serial”没有属性“ Serial”
I installed pySerial and uninstalled serial
. 我安装了pySerial并卸载了
serial
。
import serial
ser = serial.Serial('/dev/tty.usbmodem1d11', 9600)
ser.write('5')
So what is the problem? 那是什么问题呢? My Python is 3.6.
我的Python是3.6。 My OS is Windows 10.
我的操作系统是Windows 10。
It's working for me. 它为我工作。 Try it:
试试吧:
#!/usr/bin/env python
import serial
from time import sleep
import math
port = '/dev/ttyAMA0'
baud = 9600
timeout = 5
ser = serial.Serial(port=port, baudrate=baud, timeout=timeout)
You can also refer to the link https://www.raspberrypi.org/forums/viewtopic.php?t=87465 您也可以参考链接https://www.raspberrypi.org/forums/viewtopic.php?t=87465
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.