【问题标题】:JRuby require error on .so fileJRuby 要求 .so 文件出错
【发布时间】:2010-12-17 21:30:25
【问题描述】:

我正在为必须在 JRuby 上运行的应用程序开发一项功能。出于习惯,我在“原生”Ruby 上进行开发。当我尝试在 JRuby 中运行此类中的任何方法时,我收到如下错误消息:

MissingSourceFile:没有要加载的文件 -- 串行端口

我认为问题在于需要'serialport.so'。有没有办法在 JRuby 中完成这项工作?还有另一种需要 .so 文件的方法吗?还是可以与 JRuby 一起提供 SerialPort 类的 gem?我尝试安装 ruby​​-serialport gem,但似乎安装不正确(Windows nmake 问题)。

这是我的类文件的样子:

require 'serialport.so'
class AlphaDisplay

  #STATES
  SOLID = "b"
  ROTATE = "a"
  BLINK = "c"
  #COLORS
  RED = "1"
  GREEN = "2"
  YELLOW = "3"
  ORANGE = "7"

  def self.message(address = 00, text = "ICS", color = AlphaDisplay::GREEN, state = AlphaDisplay::SOLID)
    address = address.to_s
    if address.length == 1
      address = "0#{address}"
    end
    string = 1.chr + 90.chr + address + 2.chr + 65.chr + 65.chr + 27.chr + 26.chr + state + 28.chr + color + text + 4.chr
    return string
  end
  def self.test(address = 00, text = "ICS", color = AlphaDisplay::GREEN, state = AlphaDisplay::SOLID)
    sp = SerialPort.new(0, 9600, 8, 1, SerialPort::NONE)
    sp.write(message(address,text,color,state))
    sp.close
  end   
end

def SerialPort::new(port, *params)
  sp = create(port)
  begin
    sp.set_modem_params(*params)
  rescue
    sp.close
    raise
  end
  return sp
end

def SerialPort::open(port, *params)
  sp = create(port)
  begin
    sp.set_modem_params(*params)
    if (block_given?)
      yield sp
      sp.close
      return nil
    end
  rescue
    sp.close
    raise
  end
  return sp
end

【问题讨论】:

  • 不能使用Java原生方法访问串口?

标签: ruby serial-port jruby


【解决方案1】:

据我所知,JRuby 不提供任何本机仿真层,仅提供 Java 中的 Ruby 解释器。问题是“.so”文件是 UNIX 特定的,如果没有某种模拟/翻译,就无法在 Windows 上运行。

如果要使用 JRuby,最好避免使用需要原生扩展的 Ruby 库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 2016-11-18
    • 2015-03-14
    相关资源
    最近更新 更多