gpt4 book ai didi

c - require 'serialport' 需要错误的 gem

转载 作者:行者123 更新时间:2023-11-30 18:07:08 24 4
gpt4 key购买 nike

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

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

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

(gem 列表返回空)

更新:

require 'serialport'

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

如何确保需要正确的 gem?

更新:

[删除 gem 列表]

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

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

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

我不知道什么可能会响应需要“串行端口”

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 命名为初始化?)。

gem 的 ruby 部分看起来像:

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/)

有什么想法吗?谢谢。

最佳答案

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之后,我的代码再次按预期工作。

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

关于c - require 'serialport' 需要错误的 gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4949432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com