[英]ruby on rails - cannot load such file — serialport
I am trying to use serial port by ruby on rails. 我正在尝试在Ruby上使用串行端口。 I use require 'serialport'. 我使用require'serialport'。 I installed gem serialport. 我安装了gem serialport。 I have got this error: 我有这个错误:
cannot load such file -- serialport
and this line is highlighted: 并且此行突出显示:
require 'serialport'
This is my script: 这是我的脚本:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
def hello
render text: "hello1, world!"
end
def cmd
require 'serialport'
@result = params[:parametr]
@dioda = params[:dioda]
#params for serial port
port_str = "/dev/ttyACM0" #may be different for you
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
case @result
when "1"
render html: "<strong>Led_on</strong>".html_safe
when "0"
render html: "<strong>Led_off</strong>".html_safe
when "sos"
render html: "<strong>Led_sos</strong>".html_safe
end
sleep 4
puts sp.readlines
end
end
如果您使用的是Rails,则需要将gem 'serialport'
放入Gemfile
,然后运行bundle install
。
Problem solved by changing configuration of passenger which used wrong ruby interpreter. 通过更改使用错误的红宝石解释器的乘客的配置解决了问题。 When I checked as a user in command line everything seemed to be ok, but using Apache/Passenger was an error, everything because different ruby interpreters used in these two situations. 当我在命令行中以用户身份检查时,一切似乎都还可以,但是使用Apache / Passenger会出错,这一切都是因为在这两种情况下使用了不同的ruby解释器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.