Ruby, keine implizite Umwandlung von Symbol in Integer
gestern habe ich dich schon gefragt in "keine implizite Umwandlung von Symbol in Integer, Ruby ". Ich glaube, Sie benötigen weitere Informationen, um die Frage zu beantworten. Aus diesem Grund habe ich erneut gefragt. Ich habe mein System von Ruby 1.8.7 auf die neuere Version von Ruby 2.3.1p112 aktualisiert.
Wenn ich einen Test ausführen möchte, erhalte ich immer die Fehlermeldung:FATAL: keine implizite Umwandlung von Symbol in Integer
Hier ist der Code:
def element_switch_wago_do(step)
raise Rutema::ParserError, "Missing DO tag!" unless step.has_do?
raise Rutema::ParserError, "Missing DO value!" unless step.has_value?
raise Rutema::ParserError, "Used DO value '#{step.value}' not supported [0||1 valid]!" unless ((0 == step.value.to_i) || (step.value.to_i == 1))
step.txt="Switch Wago DIGITAL output-pin #{step.do} to #{step.value}"
ip = "{WAGO_IP}"
port = "{WAGO_PORT}"
step.cmd = Litu::RubyCommand.new("switch_wago_do") do |cmd, context|
Litu::subst_template!(ip, context)
Litu::subst_template!(port, context)
Litu::subst_template!(step.do, context)
ModBus::TCPClient.new(ip, port.to_i) do |cl|
cl.with_slave(1) do |slave|
slave.debug = false
slave.write_single_coil(step.do.to_i,step.value.to_i) end
end
end
end
class RubyCommand
include Patir::Command
attr_reader :cmd,:working_directory,:killProc
def initialize params,&block
@killProc=params[:killProc]
@name=params[:name]
@working_directory=params[:working_directory]||"."
if block_given?
@cmd=block
else
raise "You need to provide a block"
end
end
#Runs the associated block
def run context=nil
@run=true
begin
t1=Time.now
cmd = @cmd
pwd = @working_directory
p = Dir.pwd
puts "######: #{cmd}:"
Litu::subst_template!(pwd, context)
puts "before block in dir #{Dir.pwd}"
Dir.chdir(pwd) do
p = Dir.pwd
puts "in block in dir #{cmd}"
@cmd.call(self, context)
@status=:success
end
puts ":###### #{p}"
rescue StandardError
error << "\n#{$!.message}"
error << "\n#{$!.backtrace}" if $DEBUG
@status=:error
ensure
@exec_time=Time.now-t1
end
return @status
end
def kill!
@killProc.call if @killProc
end
def to_s
return @name
end
end
Wenn ich die 3 Zeilen in RubyCommand kommentiere, wird der Fehler nicht angezeigt.
#@killProc=params[:killProc]
#@name=params[:name]
#@working_directory=params[:working_directory]||"."
Das Problem ist etwas mit Array und Hash. Aber ich habe keine Ahnung, wie ich diesen Code zum Laufen bringen kann.