2

I'd like to connect to 3G modem using Ruby and the serialport gem.

My Ruby code:

require 'serialport'

class GSM
  sp = SerialPort.new('COM7', 9600)
  sp.read_timeout = 1500
  sp.write "AT\r\n"
  puts sp.read
end

I get this error after starting my script:

serialport.rb:25:in `create': Permission denied - \\.\COM7 (Errno::EACCES)

The IDE is run under administrator and the COM port is available from Putty and works fine. (I close Putty before running the script.)

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
alexey.chumagin
  • 630
  • 5
  • 16

1 Answers1

0

According to the docs http://rubydoc.info/gems/serialport/SerialPort#new-class_method the port must be an integer or a full path to the device file. In your case I believe you want to replace 'COM7' with 6

bridiver
  • 1,694
  • 12
  • 13