-
Notifications
You must be signed in to change notification settings - Fork 27
Home
Welcome to the openzwave-dotnet-uwp wiki!
For more full examples, check out the sample apps.
//Initialize
ZWMOptions.Instance.Initialize(); //Configure default options
ZWMOptions.Instance.Lock(); //Options must be locked before using
ZWManager.Instance.Initialize(); //Start up the manager
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!)
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!)
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;
}
TODO