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

Wrong number of arguments #13

Closed markf closed 14 years ago

markf commented 14 years ago

I'm having trouble (and appear to be the only one doing so) using serialport with ruby 1.8.6/1.8.7. I've tried on two installations - one Linux (2.6.26) the other OS X and I'm having the same behavior on both. For starters, I've built the binary in ext/native appropriately on both (and I know it works as I had some slight changes to the text of the tty ports). Then I see something like the following on both installations:

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'serialport'
=> true
irb(main):003:0> sp = SerialPort.new("/dev/ttyUSB1", 9600)
TypeError: can't convert String into Integer
    from (irb):3:in `initialize'
from (irb):3:in `new'
from (irb):3

Passing a string should work, I thought, but I can easily work around that - so far did it using the C piece

irb(main):004:0> sp = SerialPort.new(1, 4800, 8, 1, SerialPort::NONE)
ArgumentError: wrong number of arguments (5 for 2)
from (irb):4:in `initialize'
from (irb):4:in `new'
from (irb):4
from :0

This part is the issue. It isn't allowing me to send more than 2 arguments; that is, it doesn't seem to be allowing me to use the variable argument list *params. However, if I do 2 or less, I have success. Surely I'm doing something silly here, but from what I can tell, this is in line with all of the examples. The included miniterm.rb has the same issue.

irb(main):005:0> sp = SerialPort.new(1)
=> #<SerialPort:0x7f95cd51f648>
irb(main):006:0> sp = SerialPort.new(1,4800)
=> #<SerialPort:0x7f95cd50db50>

Surely I'm doing something wrong (consistently) as this is showing up wherever I install.

The issue exists with the serialport-1.0.1 and 1.0.2 gems as well as historical ruby-serialport gems.

markf commented 14 years ago

More information:

From my installed serialport.rb:

def SerialPort::new(port, *params)
   sp = create(port)
   begin
      sp.set_modem_params(*params)
   rescue
      sp.close
      raise
   end
   return sp
end

Looks right to me.

hparra commented 14 years ago

Does the same behavior occur with Serialport.open?

hparra commented 14 years ago

Are you building this through ruby gems? Version? Mac OS X version (10.6)? 64-bit?

markf commented 14 years ago

Same behavior exists with Serialport.open:

irb(main):003:0> sp = SerialPort.open("/dev/ttyUSB1", 4800, 8, 1)
ArgumentError: wrong number of arguments (4 for 2)
from (irb):3:in `initialize'
from (irb):3:in `open'
from (irb):3
from :0

Building through ruby gems on both platforms.

Mac OS X version is 10.6.3.

markf commented 14 years ago

Messing around a bit more with this today and explicitly directed Ruby to the location of serialport.rb (require '/path/serialport.rb'), and it worked as expected. Not sure exactly what it might be seeing with just require 'serialport' but obviously picking something else up. Either way, closing this issue.