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.

[C#] Windows-Anwendung - IO16-Interrupt funktioniert nicht

Featured Replies

Geschrieben

Hallo Community,

 

ich habe vor mit dem IO16-Bricklet, 8 Relaisausgänge zu überwachen mit Hilfe eines Interrupt-Callbacks.

 

Hier mein Versuch:

 

using Tinkerforge;
namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Main2();
        }

        private static string HOST = "localhost";
        private static int PORT = 4223;
        private static string UID_IO16 = "b5W"; 
    

        static void InterruptCB(BrickletIO16 sender, char port, byte interruptMask, byte valueMask)
        {
            MessageBox.Show("ausgelöst");
        }


        static void Main2()
        {
     
            IPConnection ipcon = new IPConnection();
            BrickletIO16 io16 = new BrickletIO16(UID_IO16, ipcon);

            ipcon.Connect(HOST, PORT);

            io16.Interrupt += InterruptCB;
            io16.SetPortInterrupt('b', 129);
            //texttobox("Interrupt deklariert");

            ipcon.Disconnect();
        }
       
    }
}

 

Jedoch wird das Callback beim Anziehen eines Relais nicht ausgelöst..

Bin leider noch ein Anfänger, aber in einer Konsolenanwendung funktioniert dies ohne Probleme.  :(

 

Geschrieben
  • Autor

Ich habe mittlerweile herausgefunden, dass wenn ich die IP-Verbindung nicht beende (also die Zeile ipcon.Disconnect() herausnehme) es funktioniert.

Geschrieben

Ja du öffnest und beendest die Connection in einer Methode, damit ist die Verbindung schneller beendet als dass der Callback auslösen kann.

 

Du solltest die Verbindung als Member hinterlegen und nicht als Lokale Variable.

Dann kannst du wie jetzt oder per Button die Connection öffnen und den Callback hinterlegen. Mit einen anderen Button oder beim FormClosing Event der Form kannst du dann die Verbindung wieder sauber beenden.

 

 

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.