2011-02-09 55 views
0

我已經將我的原始問題轉移到了底部,因爲它不再完全解決問題。需要'串口'需要錯誤的寶石

我無法找到serialport.so這我能要求是這樣的:

$ [email protected] 
$ irb 
> require 'serialport.so' 
=> true 

(GEM列表返回emtpy)

更新:

require 'serialport' 

時在irb會話中執行,即使在卸載gem時也要求返回true。所以,通過「require'serialport'」似乎需要另一個gem。我已經在我的系統中搜索這個gem的任何其他版本而沒有結果。

我如何確保正確的寶石被要求?

更新:

[移除寶石列表]

當我卸載RVM全局命名空間中所有的寶石,我仍然可以要求 '的SerialPort',並得到正確的。

現在我的gem list輸出完全是空的,並且要求'serialport'仍然在irb內返回true。

我正在使用rvm,我清空了全局寶石,以及我正在使用的gemset中的所有寶石。沒有包含'serialport'的名稱的系統寶石,我搜索了包含在gem目錄中的文件,如serialport.o,serialport.so,但沒有找到任何東西。

我在一個損失什麼可能是應對要求 '的SerialPort'

require 'serialport.so' 

也返回true,

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

不返回任何東西。

任何想法?

原貼:

我使用一個串口(1.0.4)的寶石。

文檔在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 


當運行紅寶石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

後者寶石(紅寶石的serialport)在http://rubyforge.org/projects/ruby-serialport/(在http://ruby-serialport.rubyforge.org/文檔)

任何想法是發現發現?謝謝。

+0

這適用於我,如果你運行寶石列表,它列出了什麼版本的串行端口? – 2011-02-09 19:48:11

回答

0

irb中查看$LOAD_PATH,我開始通過它們搜索serialport相關的任何東西。

不久,我發現~/.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之後,我的代碼再次按預期工作。

如果我一直在思考,我會首先做到這一點,並避免頭痛。我希望這可以幫助任何有類似問題的人更快地進行調試。