我正在尝试使用 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) 如何比较 JavaScript 中的 2 个字母以检查它们是否是字母表中的后续字母。基本上,这两个字母在字母表中必须相邻。
例如,比较:
a将会b是true a将会c是false对于我的程序,我收到一个输入数组,例如,["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。