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.

Featured Replies

Geschrieben

Hallo zusammen,

 

bis vor kurzem war es noch problemlos möglich mit dem in der Dokumentation bereitsgestellten Beispiel ein Interrupt auf das IO-16 Bricklet in Python 3 zu legen. Aktuell habe ich jedoch das Problem, dass zwar grundsätzlich der Interrupt erkannt wird, allerdings erst, nachdem ich den input am Ende des Programms ausgelöst habe. Dadurch beendet sich das Programm natürlich auch und ich bin keinen Schritt weiter. Wird kein input eingegeben, dann wird auch kein Interrupt angezeigt oder ausgeführt. Hat jemand eine Idee woran das liegen kann? Die Firmware und Bindings habe ich jetzt auch schon ohne Erfolg aktualisiert.

 

Hier nochmal der angepasste Code aus der Dokumentation:

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-  

HOST = "localhost"
PORT = 4223
UID = "uid" # Change to your UID

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_io16 import IO16

# Callback function for interrupts
def cb_interrupt(port, interrupt_mask, value_mask):
    print('Interrupt on port: ' + port)
    print('Interrupt by: ' + str(bin(interrupt_mask)))
    print('Value: ' + str(bin(value_mask)))

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    io = IO16(UID, ipcon) # Create device object

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

    # Register callback for interrupts
    io.register_callback(io.CALLBACK_INTERRUPT, cb_interrupt)

    # Enable interrupt on pin 2 of port a
    io.set_port_interrupt('a', 0xFF)

    input('Press key to exit\n') # Use input() in Python 3
    ipcon.disconnect()

 

Wenn ich das input weglasse, dann wird das Programm natürlich direkt beendet und auch hier komme ich also keinen Schritt weiter.

Geschrieben

Ok, es scheint jetzt, als hätte ich eine Lösung gefunden. Ich habe das ganze bisher zwar nur beim Temperatr threshold Callback ausprobiert, hatte da aber das gleiche Problem. Es reicht eine unendliche Schleife zu erstellen. Es ist natürliche eher ein Workaround als eine schöne Lösung, funktioniert aber trotzdem.

 

import time

TinkerForge Code

while true:
    time.sleep (999) #Auch jeder andere große Wert möglich, beeinflusst Programm nicht

Geschrieben

Funktioniert hier ohne Probleme unter Linux mit Python 3.2.3.

 

Probier mal nach den prints stdout zu flushen:

 

#!/usr/bin/env python
import sys

HOST = "localhost"
PORT = 4223
UID = "aE7" # Change to your UID

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_io16 import IO16

# Callback function for interrupts
def cb_interrupt(port, interrupt_mask, value_mask):
    print('Interrupt on port: ' + port)
    print('Interrupt by: ' + str(bin(interrupt_mask)))
    print('Value: ' + str(bin(value_mask)))
    sys.stdout.flush()

if __name__ == "__main__":
    # [...]

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.