Skip to content

CartBlanche/IOKit-Sharp

Repository files navigation

IOKit-Sharp

Build an IOKit Binding for MacOS .NET Applications

Build Status

Build

Project Status:

Active.

IOKit-Sharp is a simple to use IOKit binding to (Surprise, surprise) IOKit. As the Xamarin.Mac developers think that IOKit is too niche, the primary aim is to, over time, provide an easy way for MacOS .NET developers to integrate IOKit support into their apps.

Nuget Status

Version Downloads

Nuget Download

📦 NuGet: dotnet add package IOKit.Sharp

Features

  • Simple Event System for each device type
  • Device filtering per device type (see SerialDevice example below, but should work for other devices too)
  • No external .NET dependencies

Screenshots

Screenshot 2021-11-22 at 18 40 56

Screenshot 2021-11-22 at 18 40 37

Usage

Quick start

It is easy to get IOKit-Sharp to notify you when a device is plugged in or removed from within your MacOS application.

        // Some initial set-up maybe inside you ViewController
        SerialDeviceManager serialDeviceManager = new SerialDeviceManager ();
        USBDeviceManager usbDeviceManager = new USBDeviceManager ();
.
.
.
        serialDeviceManager.OnDeviceAdded += (o, e) => {
            MainThread.BeginInvokeOnMainThread (() => {
                Console.WriteLine ($"Added Serial\n{e.Device}");
            });
        };

        serialDeviceManager.OnDeviceRemoved += (o, e) => {
            MainThread.BeginInvokeOnMainThread (() => {
                Console.WriteLine ($"Removed Serial\n{e.Device}");
            });
        };

        usbDeviceManager.OnDeviceAdded += (o, e) => {
            MainThread.BeginInvokeOnMainThread (() => {
                Console.WriteLine ($"Added USB\n{e.Device}");
            });
        };

        usbDeviceManager.OnDeviceRemoved += (o, e) => {
            MainThread.BeginInvokeOnMainThread (() => {
                Console.WriteLine ($"Added USB\n{e.Device}");
            });
        };

Then when you are ready to start listening to the events....

        var serial = Task.Run (() => {
            serialDeviceManager.Start ();
        });

        var usb = Task.Run (() => {
            usbDeviceManager.Start ();
        });

The library also supports device filtering, so you only get notified about devices you might be interested in. Just provide the appropriate Predicate via the Filter property.

        serialDeviceManager.Filter = x => ((SerialDevice)x.Value).VendorName == "Wilderness Labs";

Sponsoship

Sponsor Me

Want to help make this better?

Have a look at our Issues page and let us know what you would like to work on and contribute.

About

Build an IOKit Binding for .NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages