public EthernetIO(string ipAddr) { try { m_connected = false; m_ipAddr = ipAddr; m_device = EDDevice.Create(ipAddr); m_device.DeviceStatusChangedEvent += m_device_DeviceStatusChangedEvent; m_watchdogTimer = new Timer(5.0); // monitor Ethernet connection m_watchdogTimer.Elapsed += m_watchdogTimer_Elapsed; m_watchdogTimer.Start(); m_tryingToConnect = false; m_watchdogTimer_Elapsed(null, null); m_device.Inputs.IOLineChange += Inputs_IOLineChange; m_device.Outputs.IOLineChange += Outputs_IOLineChange; } catch (Exception ex) { OnIOMessageEvent(new IOMessageEventArgs("Could not create Ethernet IO: " + ex.Message)); } }
public void set(LockType value) { using (IConnection connection = new TCPConnection(value.OutputIP)) { using (EDDevice ed = GetDeviceType(value.OutputType, connection)) { ed.Connect(); ed.Outputs[value.OutputPort].Value = 0; } } }
void Inputs_IOLineChange(IOLine line, EDDevice device, IOChangeTypes changeType) { switch (line.IONumber) { case 0: if (changeType == IOChangeTypes.RisingEdge) { if (m_device.Outputs[0].Value == 1) // magnetic latch is ON { GlobalVars.DoorStatus = DOOR_STATUS.LOCKED; } else { GlobalVars.DoorStatus = DOOR_STATUS.CLOSED; } } else if (changeType == IOChangeTypes.FallingEdge) { GlobalVars.DoorStatus = DOOR_STATUS.OPEN; } OnDoorStatusEvent(new DoorStatusEventArgs(GlobalVars.DoorStatus)); break; case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; } OnIOEvent(new IOEventArgs(IO_TYPE.INPUT, line.IONumber, line.Value == 1 ? true : false)); }
public EthernetIO(string ipAddr) { m_connected = false; m_ipAddr = ipAddr; m_device = EDDevice.Create(ipAddr); m_device.DeviceStatusChangedEvent += m_device_DeviceStatusChangedEvent; m_watchdogTimer = new Timer(5.0); // monitor Ethernet connection m_watchdogTimer.Elapsed += m_watchdogTimer_Elapsed; m_watchdogTimer.Start(); m_tryingToConnect = false; m_watchdogTimer_Elapsed(null, null); m_device.Inputs.IOLineChange += Inputs_IOLineChange; m_device.Outputs.IOLineChange += Outputs_IOLineChange; }
void Outputs_IOLineChange(IOLine line, EDDevice device, IOChangeTypes changeType) { OnIOEvent(new IOEventArgs(IO_TYPE.OUTPUT, line.IONumber, line.Value == 1 ? true : false)); }
public void InitialiseDevices() { foreach (string ip in _deviceIps) _devices.Add(ip, EDDevice.Create(ip)); }
public void AddDevice(string ip) { if (_deviceIps.Add(ip)) _devices.Add(ip, EDDevice.Create(ip)); }
private void TryToConnect() { if (string.IsNullOrEmpty(m_Properties.IP)) { Log?.Invoke(EventLogEntryCodes.NoIPSet, null); return; } Log?.Invoke(EventLogEntryCodes.Connecting, new string[] { m_Properties.IP }); Status.Status = StatusEnum.Connecting; try { if (m_Properties.EDDevice == null) { m_Properties.EDDevice = EDDevice.Create(m_Properties.IP); m_Properties.EDDevice.DeviceStatusChangedEvent += DeviceStatusChanged; } Log?.Invoke(EventLogEntryCodes.Connected, new string[] { m_Properties.EDDevice.Describe(), m_Properties.IP }); } catch (System.Net.WebException ex) { m_Properties.EDDevice = null; Status.Status = StatusEnum.Errored; Log?.Invoke(EventLogEntryCodes.ConnectionException, new string[] { m_Properties.IP, ex.Message }); throw (ex); } catch (Exception ex) { m_Properties.EDDevice = null; Status.Status = StatusEnum.Errored; Log?.Invoke(EventLogEntryCodes.ConnectionException, new string[] { m_Properties.IP, ex.Message }); throw (ex); } if (!string.IsNullOrEmpty(m_Properties.Name) && m_Properties.Name != m_Properties.EDDevice.Protocol.DeviceName) { m_Properties.EDDevice.Protocol.DeviceName = m_Properties.Name; } if (string.IsNullOrEmpty(m_Properties.Name) && m_Properties.EDDevice.Protocol.DeviceName != null) { m_Properties.Name = m_Properties.EDDevice.Protocol.DeviceName; } var NewEvents = new List <BBDeviceEvent>(); NewEvents.AddRange(m_Properties.IOEvents); foreach (var InputIO in m_Properties.EDDevice.Inputs) { BBDeviceEvent FoundEvent = m_Properties.IOEvents.FirstOrDefault(e => e.IONumber == InputIO.IONumber); // BBEventFire EventFire = null; if (FoundEvent == null) { string NewGuid = System.Guid.NewGuid().ToString(); FoundEvent = new BBDeviceEvent { Guid = NewGuid, Id = NewGuid, IONumber = InputIO.IONumber, Description = "Device [" + m_Properties.MACAddress + "] I/O [" + InputIO.IONumber.ToString() + "]", Subjects = new string[] { Core.Instance.Defaults.Key }, RisingEdgeValue = Core.Instance.Defaults.RisingEdge, FallingEdgeValue = Core.Instance.Defaults.FallingEdge }; // EventFire = new BBEventFire(NewEvent.Guid, NewEvent.Keys[0], NewEvent.RisingEdgeValue, NewEvent.FallingEdgeValue); // NewEvent.Object = EventFire; NewEvents.Add(FoundEvent); } else { // EventFire = FoundEvent.Object as BBEventFire; } InputIO.IOLineRisingEdge += FoundEvent.OnIOLineRisingEdgeChangedEvent; InputIO.IOLineFallingEdge += FoundEvent.OnIOLineFallingEdgeChangedEvent; FoundEvent.SetInit(InputIO.Value); } m_Properties.IOEvents = NewEvents.ToArray(); var NewOutputs = new List <BBOutput>(); NewOutputs.AddRange(m_Properties.Outputs); foreach (var item in m_Properties.EDDevice.Outputs) { BBOutput AOutput = m_Properties.Outputs.FirstOrDefault(o => o.Name == item.IONumber.ToString()); if (AOutput == null) { NewOutputs.Add(new BBOutput(item)); } else { AOutput.IOLine = item; } } m_Properties.Outputs = NewOutputs.ToArray(); Status.Status = StatusEnum.Connected; Connected?.Invoke(); }
public void OnIOLineFallingEdgeChangedEvent(IOLine line, EDDevice device, IOChangeTypes changeType) { m_Cached = new Payload(Id, new PayloadSubject[] { new PayloadSubject("value", FallingEdgeValue) }); Invoke(m_Cached); }