Skip to content
Morten Nielsen edited this page Apr 5, 2017 · 9 revisions

Welcome to the openzwave-dotnet-uwp wiki!

For more full examples, check out the sample apps.

Getting Started

Initializing the OpenZWave Library

//Initialize
ZWMOptions.Instance.Initialize(); //Configure default options
ZWMOptions.Instance.Lock();       //Options must be locked before using
ZWManager.Instance.Initialize();  //Start up the manager

Opening a serial port

.NET

var availablePorts = System.IO.Ports.SerialPort.GetPortNames();
var serialPort = availablePorts.First().Id; //Adjust to pick the right port for your usb stick
ZWManager.Instance.AddDriver(serialPort); //Add the serial port (you can have multiple!)

UWP

In UWP apps you must first enable the Serial Port capability. To do this, you must add the following section to the Capabilities part of the Package.appxmanifest:

  <Capabilities>
    <DeviceCapability Name="serialcommunication">
      <Device Id="any">
        <Function Type="name:serialPort" />
      </Device>
    </DeviceCapability>
  </Capabilities>

Next is finding the serial port using the DeviceInformation APIs, and then add the driver

//Hook up the serial port
var serialPortSelector = Windows.Devices.SerialCommunication.SerialDevice.GetDeviceSelector();
var devices = await DeviceInformation.FindAllAsync(serialPortSelector);
var serialPort = devices.First().Id; //Adjust to pick the right port for your usb stick
ZWManager.Instance.AddDriver(serialPort); //Add the serial port (you can have multiple!)

Listening for devices

ZWManager.Instance.OnNotification += OnNodeNotification; //Start listening for node events

The rest is in the Notification handler. Every time a node is found, changed, removed etc. an event is reported here, including responses to commands you send. Nodes are identified by the HomeID (one per usb controller connected), and by the NodeID. You use these two values to uniquely identify a node on your network, and can then perform operations like changing properties via the ZWManager instance.

private void OnNodeNotification(ZWNotification notification)
{
    var homeID = notification.HomeId;
    var nodeId = notification.NodeId;
    var type = notification.Type;
}

Sending commands

TODO

Clone this wiki locally