コード例 #1
0
ファイル: ZWaveNetwork.cs プロジェクト: Mavtak/roomie
        public void Connect()
        {
            try
            {
                if (ZWaveController.IsConnected)
                {
                    return;
                }

                ZWaveController.Connect();
                //TODO: clean this up
                Name    = "ZWave" + ZWaveController.HomeID.ToString();
                Address = Name;
            }
            catch (Exception e)
            {
                if (e.Message.Contains("not licensed"))
                {
                    throw new SdkNotLicencedException();
                }
                throw new HomeAutomationException("Error while connecting to the Z-Wave controller: " + e.Message);
            }

            ScanForDevices();

            //TODO: should this be elsewhere?
            Load();

            Connected();
        }
コード例 #2
0
 public Task Start()
 {
     if (_startingSemaphor == null)
     {
         _startingSemaphor = new SemaphoreSlim(0, 1);
         Controller.Connect();
     }
     return(_startingSemaphor.WaitAsync());
 }
コード例 #3
0
        public static void SetSerialPortName(ZWaveController controller, string com_port)
        {
            var port = com_port;

            if (!String.IsNullOrWhiteSpace(port))
            {
                serialPortName      = port;
                controller.PortName = serialPortName;
                controller.Connect();
            }
        }
コード例 #4
0
        private static void SetSerialPortName(ZWaveController controller)
        {
            Console.WriteLine("Enter the serial port name (eg. COM7 or /dev/ttyUSB0):");
            var port = Console.ReadLine().Trim();

            if (!String.IsNullOrWhiteSpace(port))
            {
                serialPortName      = port;
                controller.PortName = serialPortName;
                controller.Connect();
            }
        }
コード例 #5
0
        public bool Connect()
        {
            int commandDelay = 100;

            if (this.GetOption("Delay") != null)
            {
                int.TryParse(this.GetOption("Delay").Value, out commandDelay);
            }
            controller.CommandDelay = commandDelay;
            controller.PortName     = this.GetOption("Port").Value;
            controller.Connect();
            return(true);
        }
コード例 #6
0
        public static void Main(string[] cargs)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\nZWaveLib Test Program\n");
            Console.ForegroundColor = ConsoleColor.White;

            var controller = new ZWaveController(serialPortName);

            // Register controller event handlers
            controller.ControllerStatusChanged += Controller_ControllerStatusChanged;;
            controller.DiscoveryProgress       += Controller_DiscoveryProgress;
            controller.NodeOperationProgress   += Controller_NodeOperationProgress;
            controller.NodeUpdated             += Controller_NodeUpdated;

            // Main program loop
            var command = "";

            while (command != "!")
            {
                ShowMenu();
                // TODO: Allow issuing CommandClass commands on nodes from the console input
                // TODO: Add "Associate node to controller" option
                // TODO: Add "Query node parameters" based on implemented classes
                command = Console.ReadLine();
                switch (command)
                {
                case "0":
                    ToggleDebug(!showDebugOutput);
                    break;

                case "1":
                    ListNodes(controller);
                    break;

                case "2":
                    StartNodeAdd(controller);
                    break;

                case "3":
                    StopNodeAdd(controller);
                    break;

                case "4":
                    StartNodeRemove(controller);
                    break;

                case "5":
                    StopNodeRemove(controller);
                    break;

                case "6":
                    HealNetwork(controller);
                    break;

                case "7":
                    RunStressTest(controller);
                    break;

                case "8":
                    ShowZWaveLibApi();
                    break;

                case "9":
                    Discovery(controller);
                    break;

                case "?":
                    SetSerialPortName(controller);
                    break;

                case "+":
                    controller.Connect();
                    break;

                case "~":
                    RunCommandInteractive(controller);
                    break;
                }
            }
            Console.WriteLine("\nCiao!\n");
            controller.Dispose();
        }