【问题标题】:WriteFile failed (PermissionError(13, 'the device does not recognize the command.', None, 22)), pyserial and ArduinoWriteFile failed (PermissionError(13, 'the device does not identify the command.', None, 22)), pyserial 和 Arduino
【发布时间】:2022-06-22 02:43:15
【问题描述】:

我正在使用 Python 和 Arduino 控制伺服器的位置。我在 python 中输入角度并将其发送到 Arduino,然后将伺服器移动到该特定角度。 Arduino代码:

#include <Servo.h>

Servo servo;

void setup() {
  servo.attach(9);
  Serial.begin(9600);
}

void loop() {
  while(Serial.available())
  {
    int pos = Serial.parseInt();
    if(pos >= 0)
    {
      servo.write(pos);  
    }
    else
    {
      continue;
    }
  }
}

python 代码:

import serial

port = serial.Serial('COM3',9600)

while(port.isOpen()):
    int_data = int(input("Enter servo position: "))
    str_data = str(int_data)
    byte_data = str_data.encode()

    port.write(byte_data)

30 秒内一切正常,我可以控制伺服,但突然出现错误:WriteFile failed (PermissionError(13, 'the device does not recognize the command ', None, 22))

【问题讨论】:

    标签: python arduino serial-port pyserial servo


    【解决方案1】:

    我遇到了同样的错误。对不起,我也不知道是什么原因造成的。 它的工作时间大约为 30 秒,有时甚至更短。 希望你能找到答案。

    我确实发现这可能是因为长串行电缆可能导致数据损坏,但就我而言,这并没有解决任何问题。

    【讨论】:

      猜你喜欢
      • 2022-12-27
      • 1970-01-01
      • 2022-12-27
      • 1970-01-01
      • 2016-08-23
      • 2022-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多