hparra / ruby-serialport

ruby-serialport is a Ruby library that provides a class for using RS-232 serial ports
http://rubygems.org/gems/serialport
GNU General Public License v2.0
246 stars 58 forks source link

Does test run? #51

Open ghost opened 10 years ago

ghost commented 10 years ago

When I run the test, I get the following output:

miniterm.rb:11:in `initialize': wrong number of arguments (5 for 1..2) (ArgumentError)
    from miniterm.rb:11:in `new'
    from miniterm.rb:11:in `<main>'

Does that make sense? It is trying to run:

sp = SerialPort.new(ARGV[0].to_i, ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE)

but the new method is looking for 2 args, looking at api docs:

(SerialPort) new(port, *params)

jontio commented 5 years ago

I know 5 years old but it seems a simple question that should have been answered

I got the same thing.

try replacing miniterm.rb with...

require "../serialport.so"
require "rubygems"
require "serialport"

if ARGV.size < 4
  STDERR.print <<EOF
  Usage: ruby #{$0} num_port bps nbits stopb
EOF
  exit(1)
end

sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE)

open("/dev/tty", "r+") { |tty|
  tty.sync = true
  Thread.new {
    while true do
      tty.printf("%c", sp.getc)
    end
  }
  while (l = tty.gets) do
    sp.write(l.sub("\n", "\r"))
  end
}

sp.close

in lib/serialport type ruby ../../test/miniterm.rb "/dev/ttyACM0" 1200 8 1 or something. That worked for me.