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 liebes Tinkerforge-Team.

 

Ich bin gerade wieder darüber gestolpert und möchte heute an dieser Stelle gern mal nachfragen. Würde es zukünftig nicht Sinn machen die Python-API dahingehend zu erweitern, dass man die verschiedenen Klassen auch im Rahmen des Kontext-Managers mit dem with-Statement ansprechen könnte?

 

from tinkerforge.ip_connection import IPConnection as _IPConnection
from tinkerforge.brick_master import BrickMaster as _BrickMaster

class IPConnection(_IPConnection):
    def __init__(self, host=None, port=4223):
        _IPConnection.__init__(self)
        if host is not None:
            self.connect(host, port)
        self.__host = host
        self.__port = port

    def __enter__(self):
        if not self.get_connection_state():
            self.connect(self.__host, self.__port)
        return self

    def __exit__(self, type, value, traceback):
        if self.get_connection_state():
            self.disconnect()


def test(ipcon):
    print(ipcon.get_connection_state())
    ipcon.set_auto_reconnect(True)
    ipcon.disconnect()
    print(ipcon.get_connection_state())


if __name__ == '__main__':
    HOST = '127.0.0.1'
    PORT = 4223

    with IPConnection(HOST, PORT) as ipcon:
        test(ipcon)

 

Viele Grüße

__LC__

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.