Jump to content

Ruby Problem


Recommended Posts

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?

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...