void Notify_NewStatusMessage(object sender, FMStatusEventArgs e) { IFM2Device device; Dictionary <string, string> Lastdata1 = new Dictionary <string, string>(); Devices = ((cFM2Notify)sender).Devices; if (e.StatusChangeNotification == StatusChangeNotifications.MeterAdded) { FMCounter = FMCounter + 1; device = (IFM2Device)Devices.Item(((cFM2Notify)sender).DeviceIndex.ToString()); device.DeviceEvents = Notify; Lastdata.Add(device.SerialNumber, ""); metterArray.Add(device.DeviceIndex.ToString(), device.SerialNumber); //MessageBox.Show(metterArray[device.DeviceIndex.ToString()]); if (FMCounter >= 1) { ScanData.CheckTimer(Devices); } } if (e.StatusChangeNotification == StatusChangeNotifications.MeterRemoved) { metterArray.Remove(((cFM2Notify)sender).DeviceIndex.ToString()); Lastdata.Remove(((cFM2Notify)sender).SerialNumber); FMCounter = FMCounter - 1; if (FMCounter >= 1) { ScanData.CheckTimer(Devices); } } }
public void EngineFM2DeviceStatusNotifier(IFM2DeviceEvents CallbackData, cFM2Devices DevicesList) { m_DevicesList = DevicesList; switch (CallbackData.CallbackEvent) { case "MeterAdded": m_lastDeviceStatusConnection = "MeterAdded"; string s = CallbackData.DeviceIndex.ToString(); m_DevicesList.Item(ref s).DeviceEvents = NotifyMe; ScanForData.CheckTimer(ref m_DevicesList); m_stringDeviceList.Add(new deviceStringInfo(s, m_DevicesList.Item(ref s).SerialNumber)); Console.WriteLine("MeterAdded " + m_DevicesList.Item(ref s).SerialNumber); if (EventNotifyMeterAdded != null) { EventNotifyMeterAdded(m_DevicesList.Item(ref s).SerialNumber, s); } break; case "MeterRemoved": m_lastDeviceStatusConnection = "MeterRemoved"; ScanForData.CheckTimer(ref m_DevicesList); m_stringDeviceList.Clear(); Console.WriteLine("MeterRemoved"); foreach (IFM2Device d in m_DevicesList) { m_stringDeviceList.Add(new deviceStringInfo(d.DeviceIndex.ToString(), d.SerialNumber)); } if (EventNotifyMeterRemoved != null) { EventNotifyMeterRemoved(CallbackData.SerialNumber, CallbackData.DeviceIndex.ToString()); } break; default: m_lastDeviceStatusConnection = "NoMeterAdded"; break; } }
void Notify_NewMessage(object sender, FMDataEventArgs e) { CurIndex = e.DeviceIndex.ToString(); Debug.Write(CurIndex); IFM2Device device = (IFM2Device)Devices.Item(CurIndex); if (e.DataNotification == DataNotifications.MeasurementData) { Power = device.LastData; } if (e.DataNotification == DataNotifications.PowerOn) { PowerOn = true; } if (e.DataNotification == DataNotifications.PowerOff) { PowerOn = false; } if (e.DataNotification == DataNotifications.ProbeAdded) { ProbePresent = true; } if (e.DataNotification == DataNotifications.ProbeRemoved) { ProbePresent = false; } if (e.DataNotification == DataNotifications.Zeroing) { Debug.WriteLine("Zero event" + Notify.ZeroDeviceTimeoutCounter.ToString()); if (Notify.ZeroDeviceTimeoutCounter == 0) { Zeroed = true; } else { Zeroed = false; } } }
public void EngineFm2EventHandler(IFM2DeviceEvents CallbackData) { IFM2Device d; string s = CallbackData.DeviceIndex.ToString(); d = (IFM2Device)m_DevicesList.Item(ref s); if (d == null) { Console.WriteLine("Notify data is null"); } switch (CallbackData.CallbackEvent) { case "Fault": lastError.Add(d.LastFault.ToString()); Console.WriteLine(d.LastFault); if (EventNotifyFault != null) { EventNotifyFault(d.SerialNumber, d.LastFault.ToString()); } break; case "ProbeRemoved": Console.WriteLine("ProbeRemoved"); if (EventNotifyProbeRemoved != null) { EventNotifyProbeRemoved(d.SerialNumber); } break; case "ProbeAdded": Console.WriteLine("ProveAdded"); if (EventNotifyProbeAdded != null) { EventNotifyProbeAdded(d.SerialNumber); } break; case "PowerOn": Console.WriteLine("PowerOn " + d.SerialNumber); if (EventNotifyPowerOn != null) { EventNotifyPowerOn(d.SerialNumber); } break; case "PowerOff": Console.WriteLine("PowerOff" + d.SerialNumber); if (EventNotifyPowerOff != null) { EventNotifyPowerOff(d.SerialNumber); } break; case "MeasurementData": Console.WriteLine("Device " + d.SerialNumber + " " + d.LastData); if (EventNotifyMeasurementData != null) { EventNotifyMeasurementData(d.SerialNumber, d.LastData, d.LastPeriod); } break; case "PacketIsOverrange": Console.WriteLine("Device " + d.SerialNumber + "PacketIsOverrange"); if (EventNotifyPacketIsOverrange != null) { EventNotifyPacketIsOverrange(d.SerialNumber); } break; case "OverTemperature": Console.WriteLine("Device " + d.SerialNumber + "OverTemperature"); if (EventNotifyOverTemperature != null) { EventNotifyOverTemperature(d.SerialNumber); } break; case "MeasurementDataLost": Console.WriteLine("Device " + d.SerialNumber + "MeasurementDataLost"); if (EventNotifyMeasurementDataLost != null) { EventNotifyMeasurementDataLost(d.SerialNumber); } break; default: break; } }