如何使用 Python serial 修复此语法错误?
How do I fix this syntax error with Python serial?
这是错误:
AttributeError: module 'serial' has no attribute 'Serial'
我安装了 pySerial 并卸载了 serial
。
import serial
ser = serial.Serial('/dev/tty.usbmodem1d11', 9600)
ser.write('5')
那么问题是什么?我的 Python 是 3.6。我的 OS 是 Windows 10。
它对我有用。试一试:
#!/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)
也可以参考linkhttps://www.raspberrypi.org/forums/viewtopic.php?t=87465
这是错误:
AttributeError: module 'serial' has no attribute 'Serial'
我安装了 pySerial 并卸载了 serial
。
import serial
ser = serial.Serial('/dev/tty.usbmodem1d11', 9600)
ser.write('5')
那么问题是什么?我的 Python 是 3.6。我的 OS 是 Windows 10。
它对我有用。试一试:
#!/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)
也可以参考linkhttps://www.raspberrypi.org/forums/viewtopic.php?t=87465