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 void AddController(Controller controller, Action <bool> callback) { lock (_nodes) { controller.Path = controller.Path.ToUpper(); if (!_controllers.Any(x => x.Equals(controller))) { _controllers.Add(controller); SaveControllersList(); if (_manager != null) { _callbacksPool.ExecuteBool(() => _manager.AddDriver(controller.Path, controller.IsHID ? ZWControllerInterface.Hid : ZWControllerInterface.Serial), (result) => { if (!result) { _controllers.Remove(controller); SaveControllersList(); } callback?.Invoke(result); }); } else { Initialize(); } } } }
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); }
private void eraseAllToolStripMenuItem_Click(object sender, EventArgs e) { if (DialogResult.Yes == MessageBox.Show("Are you sure you want to fully reset the controller? This will delete all network information and require re-including all nodes.", "Hard Reset", MessageBoxButtons.YesNo)) { m_manager.ResetController(m_homeId); m_manager.RemoveDriver(m_driverPort); m_manager.AddDriver(m_driverPort); } }
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 override async Task StartAsync(CancellationToken cancellationToken) { await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ContinueWith(_ => { }); if (string.IsNullOrEmpty(_comPortName)) { _messageQueue.Publish(new NotifyUserMessage("Add z-wave configuration (port) to config file.")); return; } var validComPorts = new HashSet <string>(SerialPort.GetPortNames(), StringComparer.Ordinal); if (!validComPorts.Contains(_comPortName)) { _messageQueue.Publish(new NotifyUserMessage("COM Port for z-wave configuration is invalid.")); return; } try { var configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins", "config"); var userPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConfigurationBackup", Name); var options = ZWOptions.Instance; options.Initialize(configPath, userPath, string.Empty); options.AddOptionInt("SaveLogLevel", (int)ZWLogLevel.Detail); options.AddOptionInt("QueueLogLevel", (int)ZWLogLevel.Debug); options.AddOptionInt("DumpTriggerLevel", (int)ZWLogLevel.Error); if (!string.IsNullOrEmpty(_networkKey)) { options.AddOptionString("NetworkKey", _networkKey, false); } options.AddOptionBool("Associate", true); options.Lock(); _manager.Initialize(); _manager.OnNotification += OnZwaveNotification; _manager.AddDriver(_comPortName); } catch (Exception e) { _log.Error(e.Message, e); } }
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); } }
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); } }
/// <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 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); }
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; }
public void AddDriver(string comPath, ZWControllerInterface controllerInterface) { _manager.AddDriver(comPath, controllerInterface); }
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 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); } }
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(); } }
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 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); } }
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); } }