public static void InitSensors() { List <SensorGroupCtrl> sgs = ls.Where(g => g.isLocal == true).ToList(); foreach (SensorGroupCtrl sg in sgs) { if (sg.hasDTMFS) { try { ChannelFactory <IBaseSensorsContract> factory = new ChannelFactory <IBaseSensorsContract>("DTMF", new EndpointAddress(sg.dtmf_Address)); IBaseSensorsContract client = factory.CreateChannel(); if (!client.IsDetecting()) { client.StartDetect(); } factory.Close(); sg.IsDTMFActive = true; } catch (Exception e) { sg.IsDTMFActive = false; Console.WriteLine("No se pudo establecer comunicacion con el servicio: " + sg.dtmf_Address); } } if (sg.hasPPort) { try { ChannelFactory <IPortServerContract> factory = new ChannelFactory <IPortServerContract>("PPort", new EndpointAddress(sg.pport_Address)); IBaseSensorsContract client = factory.CreateChannel(); if (!client.IsDetecting()) { client.StartDetect(); } factory.Close(); sg.IsPPortActive = true; } catch (Exception e) { sg.IsPPortActive = false; Console.WriteLine("No se pudo establecer comunicacion con el servicio: " + sg.pport_Address); } } } }
void StartSensors(String SensorType) { List <SensorGroupCtrl> sgs = ls.Where(g => g.isLocal == true).ToList(); foreach (SensorGroupCtrl sg in sgs) { if (sg.hasDTMFS && SensorType == "DTMF") { try { ChannelFactory <IBaseSensorsContract> factory = new ChannelFactory <IBaseSensorsContract>("DTMF", new EndpointAddress(sg.dtmf_Address)); IBaseSensorsContract client = factory.CreateChannel(); if (!client.IsDetecting()) { client.StartDetect(); } factory.Close(); } catch (Exception e) { } } if (sg.hasPPort && SensorType == "PPort") { try { ChannelFactory <IPortServerContract> factory = new ChannelFactory <IPortServerContract>("PPort", new EndpointAddress(sg.pport_Address)); IBaseSensorsContract client = factory.CreateChannel(); if (!client.IsDetecting()) { client.StartDetect(); } factory.Close(); } catch (Exception e) { } } } }
void ReadSensorsStatus() { List <SensorGroupCtrl> sgs; sgs = ls.Where(g => g.isLocal == false).ToList(); sgs = ls.Where(g => g.isLocal == true).ToList(); foreach (SensorGroupCtrl sg in sgs) { if (sg.hasDTMFS) { try { ChannelFactory <IBaseSensorsContract> factory = new ChannelFactory <IBaseSensorsContract>("DTMF", new EndpointAddress(sg.dtmf_Address)); IBaseSensorsContract client = factory.CreateChannel(); if (!client.IsDetecting()) { sg.IsDTMFActive = false; LB_dtmfStatus.Text = "Sensores DTMF: Desconectados."; sg.Sensors.Where(sens => sens.DeviceType == "DTMF").ToList().ForEach(sens => sens.Active = false); } else { sg.Sensors.Where(sens => sens.DeviceType == "DTMF").ToList().ForEach(sens => sens.Active = true); LB_dtmfStatus.Text = "Sensores DTMF: Conectados."; sg.IsDTMFActive = true; } factory.Close(); } catch (Exception e) { sg.IsDTMFActive = false; LB_dtmfStatus.Text = "Sensores DTMF: Desconectados."; sg.Sensors.Where(sens => sens.DeviceType == "DTMF").ToList().ForEach(sens => sens.Active = false); } } if (sg.hasPPort) { try { ChannelFactory <IPortServerContract> factory = new ChannelFactory <IPortServerContract>("PPort", new EndpointAddress(sg.pport_Address)); IBaseSensorsContract client = factory.CreateChannel(); if (!client.IsDetecting()) { LB_PPortStatus.Text = "Sensores Puerto Paralelo: Desconectados."; sg.IsPPortActive = false; sg.Sensors.Where(sens => sens.DeviceType == "PSC").ToList().ForEach(sens => sens.Active = false); } else { sg.Sensors.Where(sens => sens.DeviceType == "PSC").ToList().ForEach(sens => sens.Active = true); LB_PPortStatus.Text = "Sensores Puerto Paralelo: Conectados."; sg.IsPPortActive = true; } factory.Close(); } catch (Exception e) { sg.IsPPortActive = false; LB_PPortStatus.Text = "Sensores Puerto Paralelo: Desconectados."; sg.Sensors.Where(sens => sens.DeviceType == "PSC").ToList().ForEach(sens => sens.Active = false); } } } }