Open() public method

public Open ( ) : void
return void
Beispiel #1
0
        static void Main(string[] args)
        {
            var portName = System.IO.Ports.SerialPort.GetPortNames().Where(element => element != "COM1").First();

            var controller = new ZWaveController("COM3");

            // netsh http add urlacl url=http://+:80/ user=Everyone
            // http://localhost:80/api/v1.0/controller/nodes/19/basic/get/

            //controller.Channel.Log = Console.Out;

            controller.Open();
            try
            {
                Run(controller).Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var inner in ex.InnerExceptions)
                {
                    LogMessage($"{inner}");
                }
            }
            catch (Exception ex)
            {
                LogMessage($"{ex}");
            }
            finally
            {
                Console.ReadLine();

                controller.Close();
            }
        }
Beispiel #2
0
 public void TestMethod1()
 {
     var controller = new ZWaveController("COM3");
     controller.Open();
     var version = controller.GetVersion().Result;
     controller.Close();
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            var portName = System.IO.Ports.SerialPort.GetPortNames().Where(element => 
                element != "COM1" 
                && element != "COM10" 
                && element != "COM11").First();

            var controller = new ZWaveController(portName);
            //controller.Channel.Log = Console.Out;

            controller.Open();
            try
            {
                Run(controller).Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var inner in ex.InnerExceptions)
                {
                    LogMessage($"{inner}");
                }
            }
            catch (Exception ex)
            {
                LogMessage($"{ex}");
            }
            finally
            {
                Console.ReadLine();
                controller.Close();
            }
        }
Beispiel #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseMvc();

            // Register the Controller event handlers (see methods example below)
            var controller = new ZWaveController("COM5");

            controller.Open();
            var nodesTask = controller.GetNodes();

            nodesTask.Wait();
            var nodes = nodesTask.Result;

            foreach (var node in nodes)
            {
                Subscribe(node);
            }
            while (true)
            {
                Thread.Sleep(1000);
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var portName = System.IO.Ports.SerialPort.GetPortNames().Where(element =>
                element != "COM1"
                && element != "COM10"
                && element != "COM11").First();

            var controller = new ZWaveController(portName);
            if (Directory.Exists(@"D:\Temp"))
            {
                controller.Channel.Log = File.CreateText(@"D:\Temp\ZWave_Driver.log");
            }

            controller.Open();
            try
            {
                Run(controller).Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var inner in ex.InnerExceptions)
                {
                    LogMessage($"{inner}");
                }
            }
            catch (Exception ex)
            {
                LogMessage($"{ex}");
            }
            finally
            {
                Console.ReadLine();
                controller.Close();
            }
        }
Beispiel #6
0
        public async Task SensorAlarm()
        {
            // the nodeID of the motion sensor
            byte motionSensorID = 5;

            // create the controller
            var controller = new ZWaveController("COM1");

            // open the controller
            controller.Open();

            // get the included nodes
            var nodes = await controller.GetNodes();

            // get the motionSensor
            var motionSensor = nodes[motionSensorID];

            // get the SensorAlarm commandclass
            var sensorAlarm = motionSensor.GetCommandClass<SensorAlarm>();

            // subscribe to alarm event
            sensorAlarm.Changed += (s, e) => Console.WriteLine("Alarm");

            // wait
            Console.ReadLine();

            // close the controller
            controller.Close();
        }
Beispiel #7
0
        public async Task TurnWallPlugOn()
        {
            // the nodeID of the wallplug
            byte wallPlugNodeID = 3;

            // create the controller
            var controller = new ZWaveController("COM1");
            
            // open the controller
            controller.Open();

            // get the included nodes
            var nodes = await controller.GetNodes();
            
            // get the wallplug
            var wallPlug = nodes[wallPlugNodeID];
            
            // get the SwitchBinary commandclass
            var switchBinary = wallPlug.GetCommandClass<SwitchBinary>();

            // turn wallplug on
            await switchBinary.Set(true);

            // close the controller
            controller.Close();
        }
Beispiel #8
0
 /// <summary>
 /// Invoked when the application is launched normally by the end user.  Other entry points
 /// will be used such as when the application is launched to open a specific file.
 /// </summary>
 /// <param name="e">Details about the launch request and process.</param>
 protected override void OnLaunched(LaunchActivatedEventArgs e)
 {
     Task.Run(() =>
     {
         var controller = new ZWaveController(0x0658, 0x0200);
         controller.Open();
         var version = controller.GetVersion().Result;
         controller.Close();
     });
 }
Beispiel #9
0
        public Module()
        {
            var portName = System.IO.Ports.SerialPort.GetPortNames().Where(element =>
                element != "COM1"
                && element != "COM10"
                && element != "COM11").First();

            controller = new ZWaveController(portName);
            controller.Open();

            LoadNodes();
        }
        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
            {
                await Policy
                    .Handle<WebException>()
                    .Or<Exception>()
                    .WaitAndRetryForeverAsync(_ => TimeSpan.FromSeconds(1))
                    .ExecuteAsync(async () =>
                    {
                        if (cancellationToken.IsCancellationRequested)
                        {
                            return;
                        }
                        await _library.Load(cancellationToken);
                    });

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                _controller = new ZWaveController(_comPortName);
                _controller.Open();
                _controller.Channel.NodeEventReceived += (s, e) => ContinueNodeQueueWorker(e.NodeID);

                while (!cancellationToken.IsCancellationRequested)
                {
                    _log.Debug("Discover Nodes");
                    await DiscoverNodes(cancellationToken);
                    await Task.Delay(TimeSpan.FromHours(1), cancellationToken).ContinueWith(_ => { });
                }
            }
            catch (Exception e)
            {
                _log.Error(e.Message, e);
            }
        }