Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.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_Serial Port_Arduino_Pyserial - Fatal编程技术网

Python串行错误

Python串行错误,python,serial-port,arduino,pyserial,Python,Serial Port,Arduino,Pyserial,我试图让Python读取并连接到串行端口3上的Arduino Uno,以便在Python代码中使用COM3。我使用的是Python33,Arduino和PySerial2.7的最新版本。这是Arduino的代码: void setup() { Serial.begin(9600); // set the baud rate Serial.println("Ready"); // print "Ready" once } void loop() { char inByte = ' '; if(Se

我试图让Python读取并连接到串行端口3上的Arduino Uno,以便在Python代码中使用COM3。我使用的是Python33,Arduino和PySerial2.7的最新版本。这是Arduino的代码:

void setup() {
Serial.begin(9600); // set the baud rate
Serial.println("Ready"); // print "Ready" once
}
void loop() {
char inByte = ' ';
if(Serial.available()){ // only send data back if data has been sent
char inByte = Serial.read(); // read the incoming data
Serial.println(inByte); // send the data back in a new line so that it is not all one long line
}
delay(100); // delay for 1/10 of a second
}
这是python代码:

import serial
ser = serial.Serial("COM3", 9600)
然后我得到这个错误:

Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
ser = serial.Serial("COM3", 9600)
File "C:\Python33\lib\site-packages\serial\serialwin32.py", line 38, in __init__
SerialBase.__init__(self, *args, **kwargs)
File "C:\Python33\lib\site-packages\serial\serialutil.py", line 282, in __init__
self.open()
File "C:\Python33\lib\site-packages\serial\serialwin32.py", line 66, in open
raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM3': FileNotFoundError(2,   'The system cannot find the file specified.', None, 2)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ser=串行。串行(“COM3”,9600)
文件“C:\Python33\lib\site packages\serial\serialwin32.py”,第38行,在\uuu init中__
SerialBase.\uuuu init\uuuu(self,*args,**kwargs)
文件“C:\Python33\lib\site packages\serial\serialutil.py”,第282行,在\uuu init中__
self.open()
打开文件“C:\Python33\lib\site packages\serial\serialwin32.py”,第66行
引发SerialException(“无法打开端口%r:%r”%(self.portstr,ctypes.WinError()))
serial.serialutil.SerialException:无法打开端口“COM3”:FileNotFoundError(2,“系统找不到指定的文件”,无,2)
这可能是一个很容易解决的问题,我几乎到处都找过了,但似乎仍然找不到问题的答案

为什么要在Linux机器上使用“COM3”?这是一个Windows端口名。Linux/Unix端口名的格式为
/dev/ttyUSB0


但是,如图所示,您可能只需要直接使用端口号—它们从0开始,因此您可以执行
ser=serial.serial(29600)
如果您打开了arduino ide,那么python可能无法访问该端口。我也使用处理来解决这个问题。

我没有使用Linux机器,我使用的是Windows 8,当我输入
ser=serial时,serial(29600)
我的访问被拒绝@DanielRoseManading添加设备管理器显示的内容可能会有更多帮助