需要'serialport'需要错误的宝石

时间:2011-02-09 19:20:17

标签: c ruby rubygems serial-port barcode-scanner

我将原来的问题移到了最底层,因为它不再完全解决这个问题。

我无法找到我能够要求的serialport.so:

$ rvmree@global
$ irb
> require 'serialport.so'
=> true

(gem list返回emtpy)

更新

require 'serialport'

在irb会话中执行时,即使卸载gem,两者都要求返回true。因此,似乎需要通过“require'serialport'”来获得另一个宝石。我已经在我的系统中搜索了这个宝石的任何其他版本而没有结果。

如何确保需要正确的宝石?

更新

[删除了宝石列表]

当我卸载rvm全局命名空间中的所有gem时,我仍然可以要求'serialport'并且变为true。

现在我的gem列表输出完全为空,并且要求'serialport'仍然从irb中返回true。

我正在使用rvm,我已经清空了全球宝石,以及我正在使用的gemset中的所有宝石。没有名称包含'serialport'的系统宝石,我搜索了包含在gem目录中的文件,如serialport.o,serialport.so,但没有找到任何内容。

我对可能响应要求'serialport'的行为感到茫然

require 'serialport.so'

也会返回true和

sudo find / -name 'serialport.so' -print

不会返回任何内容。

有什么想法吗?

原帖:

我正在使用serialport(1.0.4)gem。

文档位于http://rubydoc.info/gems/serialport/1.0.4/

这是我的implementation.rb:

require 'rubygems'
require 'serialport'
port_str = "/dev/cu.usbserial" # Serialport mount point
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = 0

sp = SerialPort.new(port_str, data_bits, stop_bits, baud_rate, parity)

while barcode = sp.gets do
  puts barcode
end

sp.close


运行ruby implementation.rb时,我得到:

implementation.rb:14:in `initialize': wrong number of arguments (5 for 2) (ArgumentError)
from implementation.rb:14:in `open'
from implementation.rb:14

这很奇怪,因为在任何地方似乎都没有初始化方法(也许ruby在内部将SerialPort :: new命名为initialize?)。

宝石的红宝石部分看起来像:

require 'serialport.so'

class SerialPort
   private_class_method(:create)

   # Creates a serial port object.
   #
   # <tt>port</tt> may be a port number
   # or the file name of a defice.
   # The number is portable; so 0 is mapped to "COM1" on Windows,
   # "/dev/ttyS0" on Linux, "/dev/cuaa0" on Mac OS X, etc.
   #
   # <tt>params</tt> can be used to configure the serial port.
   # See SerialPort#set_modem_params for details
   def SerialPort::new(port, *params)
      sp = create(port)
      begin
         sp.set_modem_params(*params) # Calls C extension
      rescue
         sp.close
         raise
      end
      return sp
   end
  # SerialPort::open removed as its the same thing as new() with a block
end

这一天工作了,我想不出任何会改变的事情。

我也遇到了与ruby-serialport gem(0.7.0)相同的错误,从快速浏览两个来源看起来完全相同。

示例实施位于http://www.sfc.wide.ad.jp/~mitsuya/4U/ruby-serialport-macosx.html

后一个gem(ruby-serialport)位于http://rubyforge.org/projects/ruby-serialport/(文档http://ruby-serialport.rubyforge.org/

有什么想法吗?感谢。

1 个答案:

答案 0 :(得分:0)

$LOAD_PATH内查看irb,我开始在搜索任何与串口相关的内容。

不久,我找到了~/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/i686-darwin10.6.0/serialport.bundle。删除后,我尝试了require 'serialport'并获得了预期的LoadError: no such file to load -- serialport,因为我之前已经卸载了serialport gem来调试此问题。

gem install serialport之后,我的代码会按预期再次运行。

如果我一直在想清楚,我会先做到这一点并避免头痛。我希望这可以帮助有类似问题的人更快地调试它。