Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Python] [Ruby] Distance IR simple_example.py funktioniert, simple_example.rb nicht

Featured Replies

Geschrieben

Hallo Leute,

 

ich versuche gerade das Distance IR Beispiel auf einer OS X 10.8/Ruby 1.9.3 Umgebung zum Laufen zu bringen. Leider stosse ich dabei immer nur auf den folgenden Fehler:

 

simple_example.rb

~/.rvm/gems/ruby-1.9.3-p194/gems/tinkerforge-2.0.1/lib/tinkerforge/ip_connection.rb:155:in `unpack': '<' allowed only after types sSiIlLqQ (ArgumentError)

from ~/.rvm/gems/ruby-1.9.3-p194/gems/tinkerforge-2.0.1/lib/tinkerforge/ip_connection.rb:155:in `get_length_from_data'

from ~/.rvm/gems/ruby-1.9.3-p194/gems/tinkerforge-2.0.1/lib/tinkerforge/ip_connection.rb:733:in `receive_loop'

from ~/.rvm/gems/ruby-1.9.3-p194/gems/tinkerforge-2.0.1/lib/tinkerforge/ip_connection.rb:676:in `block in connect_unlocked'

 

Process finished with exit code 1

 

Ich habe dann nochmal das Python-Beispiel probiert und siehe da es funzt. Ich habe die korrekte UID mehrfach überprüft und bin sicher, dass sie bei beiden Beispielen korrekt gesetzt ist.

 

Muss ich meine Ruby-Umgebung noch irgendwie erweitern/einstellen, damit das geht?

 

Ich bin für jeden Tipp dankbar!

 

Viele Grüße,

 

Christian

 

P.S Warum gibt es eigentlich kein [Ruby] Prefix?

Geschrieben
  • Autor

Eigentlich hatte ich zuvor alles brav aktualisiert - siehe Attachments.

 

Und bei Firmware/Protokoll inkonsistenzen hätte ich erwartet, dass keines der Scripte funktioniert.

 

Danke für den Prefix & Grüße,

 

Christian

Bildschirmfoto_2013-01-27_um_10_33_18.png.390511d7af476306b63080f03c0321a1.png

Bildschirmfoto_2013-01-27_um_10_33_25.png.e496f4d33cff3fe74cb34d9802da119e.png

Geschrieben

Bei mir funktionierts:

 

olaf@pc:~/build20/ruby$ ls
example_simple.rb  tinkerforge
olaf@pc:~/build20/ruby$ cat example_simple.rb 
#!/usr/bin/env ruby
# -*- ruby encoding: utf-8 -*-

require 'tinkerforge/ip_connection'
require 'tinkerforge/bricklet_distance_ir'

include Tinkerforge

HOST = 'localhost'
PORT = 4223
UID = 'aUt' # Change to your UID

ipcon = IPConnection.new # Create IP connection
dir = BrickletDistanceIR.new UID, ipcon # Create device object

ipcon.connect HOST, PORT # Connect to brickd
# Don't use device before ipcon is connected

# Get current distance (unit is mm)
distance = dir.get_distance / 10.0
puts "Distance: #{distance} cm"

puts 'Press key to exit'
$stdin.gets
olaf@pc:~/build20/ruby$ ruby1.9.1 -I. example_simple.rb 
Distance: 10.5 cm
Press key to exit

olaf@pc:~/build20/ruby$

 

Allerdings gibt es in der ruby Doku in der Tat kein "C<" als Argument für unpack: http://www.ruby-doc.org/core-1.9.3/String.html#method-i-unpack

 

Da es bei 8bit Typen keinen unterschied zwischen little- und big-endian gibt, ist es dort auch nicht notwendig.

 

Kannst du mal einmal testweise alle "C<" in der ip_connection.rb durch "C" ersetzen?

Geschrieben
  • Autor

Das hat funktioniert :-)

 

Was bedeutet das jetzt für die Bindings? Warum hat es bei Dir funktioniert und bei mir nicht? Liegt es einfach nur an meinem OS X 10.8/Ruby 1.9.3 System? Oder kann das Problem auch anderweitig auftreten?

 

Vielen Dank aber für den Workaround!

 

Grüße,

 

Christian

Geschrieben

Alles klar, vielen Dank für die Hilfe! Ich hab Ruby Bindings 2.0.2 veröffentlicht, die sollten mit Ruby 1.9.3 "out of the box" funktionieren.

 

Warum hat es bei Dir funktioniert und bei mir nicht?

 

Naja, das "<" bei "C<" bei einem unpack Aufruf ist überflüssig. In Ruby 1.9.1 wird das "<" einfach ignoriert, Ruby 1.9.3 schmeißt eine Exception. Vermutlich hat keiner der Ruby Entwickler daran gedacht, dass diese Änderung existieren Code brechen kann.

Geschrieben
  • Autor

Was für ein prompter Service - Ich habe zu danken! :-)

 

Schönes Wochenende noch!

 

Grüße,

 

Christian

Join the conversation

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

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.