ViziaRF _viziaRf = new ViziaRF(); _viziaRf.Open("COM1"); // Add a couple event handlers (there are many more). _viziaRf.NodeLevelChanged += new EventHandler<NodeLevelChangedEventArgs>(_viziaRf_NodeLevelChanged); _viziaRf.ReceivedSceneButtonPress += new EventHandler<SceneButtonPressEventArgs>(_viziaRf_ReceivedSceneButtonPress); // When your application first starts up you will normally want to discover all the nodes in the Z-Wave network. // This will populate the underlying _viziaRf.Nodes collection and would normally be done on a separate thread. _viziaRf.RequestAllNodes(); // Instead of polling the nodes can be saved or read from a file using: _viziaRf.SaveToFile(filePath); ViziaRF _viziaRf = LoadFromFile(filePath); // After discovering all the nodes in the Z-Wave network you will likely want to poll all the current // current levels of all nodes. This is only necessary when the software is first run since the nodes should // all be associated with the RZC0P and should notify the RZC0P when their level changes. If not the software // should then poll on a timer to keep the known node levels up to date. // This is a fairly simplistic example. In the real world you would want to catch transmission errors and possibly // add a delay between requests. // I added 3 passes because some finicky nodes may not reliably respond the 1st time. for (int pass = 0; pass < 3; pass++) { for (int i = 0; i < _viziaRf.Nodes.Count; i++) { ZWaveNode node = _viziaRf.Nodes.Values[i]; try { if (node.SupportsLevel && node.RawLevel == -1) _viziaRf.RequestNodeLevel(node.ID); System.Threading.Thread.Sleep(120); // Sleep a little to allow user commands to run. } catch (Exception ex) { // ... } } // Sleep between passes to allow slow responses to still come it. System.Threading.Thread.Sleep(3000); } // Get the known percent on level of node 3. int percentOn = _viziaRf.Nodes[3].PercentOn; // Turn off node 10. _viziaRf.TurnOffNodes(10); // Turn off node 10 and 15. _viziaRf.TurnOffNodes(10, 15); // Set node 15 to 50%. _viziaRf.SetLevelOfNodes(50, 15); // Turn on group 5. _viziaRf.TurnOnGroup(5); // Start Brightening nodes 10 and 15. _viziaRf.StartBrightening(10, 15); // Stop Brighteningand nodes that are currently brightening or dimming. _viziaRf.StopBrighteningOrDimming();
void _viziaRf_NodeLevelChanged(object sender, NodeLevelChangedEventArgs e) { // The event args have NodeID, PreviousPercentOn, and NewPercentOn properties. // But if you want the whole node... ZWaveNode node = _viziaRf.Nodes[e.NodeID]; }
_viziaRf.Close();