蓝牙串行端口权限错误Errno :: EACCES [Ruby] [Serialport gem]

时间:2016-02-03 23:49:05

标签: ruby windows bluetooth serial-port

所以我试图通过HC-05蓝牙芯片向我的Arduino发送数据。我正在使用Ruby,到目前为止,我得到的错误如下所示。知道为什么吗?我正在使用Windows 10

我的arduino在COM3(USB)上,蓝牙芯片在COM37上

错误1

in `create': Permission denied - \\.\COM37 (Errno::EACCES)

如果我再试一次,我会收到此错误:

错误2

in `create': Invalid argument - \\.\COM37 (Errno::EINVAL)

Ruby代码

require 'serialport'
puts "What COM Port?"
comport = gets.chomp
comport = comport.to_i
comport = comport -1
sp =  SerialPort.new(comport,9600)
while 1
  puts "What message do you want to send?"
  write = gets.chomp
  if write == "exit"
    abort
  end
  sp.write write
end

Arduino代码

#include <Motor.h>
#include <SoftwareSerial.h>

Motor m8(8);
SoftwareSerial Bluetooth(12, 13); //12-TX 13-RX
// Declare a new 'char' or "character" that we will use to store the keyboard
// input sent to the bluetooth chip
char input;
boolean stop = false;
void setup() {
  Bluetooth.begin(9600);
  m8.attach();
}

void loop() {
  // If there is input available on the bluetooth chip (that is, we sent a    character
  // to the chip from the computer)...
  if (Bluetooth.available()) {
    // Read the first available character from the bluetooth chip and store it in the
    // 'input' variable
    input = Bluetooth.read();
    if (input == 'w') {
      stop != stop;
    }
    if (input == 'd') {
      m8.turn(100);
    }
    if (input == 'a') {
      m8.turn(-100);
    }
  }
  if (stop != true) {
    m8.stop();
  }
}

如果我尝试使用COM3和USB连接到我的arduino,我没有收到错误,它成功地将数据发送到arduino。

提前致谢!

0 个答案:

没有答案