require ‘serialport’ 需要错误的 gem;

发布于 2024-10-16 09:34:25 字数 3120 浏览 1 评论 0原文

我已将原来的问题移至底部,因为它不再与问题完全相关。

我无法找到我可以这样要求的serialport.so:(gem

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

列表返回emtpy)

更新:

require 'serialport'

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

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

更新:

[删除的 gems 列表]

当我卸载 rvm 全局命名空间中的所有 gems 时,我仍然可以 require 'serialport' 并得到 true。

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

我正在使用rvm,我已经清空了全局gem,以及我正在使用的gem集中的所有gem。没有名称包含“serialport”的系统gem,我搜索了将包含在gem目录中的文件,例如serialport.o、serialport.so,但没有找到任何内容。

我对可能响应 require 'serialport' 的内容感到不知所措,

require 'serialport.so'

也返回 true 并且

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

不返回任何内容。

有什么想法吗?

原始帖子:

我正在使用串行端口(1.0.4)gem。

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

这是我的实现.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 命名为初始化?)。

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

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/

有什么想法吗?谢谢。

I've moved my original question to the bottom as its no longer fully relavent to the problem.

I am unable to locate serialport.so which I am able to require like this:

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

(gem list returns emtpy)

Update:

require 'serialport'

when executed in an irb session, both requires return true even when I uninstall the gem. So, it appears another gem is being required via "require 'serialport'". I've searched my system for any other versions of this gem without result.

How can I ensure the correct gem is being required?

Update:

[Removed list of gems]

When I uninstall all gems in rvm global namespace, I can still require 'serialport' and get true.

Now my output of gem list is completely empty and require 'serialport' still returns true from within irb.

I'm using rvm, I've emptied the global gems, and all gems in the gemset I'm using. There are no system gems with a name containing 'serialport', I've searched for files which would be included in the gem directory such as serialport.o, serialport.so and didn't find anything.

I'm at a loss for what could possibly be responding to require 'serialport'

require 'serialport.so'

also returns true and

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

doesn't return anything.

Any ideas?

Original Post:

I'm using the serialport (1.0.4) gem.

Documentation is found at http://rubydoc.info/gems/serialport/1.0.4/

Here is my 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

When running ruby implementation.rb, I get:

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

This is weird as there doesn't appear to be an initialize method anywhere (maybe ruby is internally naming SerialPort::new as initialize?).

The ruby part of the gem looks like:

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

This was working the other day and I can't think of anything which would of changed.

I also get the same error with ruby-serialport gem (0.7.0) which appears to be exactly the same from a quick glance at both sources.

A sample implementation is found at http://www.sfc.wide.ad.jp/~mitsuya/4U/ruby-serialport-macosx.html

The latter gem (ruby-serialport) is found at http://rubyforge.org/projects/ruby-serialport/ (documentation at http://ruby-serialport.rubyforge.org/)

Any ideas? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个ˇ局外人 2024-10-23 09:34:25

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

不久,我找到了~/.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之后,我的代码再次按预期工作。

如果我考虑清楚的话,我会首先这样做并避免头痛。我希望这可以帮助有类似问题的人更快地调试它。

Looking at $LOAD_PATH from within irb, I started searching through them for anything serialport related.

Before long, I found ~/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/i686-darwin10.6.0/serialport.bundle. After deleting it, I tried require 'serialport' and got the expected LoadError: no such file to load -- serialport as I had previously uninstalled the serialport gem for debugging this problem.

After gem install serialport, my code works again as expected.

Had I been thinking clearly, I would have done this in the first place and avoided the headache. I hope this helps anyone with a similar problem to debug it more quickly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文