PanicButton - c# Control Class

This article is based on the following two blogs:
http://awatts.co.uk/?tag=panic-button
http://project-megasnake.blogspot.com/2008/11/usb-panic-button.html

I created a c# class to control the PanicButton device.

If started, a BackgroundWorker waits for input from the USB device.
To allow the main application work independent from the device state, every state change or button press are reported as Events.

UsbDevice.cs (6.23 kb)

The code expects the original TenxHID.dll in your project.

 

The USB class can be used similar to this example:

public partial class Form1 : Form
{
    readonly UsbDevice usb = new UsbDevice();

    public Form1()
    {
        InitializeComponent();
        usb.ButtonPressed += ButtonPressed;
        // usb.DeviceConnected += DeviceConnected;
        // usb.DeviceDisconnected += DeviceDisconnected;
        // usb.ListeningEnded += ListeningEnded;
        // usb.ListeningStarted += ListeningStarted;
        // usb.ErrorReport += Error;
    }

    private void ButtonPressed(object source, EventArgs args)
    {
        SystemSounds.Beep.Play();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        usb.BeginListening();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        usb.EndListening();
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (usb.IsListening)
        {
            e.Cancel = true;
        }
    }
}
Kommentare sind geschlossen

Tags