Пример #1
0
        public bool TryConnect(InsteonConnection connection)
        {
            if (connection != null)
            {
                try
                {
                    logger.DebugFormat("Trying connection '{0}'...", connection.ToString());

                    lock (bridge)
                    {
                        ControllerProperties = bridge.Connect(connection);
                    }
                    logger.DebugFormat("Connected to '{0}'", connection);

                    // disable deadman 0x48 ? TODO: according to spec this should be 00010000 0x10?
                    byte[] message = { (byte)InsteonModemSerialCommand.SetConfiguration, (byte)InsteonModemConfigurationFlags.DisableDeadman };
                    TrySend(message);

                    return(true);
                }
                catch (Exception ex)
                {
                    logger.ErrorFormat("Could not connect to '{0}'. {1}", connection.ToString(), ex.Message);
                }
            }
            return(false);
        }
Пример #2
0
 public static ISerialPort Create(InsteonConnection connection)
 {
     if (connection == null)
         throw new ArgumentNullException();
     switch (connection.Type)
     {
         case InsteonConnectionType.Net: return new NetDriver(connection.Value);
         case InsteonConnectionType.Serial: return new SerialPortDriver(connection.Value);
     }
     throw new ArgumentException();
 }
Пример #3
0
        public void Connect(InsteonConnection connection)
        {
            lock (bridge)
            {
                ControllerProperties = bridge.Connect(connection);
            }
            logger.DebugFormat("Connected to '{0}'", connection);

            // disable deadman 0x48 ? TODO: according to spec this should be 00010000 0x10?
            byte[] message = { (byte)InsteonModemSerialCommand.SetConfiguration, (byte)InsteonModemConfigurationFlags.DisableDeadman };
            Send(message);
        }
Пример #4
0
        public void SimpleConnectKnownSerialPortTest()
        {
            InsteonConnection connection;

            Assert.IsTrue(InsteonConnection.TryParse(insteonSource, out connection));
            network = new InsteonNetwork();
            var connected = network.TryConnect(connection);

            Assert.IsTrue(connected);
            Assert.AreEqual(connection.Address.Value, InsteonAddress.Parse(ConfigurationManager.AppSettings["plmIdentityTest"]).Value);
            network.Close();
        }
        public void Connect(InsteonConnection connection)
        {
            lock (bridge)
            {
                ControllerProperties = bridge.Connect(connection);
            }
            logger.DebugFormat("Connected to '{0}'", connection);

            // disable deadman 0x48 ? TODO: according to spec this should be 00010000 0x10?
            byte[] message = { (byte)InsteonModemSerialCommand.SetConfiguration, (byte)InsteonModemConfigurationFlags.DisableDeadman };
            Send(message);
        }
Пример #6
0
        public static ISerialPort Create(InsteonConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException();
            }
            switch (connection.Type)
            {
            case InsteonConnectionType.Net: return(new NetDriver(connection.Value));

            case InsteonConnectionType.Serial: return(new SerialPortDriver(connection.Value));
            }
            throw new ArgumentException();
        }
Пример #7
0
        public InsteonManager(string insteonSource)
        {
            logger.Debug("Creating insteon manager");
            InsteonConnection iConnection;

            if (InsteonConnection.TryParse(insteonSource, out iConnection))
            {
                logger.DebugFormat("Parsed InsteonConnection to {0}", iConnection.ToString());
                Connection = iConnection;
            }
            else
            {
                throw new Exception("Could not create Insteon Connection type from " + insteonSource);
            }

            Network = new InsteonNetwork {
                AutoAdd = true
            };
        }
Пример #8
0
        public void Connect(string comPort = null)
        {
            if (comPort == null)
            {
                comPort = "COM5";
            }

            var addr = new InsteonAddress(0x49, 0xFA, 0xED);
            var plm  = new InsteonConnection(InsteonConnectionType.Serial, comPort, "POWDERHORN", addr);


            Network.AutoAdd = true;

            bool ok = Network.TryConnect(plm);

            Links = Network.Controller.GetLinks();

            // add devices
            Links.ToList().ForEach(link =>
            {
                if (!Network.Devices.ContainsKey(link.Address))
                {
                    Network.Devices.Add(new InsteonAddress(link.Address.Value), new InsteonIdentity());
                }
            });

            // fire connection status
            var status = new ConnectionStatus()
            {
                Connected = ok, Links = Links
            };

            _connectionStatusSubject.OnNext(status);

            // fire device list
            _devicesSubject.OnNext(Network.Devices);

            // monitor for changes to device list
            Network.Devices.DeviceAdded += Devices_DeviceAdded;
        }
        public bool TryConnect(InsteonConnection connection)
        {
            if (connection != null)
            {
                try
                {
                    logger.DebugFormat("Trying connection '{0}'...", connection.ToString());

                    lock (bridge)
                    {
                        ControllerProperties = bridge.Connect(connection);
                    }
                    logger.DebugFormat("Connected to '{0}'", connection);

                    // disable deadman 0x48 ? TODO: according to spec this should be 00010000 0x10?
                    byte[] message = { (byte)InsteonModemSerialCommand.SetConfiguration, (byte)InsteonModemConfigurationFlags.DisableDeadman };
                    TrySend(message);

                    return true;
                }
                catch (Exception ex)
                {
                    logger.ErrorFormat("Could not connect to '{0}'. {1}", connection.ToString(), ex.Message);
                }
            }
            return false;
        }