奇怪的Python问题

问题描述 投票:0回答:1

你好,我使用win 10,我试图使用serial.Serial将python连接到arduino,但它给出了属性错误。我认为这个错误已修复,但现在它说:

另外arduino doest连接我遇到了严重的麻烦,我很感谢谁帮助我

    arduino = serial.Serial('COM4', 9600) # Replace 'COM3' with the appropriate serial port on your computer               ^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "C:\Users\hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\serial\serialwin32.py", line 33, in __init__     super(Serial, self).__init__(*args, **kwargs)   File "C:\Users\hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\serial\serialutil.py", line 244, in __init__     self.open()   File "C:\Users\hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\serial\serialwin32.py", line 64, in open     raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError())) serial.serialutil.SerialException: could not open port 'COM4': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2) PS C:\Users\hp> 

我希望能快速回复。

谢谢你

代码:


import serial 

import time

arduino = serial.Serial('COM4', 9600)

time.sleep(2) 

arduino.write('Hello Arduino!') 
time.sleep(0.2)
arduino.close() 
python arduino serial-port pyserial arduino-ide
1个回答
0
投票

它说:

serial.serialutil.SerialException: could not open port 'COM4': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)

由于您没有确认 COM4 是否是系统上连接 Arduino 的正确端口:是吗?

如果是,请关闭端口打开的任何其他工具,例如Arduino IDE 的监控部分。

© www.soinside.com 2019 - 2024. All rights reserved.