我已經將我的原始問題轉移到了底部,因爲它不再完全解決問題。需要'串口'需要錯誤的寶石
我無法找到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/文檔)
任何想法是發現發現?謝謝。
這適用於我,如果你運行寶石列表,它列出了什麼版本的串行端口? – 2011-02-09 19:48:11