public override void Initialize(MagicHomeLedOutputInfo outputInfo) { IPAddress ip; int port = 5577; switch (outputInfo.AddressType) { case AddressType.MacAddress: DeviceFindResult foundDevice = DeviceFinder.FindDevices().FirstOrDefault(x => x.MacAddress.Equals(outputInfo.MacAddress)); if (foundDevice == null) { throw new Exception(string.Format("device with mac {0} could not be found", outputInfo.MacAddress)); } ip = foundDevice.IpAddress; break; case AddressType.IpAddress: ip = outputInfo.IPAddress; if (outputInfo.Port.HasValue) { port = outputInfo.Port.Value; } break; default: throw new IndexOutOfRangeException(); } _device = new Device(new IPEndPoint(ip, port), outputInfo.DeviceType); _device.TurnOn(); }
private void RefreshDevicesList() { var task = new Task <IEnumerable <DeviceFindResult> >(() => DeviceFinder.FindDevices().ToList()); task.Start(); refreshButton.Text = "..."; task.ContinueWith(tsk => this.Invoke((MethodInvoker)(() => RefreshListDone(tsk.Result)))); }
static SmartPlug DeviceFinderDemo(IPAddress ipAddressToUse) { DeviceFinder deviceFinder = new DeviceFinder(SENDINGPORT, LISTENINGPORT, TIMEOUTPERIOD); // finding devices in the network(s), the computer is located, as these could be // more than one, tell the FindDevices method, which IP to use. deviceFinder.FindDevices(ipAddressToUse); while (deviceFinder.IsStillSearching) { System.Threading.Thread.Sleep(500); } //System.Threading.Thread.Sleep(30000); IEnumerable <Contrequarte.SmartPlug.Core.SmartPlug> smartPlugs = deviceFinder.SmartPlugList; foreach (var smartP in smartPlugs) { System.Console.WriteLine(string.Format("Name: {0} IP:{1} model: {2} sw version: {3} " , smartP.Name, smartP.IpAddress, smartP.Model, smartP.SoftwareVersion)); } int i = smartPlugs.Count(); return(smartPlugs.First()); }