Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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
从Arduino读取数据时Python readline()出现问题_Python_Arduino_Window - Fatal编程技术网

从Arduino读取数据时Python readline()出现问题

从Arduino读取数据时Python readline()出现问题,python,arduino,window,Python,Arduino,Window,我正在尝试使用pyserial从Windows上的arduino读取数据 import serial device = 'COM3' baud = 9600 with serial.Serial(device,baud, timeout = 0) as serialPort: while True: line = serialPort.readline() line = line.decode("utf-8")

我正在尝试使用pyserial从Windows上的arduino读取数据

import serial

device      = 'COM3'
baud        = 9600

with serial.Serial(device,baud, timeout = 0) as serialPort:
    while True:
        line = serialPort.readline()
        line = line.decode("utf-8")
        if line:
            print(line)
arduino串行监视器输出的正是我所期望的

12,34,56
12,34,56
12,34,56
另一方面,python脚本正在输出:

1
2,34
,56



12,
34,5
6


1
2,34
,56



12,
34,5
6
我尝试过延迟Arduino的输出,我尝试过在Arduino代码中创建一个缓冲区,并且只在缓冲区已满时输出数据,我认为python可能有时间正确读取数据

我在这个网站上看到很多人和其他人编写了类似的代码,并建议它可以正常工作,但是我无法从python中获得一致的数据。有人知道我的问题吗?

试着这样做

蟒蛇

import serial

device = 'COM3'
baud = 9600

with serial.Serial(device, baud) as port:
    while True:
        print(port.readline().decode("utf-8"))
阿杜伊诺

void setup() {
  Serial.begin(9600);
}

void loop() {
  int x = 12;
  int y = 34;
  int z = 56;
  Serial.println(x + ',' + y + ',' + z);  
}

固定的非常感谢。python代码和arduino代码在此注释中协同工作,但是,我的原始python脚本与供参考的脚本一样工作。
void setup() {
  Serial.begin(9600);
}

void loop() {
  int x = 12;
  int y = 34;
  int z = 56;
  Serial.println(x + ',' + y + ',' + z);  
}