white204 Posted June 30, 2017 at 01:14 PM Share Posted June 30, 2017 at 01:14 PM Hallo Gemeinde, ich habe ein merkwürdiges Problem. Dieses Script funktioniert: #!/usr/bin/env ruby require 'tinkerforge/ip_connection' require 'tinkerforge/bricklet_barometer' include Tinkerforge @host = '192.168.1.50' @port = 4223 @uid = '555' @ipcon = IPConnection.new @b = BrickletBarometer.new @uid, @ipcon @ipcon.connect(@host, @port) air_pressure = @b.get_air_pressure puts "Air Pressure: #{air_pressure/1000.0} hPa" Aber dieses #!/usr/bin/env ruby class TinkerClass require 'tinkerforge/ip_connection' require 'tinkerforge/bricklet_barometer' include Tinkerforge def initialize @host = '192.168.1.50' @port = 4223 @uid = '555' @ipcon = IPConnection.new @b = BrickletBarometer.new @uid, @ipcon @ipcon.connect(@host, @port) air_pressure = @b.get_air_pressure puts "Air Pressure: #{air_pressure/1000.0} hPa" end tinker = TinkerClass.new end wirft folgende Exception: /ip_connection.rb:734:in `create_packet_header': undefined method `pack' for #<Tinkerforge::IPConnection:0x305a1e0> (NoMethodError) Tinkerforge gem Version 2.1.13 Ruby Version 2.3.3 Windows 10 pro x64 Hat jemand eine Idee? Quote Link to comment Share on other sites More sharing options...
photron Posted June 30, 2017 at 02:30 PM Share Posted June 30, 2017 at 02:30 PM Der Unterschied ist, dass du require 'tinkerforge/ip_connection' require 'tinkerforge/bricklet_barometer' include Tinkerforge im zweiten Fall in der class hast. Wenn du es vor die class packst dann funktioniert es. Test mal bitte die angehängt ip_connection.rb Datei. Mit der sollte es auch in der class funktionieren.ip_connection.rb Quote Link to comment Share on other sites More sharing options...
white204 Posted June 30, 2017 at 03:31 PM Author Share Posted June 30, 2017 at 03:31 PM Super! Danke! Das habe ich die ganze Zeit übersehen :-) Es funktioniert jetzt wie gewollt. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.