public void Initialise(string ZWaveConfigPath, string ZWaveSerialPort, int ZWavePollInterval, string LogPath) { logPath = LogPath; // Configuration details ZWaveConfigPath = BuildConfigPath(ZWaveConfigPath); System.IO.FileInfo logDirectory = new System.IO.FileInfo(ZWaveConfigPath); // Create the Options Log("Building ZWOptions with " + ZWaveConfigPath); m_options = new ZWOptions(); m_options.Create(ZWaveConfigPath, @"", @""); // Lock the options m_options.Lock(); // Create the OpenZWave Manager m_manager = new ZWManager(); m_manager.Create(); // Add an event handler for all the Z-Wave notifications m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler); if (ZWavePollInterval > 0) { m_manager.SetPollInterval(ZWavePollInterval); } // Add a driver, this will start up the z-wave network m_manager.AddDriver(ZWaveSerialPort); }
public MainForm() { InitializeComponent(); if (Properties.Settings.Default.SpeechRecognitionEnabled) { try { engine.LoadGrammar(new DictationGrammar()); engine.SetInputToDefaultAudioDevice(); engine.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(engine_RecognizeCompleted); } catch (Exception ex) { MessageBox.Show("Unable to load Speech Recognition: " + ex.ToString()); } } if (Properties.Settings.Default.ZWaveEnabled) { m_options = new ZWOptions(); m_options.Create(@"C:\Users\Kevin\Documents\Visual Studio 2010\Projects\OpenZWave\config\", @"", @""); m_options.Lock(); m_manager = new ZWManager(); m_manager.Create(); m_manager.AddDriver(@"\\.\COM4"); m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler); } }
public static bool SetValueSucceed(ZWManager manager, ZWValueId valueId, ZWValueType valueType, object value, string[] possibleValues) { switch (valueType) { case ZWValueType.Button: return(manager.PressButton(valueId)); case ZWValueType.Bool: return(manager.SetValue(valueId, (bool)value)); case ZWValueType.Byte: return(manager.SetValue(valueId, (byte)value)); case ZWValueType.Decimal: return(manager.SetValue(valueId, (float)value)); case ZWValueType.Int: return(manager.SetValue(valueId, (int)value)); case ZWValueType.Short: return(manager.SetValue(valueId, (short)value)); case ZWValueType.String: return(manager.SetValue(valueId, (string)value)); case ZWValueType.List: return(manager.SetValueListSelection(valueId, (string)value)); } return(false); }
public Node(byte id, uint homeId, ZWManager manager) { Id = id; HomeId = homeId; Manager = manager; Values = new NodeValues(); }
private static void ToggleSwitchValue(ZWManager manager, ZWValueID valueId) { bool switchValue; manager.GetValueAsBool(valueId, out switchValue); manager.SetValue(valueId, !switchValue); }
/// <summary> /// The notifications handler. /// </summary> /// <param name="notification">The notification.</param> public void NotificationHandler(ZWManager manager, NotificationReceivedEventArgs e) { // Handle the notification on a thread that can safely // modify the form controls without throwing an exception. m_notification = e.Notification; Invoke(new MethodInvoker(NotificationHandler)); m_notification = null; }
private static ZWManager CreateOpenZWaveManager() { SetOptions(); var manager = new ZWManager(); manager.Create(); return(manager); }
private static string GetValue(ZWValueID value, ZWManager manager) { switch (value.GetType()) { case ZWValueID.ValueType.Bool: bool boolValue; manager.GetValueAsBool(value, out boolValue); return(boolValue.ToString()); case ZWValueID.ValueType.Byte: byte byteValue; manager.GetValueAsByte(value, out byteValue); return(byteValue.ToString()); case ZWValueID.ValueType.Decimal: decimal decimalValue; manager.GetValueAsDecimal(value, out decimalValue); return(decimalValue.ToString()); case ZWValueID.ValueType.Int: int intValue; manager.GetValueAsInt(value, out intValue); return(intValue.ToString()); case ZWValueID.ValueType.List: string[] listValues; manager.GetValueListItems(value, out listValues); string listValue = ""; if (listValues != null) { foreach (string s in listValues) { listValue += s; listValue += "/"; } } return(listValue); case ZWValueID.ValueType.Schedule: return("Schedule"); case ZWValueID.ValueType.Short: short shortValue; manager.GetValueAsShort(value, out shortValue); return(shortValue.ToString()); case ZWValueID.ValueType.String: string stringValue; manager.GetValueAsString(value, out stringValue); return(stringValue); default: return(""); } }
public static void Destroy() { lock (_lock) { if (_instance != null) { _instance.Destroy(); _instance = null; } _destroyed = true; } }
public static object GetValue(ZWManager manager, ZWValueId valueId, ZWValueType valueType, string[] possibleValues) { switch (valueType) { case ZWValueType.Button: { return(string.Empty); } case ZWValueType.Bool: { manager.GetValueAsBool(valueId, out bool result); return(result); } case ZWValueType.Byte: { manager.GetValueAsByte(valueId, out byte result); return(result); } case ZWValueType.Decimal: { manager.GetValueAsFloat(valueId, out float result); return(result); } case ZWValueType.Int: { manager.GetValueAsInt(valueId, out int result); return(result); } case ZWValueType.Short: { manager.GetValueAsShort(valueId, out short result); return(result); } case ZWValueType.String: { manager.GetValueAsString(valueId, out string result); return(result); } case ZWValueType.List: { manager.GetValueListSelection(valueId, out string result); return(result); } } return(null); }
private static void DumpNodeValues(Node node, ZWManager manager) { foreach (var value in node.Values) { var valueLabel = manager.GetValueLabel(value); if (valueLabel.ToLowerInvariant().Equals("switch")) { Console.WriteLine("***** Value ID:({0}) label:({1}) index:({2}) type:({3})", value.GetId(), valueLabel, value.GetIndex(), value.GetType()); } } }
/// <summary> /// Handles Notifications. /// </summary> /// <param name="notification">The notification.</param> private static void NotificationHandler(ZWManager manager, NotificationReceivedEventArgs e) { var notification = e.Notification; switch (notification.Type) { case ZWNotificationType.ControllerCommand: { MyControllerStateChangedHandler((ZWControllerState)notification.Event); break; } } }
public static string GetValue(this ZWValueID v, ZWManager manager) { switch (v.GetType()) { case ZWValueID.ValueType.Bool: bool r1; manager.GetValueAsBool(v, out r1); return r1.ToString(); case ZWValueID.ValueType.Byte: byte r2; manager.GetValueAsByte(v, out r2); return r2.ToString(); case ZWValueID.ValueType.Decimal: decimal r3; manager.GetValueAsDecimal(v, out r3); return r3.ToString(); case ZWValueID.ValueType.Int: Int32 r4; manager.GetValueAsInt(v, out r4); return r4.ToString(); case ZWValueID.ValueType.List: string listValue; manager.GetValueListSelection(v, out listValue); string[] r5; manager.GetValueListItems(v, out r5); var r6 = ""; foreach (var s in r5) { r6 += s; r6 += ", "; } return listValue + " [Possible Values: " + r6.Substring(0, r6.LastIndexOf(",")) + "]"; case ZWValueID.ValueType.Schedule: return "Schedule"; case ZWValueID.ValueType.Short: short r7; manager.GetValueAsShort(v, out r7); return r7.ToString(); case ZWValueID.ValueType.String: string r8; manager.GetValueAsString(v, out r8); return r8; default: return ""; } }
public ZWManager GetManager() { lock (_lock) { if (_destroyed) { throw new InvalidOperationException("Factory cannot be used after it has been destroyed."); } if (_instance == null) { _instance = Create(); } } return(_instance); }
public OpenZWaveNetwork(HomeAutomationNetworkContext context, string serialPortName) : base(context) { _serialPortName = serialPortName; _devices = new List<OpenZWaveDevice>(); Devices = _devices; _notificationProcessor = new OpenZWaveNotificationProcessor(this); ConfigureOptions(); Manager = new ZWManager(); Manager.Create(); Manager.OnNotification += OnNotification; Connect(); }
private ZWManager Create() { SetOptions(); var manager = new ZWManager(); // create the OpenZWave Manager manager.Create(); manager.OnNotification += new ZWaveNotificationHandler(_nodeList, manager).HandleNotification; manager.OnNotification += CheckAllNodesQueried; manager.OnControllerStateChanged += state => Log.Debug(state); // once the driver is added it takes some time for the device to get ready manager.AddDriver(@"\\.\" + _settings.ControllerComPort); WaitForZWaveToInitialize(); return(manager); }
public OpenZWaveNetwork(HomeAutomationNetworkContext context, string serialPortName) : base(context) { _serialPortName = serialPortName; _devices = new List <OpenZWaveDevice>(); Devices = _devices; _notificationProcessor = new OpenZWaveNotificationProcessor(this); ConfigureOptions(); Manager = new ZWManager(); Manager.Create(); Manager.OnNotification += OnNotification; Connect(); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationWakeUpDlg"/> class. /// </summary> /// <param name="_manager">The _manager.</param> /// <param name="homeId">The home identifier.</param> /// <param name="nodeId">The node identifier.</param> public ConfigurationWakeUpDlg( ZWManager _manager, UInt32 homeId, Byte nodeId) { m_manager = _manager; m_homeId = homeId; m_nodeId = nodeId; InitializeComponent(); // Set the text according to whether the device is listening if( m_manager.IsNodeListeningDevice( homeId, nodeId ) ) { label1.Text = "Waiting for configurable parameter info from device..."; } else { label1.Text = "Waiting for configurable parameter info from device.\r\nPlease ensure device is awake..."; } }
public ConfigurationWakeUpDlg(ZWManager _manager, UInt32 homeId, Byte nodeId) { m_manager = _manager; m_homeId = homeId; m_nodeId = nodeId; InitializeComponent(); // Set the text according to whether the device is listening if (m_manager.IsNodeListeningDevice(homeId, nodeId)) { label1.Text = "Waiting for configurable parameter info from device..."; } else { label1.Text = "Waiting for configurable parameter info from device.\r\nPlease ensure device is awake..."; } }
public OpenZWaveDevice(Network network, ZWManager manager, byte id) : base(network) { Manager = manager; Id = id; Values = new OpenZWaveDeviceValueCollection(); Address = Id.ToString(); Event = new OpenZWaveEvent(this); _toggleSwitch = new OpenZWaveToggleSwitch(this); _dimmerSwitch = new OpenZWaveDimmerSwitch(this); _thermostat = new OpenZWaveThermostat(this); _binarySensor = new OpenZWaveBinarySensor(this); _powerSensor = new OpenZWavePowerSensor(this); _temperatureSensor = new OpenZWaveTemperatureSensor(this); _humiditySensor = new OpenZWaveHumiditySensor(this); _illuminanceSensor = new OpenZWaveIlluminanceSensor(this); }
public static void SetUp() { if (USE_ZWAVE) { // Create the Options m_options = new ZWOptions(); m_options.Create(zWaveConfigPath, @"", @""); m_options.Lock(); // Create the OpenZWave Manager m_manager = new ZWManager(); m_manager.Create(); m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler); m_manager.AddDriver(zWaveSerialPortName); // Wait for Z-wave. do { SleepForThreeSeconds(); }while (m_nodesReady == false); } }
/// <summary> /// The notifications handler. /// </summary> /// <param name="notification">The notification.</param> private void OnNodeNotification(ZWManager manager, NotificationReceivedEventArgs e) { if (Dispatcher == null) { NotificationHandler(e.Notification); } else { // Handle the notification on a thread that can safely // modify the controls without throwing an exception. #if NETFX_CORE var _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => #else Dispatcher.BeginInvoke(new Action(() => #endif { NotificationHandler(e.Notification); } #if !NETFX_CORE ) #endif ); } }
private void StopOpenzwave() { if (!isShuttingDown) { isShuttingDown = true; if (m_manager != null) { m_manager.OnNotification -= NotificationHandler; m_manager.RemoveDriver(@"\\.\COM" + OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Port").Value); m_manager.Destroy(); m_manager = null; } if (m_options != null) { m_options.Destroy(); m_options = null; } isShuttingDown = false; } }
private Task StartOpenzwaveAsync() { if (isShuttingDown) { Log.Info("ZWave driver cannot start because it is still shutting down"); return Task.FromResult(0); } try { string port = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Port").Value; if (port != "") { // Create the Options m_options = new ZWOptions(); m_options.Create(Common.ApiPath + @"\Plugins\ZWave\config\", Common.ApiPath + @"\Plugins\ZWave\", @""); // Lock the options m_options.Lock(); // Create the OpenZWave Manager m_manager = new ZWManager(); m_manager.Create(); m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler); // Add a driver m_manager.AddDriver(@"\\.\COM" + port); int poll = 60; if (OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Polling Interval").Value != string.Empty) poll = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Polling Interval").Value); { Log.Info("Setting poll interval: " + poll.ToString()); m_manager.SetPollInterval(poll * 1000, true); } Log.Info(Common.ApiPath + @"\Plugins\ZWave\Config"); Log.Info("Zwave plugin initialized"); } } catch (Exception e) { Log.Error("Error initalizing plugin", e); } return Task.FromResult(0); }
public ControllerCommandDlg(ZWManager _manager, UInt32 homeId, ZWControllerCommand _op, Byte nodeId) { m_manager = _manager; _homeid = homeId; _zwcontrollercommand = _op; _nodeid = nodeId; _controllercommanddlg = this; InitializeComponent(); switch (_zwcontrollercommand) { case ZWControllerCommand.AddDevice: { Text = " - Add Device"; label1.Text = "Press the program button on the Z-Wave device to add it to the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being added."; break; } case ZWControllerCommand.CreateNewPrimary: { Text = " - Create New Primary Controller"; label1.Text = "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller that is being made the primary."; break; } case ZWControllerCommand.ReceiveConfiguration: { Text = " - Receive Configuration"; label1.Text = "Transfering the network configuration\nfrom another controller.\n\nPlease bring the other controller within 2m of the PC controller and set it to send its network configuration."; break; } case ZWControllerCommand.RemoveDevice: { Text = " - Remove Device"; label1.Text = "Press the program button on the Z-Wave device to remove it from the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being removed."; break; } case ZWControllerCommand.TransferPrimaryRole: { Text = " - Transfer Primary Role"; label1.Text = "Transfering the primary role\nto another controller.\n\nPlease bring the new controller within 2m of the PC controller and set it to receive the network configuration."; break; } case ZWControllerCommand.HasNodeFailed: { ButtonCancel.Enabled = false; Text = " - Has Node Failed"; label1.Text = "Testing whether the node has failed.\nThis command cannot be cancelled."; break; } case ZWControllerCommand.RemoveFailedNode: { ButtonCancel.Enabled = false; Text = " - Remove Failed Node"; label1.Text = "Removing the failed node from the controller's list.\nThis command cannot be cancelled."; break; } case ZWControllerCommand.ReplaceFailedNode: { ButtonCancel.Enabled = false; Text = " - Replacing Failed Node"; label1.Text = "Testing the failed node.\nThis command cannot be cancelled."; break; } } m_manager.OnControllerStateChanged += m_controllerStateChangedHandler; if (!m_manager.BeginControllerCommand(_homeid, _zwcontrollercommand, false, _nodeid)) { m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler; } }
/// <summary> /// Initializes a new instance of the <see cref="ControllerCommandDlg"/> class. /// </summary> /// <param name="_mainDlg">The main form.</param> /// <param name="_manager">The manager.</param> /// <param name="homeId">The home identifier.</param> /// <param name="_op">The Controller Command.</param> /// <param name="nodeId">The node identifier.</param> public ControllerCommandDlg(MainForm _mainDlg, ZWManager _manager, UInt32 homeId, Func <bool> _op, Byte nodeId, ZWControllerCommand cmd) { m_mainDlg = _mainDlg; m_manager = _manager; m_homeId = homeId; m_op = cmd; m_nodeId = nodeId; m_dlg = this; InitializeComponent(); m_manager.NotificationReceived += new NotificationReceivedEventHandler(NotificationHandler); switch (m_op) { case ZWControllerCommand.RequestNodeNeighborUpdate: { this.Text = "Node Neighbor Update"; this.label1.Text = "Request that a node update its list of neighbors."; if (!m_manager.RequestNodeNeighborUpdate(m_homeId, m_nodeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.AddDevice: { this.Text = "Add Device"; this.label1.Text = "Press the program button on the Z-Wave device to add it to the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being added."; if (!m_manager.AddNode(m_homeId, m_mainDlg.SecurityEnabled)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.CreateNewPrimary: { this.Text = "Create New Primary Controller"; this.label1.Text = "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller that is being made the primary."; if (!m_manager.CreateNewPrimary(m_homeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.ReceiveConfiguration: { this.Text = "Receive Configuration"; this.label1.Text = "Transfering the network configuration\nfrom another controller.\n\nPlease bring the other controller within 2m of the PC controller and set it to send its network configuration."; if (!m_manager.ReceiveConfiguration(m_homeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.RemoveDevice: { this.Text = "Remove Device"; this.label1.Text = "Press the program button on the Z-Wave device to remove it from the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being removed."; if (!m_manager.RemoveNode(m_homeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.TransferPrimaryRole: { this.Text = "Transfer Primary Role"; this.label1.Text = "Transfering the primary role\nto another controller.\n\nPlease bring the new controller within 2m of the PC controller and set it to receive the network configuration."; if (!m_manager.TransferPrimaryRole(m_homeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.HasNodeFailed: { this.ButtonCancel.Enabled = false; this.Text = "Has Node Failed"; this.label1.Text = "Testing whether the node has failed.\nThis command cannot be cancelled."; if (!m_manager.HasNodeFailed(m_homeId, m_nodeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.RemoveFailedNode: { this.ButtonCancel.Enabled = false; this.Text = "Remove Failed Node"; this.label1.Text = "Removing the failed node from the controller's list.\nThis command cannot be cancelled."; if (!m_manager.RemoveFailedNode(m_homeId, m_nodeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.ReplaceFailedNode: { this.ButtonCancel.Enabled = false; this.Text = "Replacing Failed Node"; this.label1.Text = "Testing the failed node.\nThis command cannot be cancelled."; if (!m_manager.ReplaceFailedNode(m_homeId, m_nodeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.RefreshNodeInfo: { this.ButtonCancel.Enabled = false; this.Text = "Refreshing Node Info"; this.label1.Text = "Refreshing the node info\nThis command cannot be cancelled."; if (!m_manager.RefreshNodeInfo(m_homeId, m_nodeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.RequestNetworkUpdate: { this.ButtonCancel.Enabled = false; this.Text = "Requesting Network Update"; this.label1.Text = "Requesting the Network Update."; if (!m_manager.RequestNetworkUpdate(m_homeId, m_nodeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } default: { m_manager.NotificationReceived -= NotificationHandler; break; } } }
public void Initialize() { State = ZWaveManagerState.Initializing; var hasAnyControllers = LoadControllers(); SetOptions(); _manager = ZWManager.Instance; _manager.NotificationReceived += (s, e) => { var homeId = e.Notification.HomeId; var path = _manager.GetControllerPath(homeId); var controller = _controllers.FirstOrDefault(x => x.Path.Equals(path)); var nodeId = e.Notification.NodeId; var node = _nodes.FirstOrDefault(x => x.Id.Equals(nodeId) && x.HomeId.Equals(homeId)); var valueId = e.Notification.ValueId; var notificationType = e.Notification.Type; switch (notificationType) { case ZWNotificationType.ControllerCommand: { ControllerStateHandle((ZWControllerState)e.Notification.Event); } break; case ZWNotificationType.DriverRemoved: { _nodes.RemoveAll(x => x.HomeId.Equals(homeId)); _callbacksPool.Dequeue(true, nameof(RemoveController)); } break; case ZWNotificationType.DriverFailed: { controller.Failed = true; if (_controllers.All(x => x.Failed)) { State = ZWaveManagerState.Initialized; ManagerInitializedCallbacksPool.ExecuteAll(this); } _callbacksPool.Dequeue(false, nameof(AddController), nameof(RemoveController)); } break; case ZWNotificationType.DriverReady: { controller.Failed = false; controller.HomeID = homeId; _callbacksPool.Dequeue( true, nameof(AddController)); } break; case ZWNotificationType.AwakeNodesQueried: case ZWNotificationType.AllNodesQueriedSomeDead: case ZWNotificationType.AllNodesQueried: { _nodes.Where(x => !x.Initialized).All(x => x.Failed = true); _manager.WriteConfig(homeId); State = ZWaveManagerState.Initialized; ManagerInitializedCallbacksPool.ExecuteAll(this); } break; case ZWNotificationType.NodeAdded: case ZWNotificationType.NodeNew: { node = new Node(nodeId, homeId, ZWManager.Instance); _nodes.Add(node); node.Controller = controller; _manager.RequestNodeDynamic(node.HomeId, node.Id); _manager.RequestAllConfigParams(node.HomeId, node.Id); _callbacksPool.Dequeue(true, nameof(AddNewDevice), nameof(AddNewSecureDevice)); } break; case ZWNotificationType.EssentialNodeQueriesComplete: case ZWNotificationType.NodeQueriesComplete: { node.Initialized = true; } break; case ZWNotificationType.NodeProtocolInfo: case ZWNotificationType.NodeNaming: { node.Refresh(); node.Failed = false; } break; case ZWNotificationType.NodeRemoved: { _nodes.Remove(node); _callbacksPool.Dequeue(true, nameof(RemoveDevice)); } break; case ZWNotificationType.ValueAdded: { if (!node.Values.Any(x => x.Id == valueId.Id)) //crutch { var nodeValue = new NodeValue(valueId, node); if (valueId.Genre == ZWValueGenre.Config && valueId.Index < 256) { node.RequestConfigParam((byte)valueId.Index); //crutch } node.Values.Add(nodeValue); nodeValue.Refresh(); NodeValueChanged?.Invoke(this, new EventsArgs <NodeValue>(nodeValue)); } } break; case ZWNotificationType.ValueRefreshed: { var nodeValue = node.Values.FirstOrDefault(x => x.Id.Equals(valueId)); nodeValue.Refresh(); NodeValueChanged?.Invoke(this, new EventsArgs <NodeValue>(nodeValue)); } break; case ZWNotificationType.ValueRemoved: { if (node != null) { var nodeValue = node.Values.FirstOrDefault(x => x.Id.Equals(valueId.Id)); node.Values.Remove(nodeValue); } } break; case ZWNotificationType.ValueChanged: { var nodeValue = node.Values.FirstOrDefault(x => x.Id.Equals(valueId.Id)); nodeValue.CurrentGroupIdx = e.Notification.GroupIndex; nodeValue.InternalSet(Helper.GetValue(_manager, valueId, nodeValue.ZWValueType, nodeValue.PossibleValues)); NodeValueChanged?.Invoke(this, new EventsArgs <NodeValue>(nodeValue)); } break; } }; _manager.Initialize(); foreach (var controller in _controllers) { var ctrl = controller; _callbacksPool.ExecuteBool( () => _manager.AddDriver(ctrl.Path, ctrl.IsHID ? ZWControllerInterface.Hid : ZWControllerInterface.Serial), (result) => { if (!result) { ctrl.Failed = true; if (_controllers.All(x => x.Failed) && State != ZWaveManagerState.Initialized) { State = ZWaveManagerState.Initialized; ManagerInitializedCallbacksPool.ExecuteAll(this); } } else { ctrl.Failed = false; } }, 60, "ControllerLoading" + controller.Path); _manager.TestNetwork(controller.HomeID, 1); } if ((!_controllers.Any() || _controllers.All(x => x.Failed)) && State != ZWaveManagerState.Initialized) { State = ZWaveManagerState.Initialized; ManagerInitializedCallbacksPool.ExecuteAll(this); } }
public ControllerCommandDlg(MainForm _mainDlg, ZWManager _manager, UInt32 homeId, ZWControllerCommand _op, Byte nodeId) { m_mainDlg = _mainDlg; m_manager = _manager; m_homeId = homeId; m_op = _op; m_nodeId = nodeId; m_dlg = this; InitializeComponent(); switch (m_op) { case ZWControllerCommand.RequestNodeNeighborUpdate: { this.Text = "Node Neighbor Update"; this.label1.Text = "Request that a node update its list of neighbors."; break; } case ZWControllerCommand.AddController: { this.Text = "Add Controller"; this.label1.Text = "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller being added."; break; } case ZWControllerCommand.AddDevice: { this.Text = "Add Device"; this.label1.Text = "Press the program button on the Z-Wave device to add it to the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being added."; break; } case ZWControllerCommand.CreateNewPrimary: { this.Text = "Create New Primary Controller"; this.label1.Text = "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller that is being made the primary."; break; } case ZWControllerCommand.ReceiveConfiguration: { this.Text = "Receive Configuration"; this.label1.Text = "Transfering the network configuration\nfrom another controller.\n\nPlease bring the other controller within 2m of the PC controller and set it to send its network configuration."; break; } case ZWControllerCommand.RemoveController: { this.Text = "RemoveController"; this.label1.Text = "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller being added."; break; } case ZWControllerCommand.RemoveDevice: { this.Text = "Remove Device"; this.label1.Text = "Press the program button on the Z-Wave device to remove it from the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being removed."; break; } case ZWControllerCommand.TransferPrimaryRole: { this.Text = "Transfer Primary Role"; this.label1.Text = "Transfering the primary role\nto another controller.\n\nPlease bring the new controller within 2m of the PC controller and set it to receive the network configuration."; break; } case ZWControllerCommand.HasNodeFailed: { this.ButtonCancel.Enabled = false; this.Text = "Has Node Failed"; this.label1.Text = "Testing whether the node has failed.\nThis command cannot be cancelled."; break; } case ZWControllerCommand.RemoveFailedNode: { this.ButtonCancel.Enabled = false; this.Text = "Remove Failed Node"; this.label1.Text = "Removing the failed node from the controller's list.\nThis command cannot be cancelled."; break; } case ZWControllerCommand.ReplaceFailedNode: { this.ButtonCancel.Enabled = false; this.Text = "Replacing Failed Node"; this.label1.Text = "Testing the failed node.\nThis command cannot be cancelled."; break; } } m_manager.OnControllerStateChanged += m_controllerStateChangedHandler; if (!m_manager.BeginControllerCommand(m_homeId, m_op, false, m_nodeId)) { m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler; } }
public override void RunInterface(string pluginName) { pName = pluginName; int poll = 60; if (OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Polling Interval").Value != string.Empty) poll = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Polling Interval").Value); string port = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Port").Value; logging.AddToLog("Port: " + port, true); try { if (port != "") { // Create the Options m_options = new ZWOptions(); m_options.Create(Common.ApiPath + @"\Plugins\ZWave\config\", Common.ApiPath + @"\Plugins\ZWave\", @""); // Add any app specific options here... m_options.AddOptionBool("ConsoleOutput", false); m_options.AddOptionBool("IntervalBetweenPolls", true); m_options.AddOptionInt("PollInterval", poll); // Lock the options m_options.Lock(); // Create the OpenZWave Manager m_manager = new ZWManager(); m_manager.Create(); m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler); // Add a driver m_manager.AddDriver(@"\\.\COM" + port); //logging.AddToLog("Setting poll interval: " + poll.ToString(), true); //m_manager.SetPollInterval(poll); logging.AddToLog(Common.ApiPath + @"\Plugins\ZWave\Config", true); logging.AddToLog("Zwave plugin initialized", true); } } catch (Exception ex) { logging.AddToLog("Error initalizing plugin: " + ex.Message, true); } }
static void Main(string[] args) { Console.WriteLine("Begin"); _mre = new ManualResetEvent(false); OpenZWaveDotNet.ZWManager manager = new OpenZWaveDotNet.ZWManager(); var options = new ZWOptions(); options.Create(@"..\..\config", @"", @""); // Add any app specific options here... options.AddOptionInt("SaveLogLevel", (int)ZWLogLevel.None); // ordinarily, just write "Detail" level messages to the log options.AddOptionInt("QueueLogLevel", (int)ZWLogLevel.None); // save recent messages with "Debug" level messages to be dumped if an error occurs options.AddOptionInt("DumpTriggerLevel", (int)ZWLogLevel.None); // only "dump" Debug to the log emessages when an error-level message is logged // Lock the options options.Lock(); _manager = new ZWManager(); _manager.Create(); _manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler); var driverPort = @"\\.\COM3"; _manager.AddDriver(driverPort); _mre.WaitOne(); var sensor = PrintValuesForDevice("Routing Binary Sensor"); _manager.SetNodeProductName(sensor.HomeId, sensor.Id, "Garage Door Sensor"); foreach (var n in _nodeList) { Console.WriteLine("======================================"); Console.WriteLine("Label: " + n.Label); Console.WriteLine("location: " + n.Location); Console.WriteLine("Manufacturer: " + n.ManufacturerName); var name = _manager.GetNodeName(sensor.HomeId, n.Id); n.Name = name; Console.WriteLine("Name: " + n.Name); Console.WriteLine("Product: " + n.Product); Console.WriteLine("Node Id: " + n.Id); Console.WriteLine("======================================"); } // var node = _nodeList.FirstOrDefault(x => x.Product == "45609 On/Off Relay Switch"); // _manager.SetPollInterval(1000, true); var node = PrintValuesForDevice("Binary Power Switch"); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("Getting value of basement light switch:"); ZWValueID v = node.ValueIds.First(x => _manager.GetValueLabel(x) == "Switch"); bool ret; bool b; ret = _manager.GetValueAsBool(v, out b); Console.WriteLine("SWITCH: Got bool value of " + b + ", success: " + ret); var v2 = sensor.ValueIds.First(x => _manager.GetValueLabel(x) == "Sensor"); ret = _manager.GetValueAsBool(v2, out b); Console.WriteLine("SENSOR: Got bool value of " + b + ", success: " + ret); //int i; //ret = _manager.GetValueAsInt(v, out i); //Console.WriteLine("got in value of " + i + ", success: " + ret); //string str; //ret = _manager.GetValueAsString(v, out str); //Console.WriteLine("got string value of " + str + ", success: " + ret); // ret = _manager.SetValue(v, true); //Console.WriteLine("Set bool value to false, success: " + ret); Console.WriteLine("Press enter..."); Console.ReadLine(); }
public void Shutdown() { m_manager.RemoveDriver(@"\\.\COM" + osae.GetObjectPropertyValue(pName, "Port").Value); m_manager = null; }
/// <summary> /// Initializes a new instance of the <see cref="MainForm"/> class. /// </summary> public MainForm() { // Initialize the form InitializeComponent(); // Add the columns to the grid view // Data Grid NodeGridView.AutoGenerateColumns = false; NodeGridView.AllowUserToResizeColumns = true; NodeGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; DataGridViewTextBoxColumn column; //DataGridViewCheckBoxColumn check; // Id column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "ID"; column.Name = "Node"; column.ReadOnly = true; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "The Z-Wave node ID of the device.\nThis value is not editable."; NodeGridView.Columns.Add(column); // Location column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Location"; column.Name = "Location"; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "The user-defined location of the Z-Wave device."; NodeGridView.Columns.Add(column); // Name column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Name"; column.Name = "Name"; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "The user-defined name for the Z-Wave device."; NodeGridView.Columns.Add(column); // Device Type column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Label"; column.Name = "Type"; column.ReadOnly = true; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "The Z-Wave device type.\nThis value is not editable."; NodeGridView.Columns.Add(column); // Manufacturer column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Manufacturer"; column.Name = "Manufacturer"; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "The manufacturer of the Z-Wave device."; NodeGridView.Columns.Add(column); // Product column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Product"; column.Name = "Product"; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; column.ToolTipText = "The product name of the Z-Wave device."; NodeGridView.Columns.Add(column); /* // Poll Interval * column = new DataGridViewTextBoxColumn(); * column.DataPropertyName = "PollInterval"; * column.Name = "Poll Interval"; * column.ReadOnly = false; * column.Frozen = false; * column.Resizable = DataGridViewTriState.True; * column.SortMode = DataGridViewColumnSortMode.NotSortable; * column.ToolTipText = "Polling interval in seconds, or zero for no polling.\nNewer devices should not need to be polled for\nyour PC to know their current state.\nFor those that do requre polling, the interval should\nbe as long as possible to reduce network traffic."; * NodeGridView.Columns.Add(column); */ /* // Schema * column = new DataGridViewTextBoxColumn(); * column.DataPropertyName = "Schema"; * column.Name = "Schema"; * column.ReadOnly = true; * column.Frozen = false; * column.Resizable = DataGridViewTriState.True; * column.SortMode = DataGridViewColumnSortMode.NotSortable; * column.ToolTipText = "The xPL message schema family that will be used\nif the 'Use zwave.basic' option is not checked.\nThe schema is chosen automatically according to\nthe Z-Wave device type, and cannot be changed."; * NodeGridView.Columns.Add(column); * * // ZWaveBasic * //check = new DataGridViewCheckBoxColumn(); * //check.DataPropertyName = "ZWaveBasic"; * //check.Name = "Use zwave.basic"; * //check.Frozen = false; * //check.Resizable = DataGridViewTriState.True; * //check.SortMode = DataGridViewColumnSortMode.NotSortable; * //check.ToolTipText = "If the box is checked, the device will send and respond to\nnative zwave.basic messages rather than those of the\ngeneric schema family listed under the Schema column."; * //NodeGridView.Columns.Add(check); */ // Level column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Level"; column.Name = "Level"; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "Current level of the device"; NodeGridView.Columns.Add(column); // On-Off button DataGridViewButtonColumn buttonColumn = new DataGridViewButtonColumn(); buttonColumn.DataPropertyName = "ButtonText"; buttonColumn.Name = "Power"; buttonColumn.Frozen = false; buttonColumn.Resizable = DataGridViewTriState.True; buttonColumn.SortMode = DataGridViewColumnSortMode.NotSortable; buttonColumn.ToolTipText = "Click a button to turn a light on or off"; NodeGridView.Columns.Add(buttonColumn); BindingSource bs = new BindingSource(); bs.DataSource = m_nodeList; NodeGridView.DataSource = bs; // Create the Options m_options = new ZWOptions(); m_options.Create(@"C:\code\open-zwave\config", @"", @""); // Add any app specific options here... m_options.AddOptionInt("SaveLogLevel", (int)ZWLogLevel.Detail); // ordinarily, just write "Detail" level messages to the log m_options.AddOptionInt("QueueLogLevel", (int)ZWLogLevel.Debug); // save recent messages with "Debug" level messages to be dumped if an error occurs m_options.AddOptionInt("DumpTriggerLevel", (int)ZWLogLevel.Error); // only "dump" Debug to the log emessages when an error-level message is logged // Lock the options m_options.Lock(); // Create the OpenZWave Manager m_manager = new ZWManager(); m_manager.Create(); m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler); // Add a driver m_driverPort = @"\\.\COM5"; m_manager.AddDriver(m_driverPort); // m_manager.AddDriver(@"HID Controller", ZWControllerInterface.Hid); }
//private readonly ZWValueID _valueId; //private readonly ZWManager _manager; public ZWaveValueProperties(ZWValueID valueId, ZWManager manager) { //_manager = manager; //_valueId = valueId; _commandClassId = (Enums.CommandClass) valueId.GetCommandClassId(); _genre = valueId.GetGenre(); _value = valueId.GetValue(manager); _help = manager.GetValueHelp(valueId); _pollingEnabled = manager.IsValuePolled(valueId); _homeId = valueId.GetHomeId(); _id = valueId.GetId(); _index = valueId.GetIndex(); _instance = valueId.GetInstance(); _label = manager.GetValueLabel(valueId); _nodeId = valueId.GetNodeId(); _type = valueId.GetType(); _units = manager.GetValueUnits(valueId); }
public ZWaveNotificationHandler(IZWaveNodeList nodes, ZWManager manager) { _nodes = nodes; _manager = manager; }
public ZWaveManager() { _manager = new ZWManager(); _manager.OnNotification = new ManagedNotificationsHandler(notification => NotificationHandler(notification, this)); }
public void RunInterface(string pluginName) { pName = pluginName; int poll = 60; if (osae.GetObjectPropertyValue(pName, "Polling Interval").Value != "") poll = Int32.Parse(osae.GetObjectPropertyValue(pName, "Polling Interval").Value); string port = osae.GetObjectPropertyValue(pName, "Port").Value; osae.AddToLog("Port: " + port, true); try { if (port != "") { // Create the Options m_options = new ZWOptions(); m_options.Create(osae.APIpath + @"\AddIns\ZWave\config\", osae.APIpath + @"\AddIns\ZWave\", @""); // Add any app specific options here... m_options.AddOptionBool("ConsoleOutput", false); m_options.AddOptionBool("IntervalBetweenPolls", true); m_options.AddOptionInt("PollInterval", 50); // Lock the options m_options.Lock(); // Create the OpenZWave Manager m_manager = new ZWManager(); m_manager.Create(); m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler); // Add a driver m_manager.AddDriver(@"\\.\COM" + port); //osae.AddToLog("Setting poll interval: " + poll.ToString(), true); //m_manager.SetPollInterval(poll); osae.AddToLog(osae.APIpath + @"\AddIns\ZWave\Config", true); osae.AddToLog("Zwave plugin initialized", true); } osae.ObjectTypeUpdate("ZWAVE DIMMER", "ZWAVE DIMMER", "ZWave Dimmer", pName, "MULTILEVEL SWITCH", 0, 0, 0, 1); osae.ObjectTypeUpdate("ZWAVE BINARY SWITCH", "ZWAVE BINARY SWITCH", "ZWave Binary Switch", pName, "BINARY SWITCH", 0, 0, 0, 1); osae.ObjectTypeUpdate("ZWAVE THERMOSTAT", "ZWAVE THERMOSTAT", "ZWave Thermostat", pName, "THERMOSTAT", 0, 0, 0, 1); osae.ObjectTypeUpdate("ZWAVE REMOTE", "ZWAVE REMOTE", "ZWave Remote", pName, "ZWAVE REMOTE", 0, 0, 0, 1); osae.ObjectTypeUpdate("ZWAVE MULTISENSOR", "ZWAVE MULTISENSOR", "ZWave MultiSensor", pName, "ZWAVE MULTISENSOR", 0, 0, 0, 1); osae.ObjectTypeUpdate("ZWAVE HOME ENERGY METER", "ZWAVE HOME ENERGY METER", "ZWave Home Energy Meter", pName, "ZWAVE HOME ENERGY METER", 0, 0, 0, 1); osae.ObjectTypeUpdate("ZWAVE SMART ENERGY SWITCH", "ZWAVE SMART ENERGY SWITCH", "ZWave Smart Energy Switch", pName, "ZWAVE SMART ENERGY SWITCH", 0, 0, 0, 1); #region Screen Init //osae.ObjectPropertySet("Screen - ZWave Manager - ZWave - ADD CONTROLLER", "Object Name", pName); //osae.ObjectPropertySet("Screen - ZWave Manager - ZWave - ADD DEVICE", "Object Name", pName); //osae.ObjectPropertySet("Screen - ZWave Manager - ZWave - REMOVE CONTROLLER", "Object Name", pName); //osae.ObjectPropertySet("Screen - ZWave Manager - ZWave - REMOVE DEVICE", "Object Name", pName); #endregion } catch (Exception ex) { osae.AddToLog("Error initalizing plugin: " + ex.Message, true); } }
public ControllerCommandDlg(ZWManager _manager, uint _homeId, ZWControllerCommand _op, byte? nodeId, bool securityEnabled) { m_manager = _manager; homeId = _homeId; m_op = _op; m_nodeId = nodeId != null ? nodeId.Value : (byte)0; m_dlg = this; InitializeComponent(); m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler); switch (m_op) { case ZWControllerCommand.RequestNodeNeighborUpdate: { this.Text = "Обновление списка соседних узлов"; this.label1.Text = "Узел обновляет список соседних узлов"; if (!m_manager.RequestNodeNeighborUpdate(homeId, m_nodeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.AddDevice: { this.Text = "Добавить устройство в ZWave сеть"; this.label1.Text = "Нажмите программную кнопку на Z-Wave устройстве для добавления его в сеть.\nДля безопасности, контроллер должен быть рядом с устройством ZWave (не более 2 метров)."; if (!m_manager.AddNode(homeId, securityEnabled)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.CreateNewPrimary: { this.Text = "Создать новый основной контроллер"; this.label1.Text = "Введите новый контроллер в режим передачи данных.\nТекущий контроллер должен быть рядом с целевым контроллером (не более 2 метров)."; if (!m_manager.CreateNewPrimary(homeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.ReceiveConfiguration: { this.Text = "Передача конфигурации"; this.label1.Text = "Передача сетевой конфигурации от другого устройства.\nПоместите другой контроллер в пределах 2 метров от текущего контроллера."; if (!m_manager.ReceiveConfiguration(homeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.RemoveDevice: { this.Text = "Удалит устройство из сети"; this.label1.Text = "Нажмите программную кнопку на устройстве ZWave для удаления его из сети.\nПо причинам безопасности, контроллер должен быть в радиусе 2-х метров от устройства."; if (!m_manager.RemoveNode(homeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.TransferPrimaryRole: { this.Text = "Передача роли основного контроллера другому контроллеру"; this.label1.Text = "Передача роли основного контроллера другому контроллеру.\n\nПо причинам безопасности, контроллер должен быть в радиусе 2-х метров от устройства."; if (!m_manager.TransferPrimaryRole(homeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.HasNodeFailed: { this.ButtonCancel.Enabled = false; this.Text = "Проверка узла на неисправность"; this.label1.Text = "Проверка узла.\nЭта команда не может быть отменена"; if (!m_manager.HasNodeFailed(homeId, m_nodeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.RemoveFailedNode: { this.ButtonCancel.Enabled = false; this.Text = "Удаление неисправного узла"; this.label1.Text = "Удаление неисправного узла.\nКоманда не может быть отменена."; if (!m_manager.RemoveFailedNode(homeId, m_nodeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.ReplaceFailedNode: { this.ButtonCancel.Enabled = false; this.Text = "Замена неисправного узла"; this.label1.Text = "Тестирование неисправного узла.\nКоманда не может быть отменена."; if (!m_manager.ReplaceFailedNode(homeId, m_nodeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } case ZWControllerCommand.RequestNetworkUpdate: { this.ButtonCancel.Enabled = false; this.Text = "Запрос обновления сети устройств"; this.label1.Text = "Запрос обновления сети устройств."; if (!m_manager.RequestNetworkUpdate(homeId, m_nodeId)) { MyControllerStateChangedHandler(ZWControllerState.Failed); } break; } default: { m_manager.OnNotification -= NotificationHandler; break; } } }
public MainForm() { // Initialize the form InitializeComponent(); // Add the columns to the grid view // Data Grid NodeGridView.AutoGenerateColumns = false; NodeGridView.AllowUserToResizeColumns = true; NodeGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; DataGridViewTextBoxColumn column; //DataGridViewCheckBoxColumn check; // Id column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "ID"; column.Name = "Node"; column.ReadOnly = true; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "The Z-Wave node ID of the device.\nThis value is not editable."; NodeGridView.Columns.Add(column); // Location column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Location"; column.Name = "Location"; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "The user-defined location of the Z-Wave device."; NodeGridView.Columns.Add(column); // Name column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Name"; column.Name = "Name"; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "The user-defined name for the Z-Wave device."; NodeGridView.Columns.Add(column); // Device Type column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Label"; column.Name = "Type"; column.ReadOnly = true; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "The Z-Wave device type.\nThis value is not editable."; NodeGridView.Columns.Add(column); // Manufacturer column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Manufacturer"; column.Name = "Manufacturer"; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "The manufacturer of the Z-Wave device."; NodeGridView.Columns.Add(column); // Product column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Product"; column.Name = "Product"; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; column.ToolTipText = "The product name of the Z-Wave device."; NodeGridView.Columns.Add(column); /* // Poll Interval column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "PollInterval"; column.Name = "Poll Interval"; column.ReadOnly = false; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "Polling interval in seconds, or zero for no polling.\nNewer devices should not need to be polled for\nyour PC to know their current state.\nFor those that do requre polling, the interval should\nbe as long as possible to reduce network traffic."; NodeGridView.Columns.Add(column); */ /* // Schema column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Schema"; column.Name = "Schema"; column.ReadOnly = true; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "The xPL message schema family that will be used\nif the 'Use zwave.basic' option is not checked.\nThe schema is chosen automatically according to\nthe Z-Wave device type, and cannot be changed."; NodeGridView.Columns.Add(column); // ZWaveBasic //check = new DataGridViewCheckBoxColumn(); //check.DataPropertyName = "ZWaveBasic"; //check.Name = "Use zwave.basic"; //check.Frozen = false; //check.Resizable = DataGridViewTriState.True; //check.SortMode = DataGridViewColumnSortMode.NotSortable; //check.ToolTipText = "If the box is checked, the device will send and respond to\nnative zwave.basic messages rather than those of the\ngeneric schema family listed under the Schema column."; //NodeGridView.Columns.Add(check); */ // Level column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Level"; column.Name = "Level"; column.Frozen = false; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.NotSortable; column.ToolTipText = "Current level of the device"; NodeGridView.Columns.Add(column); // On-Off button DataGridViewButtonColumn buttonColumn = new DataGridViewButtonColumn(); buttonColumn.DataPropertyName = "ButtonText"; buttonColumn.Name = "Power"; buttonColumn.Frozen = false; buttonColumn.Resizable = DataGridViewTriState.True; buttonColumn.SortMode = DataGridViewColumnSortMode.NotSortable; buttonColumn.ToolTipText = "Click a button to turn a light on or off"; NodeGridView.Columns.Add(buttonColumn); BindingSource bs = new BindingSource(); bs.DataSource = m_nodeList; NodeGridView.DataSource = bs; // Create the Options m_options = new ZWOptions(); m_options.Create(@"..\..\..\..\..\..\..\config\", @"", @""); // Add any app specific options here... m_options.AddOptionInt("SaveLogLevel", (int)ZWLogLevel.Detail); // ordinarily, just write "Detail" level messages to the log m_options.AddOptionInt("QueueLogLevel", (int)ZWLogLevel.Debug); // save recent messages with "Debug" level messages to be dumped if an error occurs m_options.AddOptionInt("DumpTriggerLevel", (int)ZWLogLevel.Error); // only "dump" Debug to the log emessages when an error-level message is logged // Lock the options m_options.Lock(); // Create the OpenZWave Manager m_manager = new ZWManager(); m_manager.Create(); m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler); // Add a driver m_driverPort = @"\\.\COM4"; m_manager.AddDriver(m_driverPort); // m_manager.AddDriver(@"HID Controller", ZWControllerInterface.Hid); }
public ZWaveValue(ZWValueID valueId, ZWManager manager) { _valueId = valueId; _properties = new ZWaveValueProperties(_valueId, manager); }
protected override bool StartPlugin() { try { WriteToLog(Urgency.INFO, this.Friendly_Name + " plugin started."); // Environment.CurrentDirectory returns wrong directory in Service env. so we have to make a trick string directoryName = System.IO.Path.GetDirectoryName(new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); // Create the Options m_options = new ZWOptions(); m_options.Create(directoryName + @"\config\", directoryName + @"\", @""); m_options.Lock(); m_manager = new ZWManager(); m_manager.Create(); m_manager.OnNotification += NotificationHandler; bool useHID = false; //bool.TryParse(GetSettingValue("HID"), out useHID); if (!useHID) { string comPort = GetSettingValue("COMPORT"); if (comPort != "0") { m_manager.AddDriver(@"\\.\COM" + comPort); } } else { //m_manager.AddHidDriver(); } int pollint = 0; int.TryParse(GetSettingValue("POLLINT"), out pollint); if (pollint != 0) { m_manager.SetPollInterval(pollint); } } catch (Exception e) { WriteToLog(Urgency.ERROR, e.Message); return false; } return true; }
protected override bool StopPlugin() { WriteToLog(Urgency.INFO, Friendly_Name + " plugin stopped."); m_manager.OnNotification -= NotificationHandler; string comPort = GetSettingValue("COMPORT"); m_manager.RemoveDriver(@"\\.\COM" + comPort); m_manager.Destroy(); m_options.Destroy(); m_options = null; m_manager = null; IsReady = false; return true; }
public override void Shutdown() { m_manager.RemoveDriver(@"\\.\COM" + OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Port").Value); m_manager = null; }
public ZWaveNetwork(IZWaveNodeList nodeList, IZWaveManagerFactory managerFactory) { _nodeList = nodeList; _manager = managerFactory.GetManager(); }
public static void SetUp() { if (USE_ZWAVE) { // Create the Options m_options = new ZWOptions(); m_options.Create(zWaveConfigPath, @"", @""); m_options.Lock(); // Create the OpenZWave Manager m_manager = new ZWManager(); m_manager.Create(); m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler); m_manager.AddDriver(zWaveSerialPortName); // Wait for Z-wave. do { SleepForThreeSeconds(); } while (m_nodesReady == false); } }
private async Task StartOpenzwaveAsync() { if (CancellationToken.IsCancellationRequested) { await Log.ReportInfoFormatAsync(CancellationToken, "{0} driver cannot start because it is still shutting down", Name); return; } PropertyChanged += OpenZWaveAdapter_PropertyChanged; try { await Log.ReportInfoFormatAsync(CancellationToken, "OpenZwave driver starting on {0}", UseHidSetting ? "HID" : "COM" + ComportSetting); // Environment.CurrentDirectory returns wrong directory in Service environment so we have to make a trick var directoryName = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); // Create the Options MOptions = new ZWOptions(); MOptions.Create(directoryName + @"\config\", LogPath, @""); MOptions.Lock(); MManager = new ZWManager(); MManager.Create(); MManager.OnNotification += NotificationHandler; if (!UseHidSetting) { if (ComportSetting != "0") { MManager.AddDriver(@"\\.\COM" + ComportSetting); } } else { MManager.AddDriver("HID Controller", ZWControllerInterface.Hid); } if (PollingIntervalSetting != 0) { MManager.SetPollInterval(PollingIntervalSetting, true); } } catch (Exception e) { Log.ReportErrorFormatAsync(CancellationToken, "Error initializing Openzwave {0}", e.Message).Wait(); } }