小编Ram*_*lez的帖子

serial.serialutil.SerialException:[Errno 16] 无法打开端口:[Errno 16] 设备或​​资源繁忙:'/dev/ttyACM0'

我正在尝试使用 Pyserial python 库将 Arduino Uno 的串行输出打印到我的屏幕上。

这是我的 Arduino 代码。它只是生成随机数并将其打印到串行监视器:

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

}

void loop() {
    long rand = random(10);
    Serial.print(rand);
}
Run Code Online (Sandbox Code Playgroud)

我的 python 代码只是应该将序列中的值打印到命令行上,代码如下:

#!/usr/bin/python

import serial

ser = serial.Serial("/dev/ttyACM0",9600)
while True:
    thing = ser.readline()
    print(thing)
Run Code Online (Sandbox Code Playgroud)

当 Arduino 将随机数打印到串行监视器时,我运行 python 脚本并收到错误:

Traceback (most recent call last):
  File "/home/archimedes/anaconda3/lib/python3.6/site-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
OSError: [Errno 16] Device or resource busy: '/dev/ttyACM0'

During handling of the above exception, another exception occurred: …
Run Code Online (Sandbox Code Playgroud)

python linux arduino pyserial python-3.x

2
推荐指数
1
解决办法
2万
查看次数

JavaScript:检查两个字母是否是字母表中的后续字母

如何比较 JavaScript 中的 2 个字母以检查它们是否是字母表中的后续字母。基本上,这两个字母在字母表中必须相邻。

例如,比较:

  • a将会btrue
  • a将会cfalse

对于我的程序,我收到一个输入数组,例如,["a","b","e"]我想循环遍历该数组并将每一项与其前面的一项进行比较,下面是我的代码:

function fearNotLetter(str) {
  str = str.split("");
  console.log(str);
  for(let i=1; i<str.length; i++){
    console.log(str[i]>str[i-1]);
    if(str[i] > str[i-1]){
      console.log("good order");
    } else {
      console.log("missing");
    }
  }
  return str;
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我不确定在内部要做什么,if statement我只是尝试比较项目以检查索引处的项目是否i大于索引处的项目i-1

javascript regex

2
推荐指数
1
解决办法
847
查看次数

标签 统计

arduino ×1

javascript ×1

linux ×1

pyserial ×1

python ×1

python-3.x ×1

regex ×1