提前谢谢你。在
我会尽量简短。在
我有一个Arduino+IDE,有一个串行端口,工作正常。
我下载了python3.7.2、PySerial和VPython。
全部安装完毕。在
通过我的MacBook终端安装了PySerial。sudo easy_install pyserial
Password: Searching for pyserial
Best match: pyserial 3.4
Adding pyserial 3.4 to easy-install.pth file
我也通过终端安装了VPython。
^{pr2}$
当我在python3.7.2shell中输入help(“modules”)时,我得到了这个消息,它说PySerial是我拥有的一个模块。在Please wait a moment while I gather a list of all available modules... PySerial _thread getopt resource YoutubeARDTOPY
_threading_local getpass rlcompleter future _tkinter
我在Arduino上做了一个简单的代码,写入串口,验证并上传。它工作得很好。关闭了那个港口。在Python3.7.2上运行这段代码,希望这段代码能够获取发送到Arduinos串行端口的内容,并开始向Pythons串行端口发送。在import serial #Import Serial Library
arduinoSerialData = serial.Serial('/dev/cu.usbmodem14101', 9600)
while (1==1):
if (arduinoSerialData.inWaiting()>0):
myData = arduinoSerialData.readline()
print (myData.decode())
但我收到这样的错误信息
==========重新启动:/Users/donaldlair/Documents/YoutubeARDTOPY.py==========Traceback (most recent call last):
File "/Users/donaldlair/Documents/YoutubeARDTOPY.py", line 3, in
arduinoSerialData = serial.Serial('/dev/cu.usbmodem14101', 9600)
AttributeError: module 'serial' has no attribute 'Serial'
所以我查看了我的dir(serial)文件夹,结果出来了(我被告知要这么做,仍然不知道为什么,但这可能有助于弄清楚。在>>> dir(serial)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'abc', 'absolute_import', 'division', 'errors', 'generators', 'hooks', 'marshal', 'meta', 'model', 'nested_scopes', 'print_function', 'properties', 'request', 'test', 'unicode_literals', 'utilities', 'with_statement']
这些东西我都是第一次学的,所以如果你真的回答了我很感激的话,请你把它说得小一点,因为我有点文盲和初学者。在
谢谢你!在