static void Main(string[] args) { Console.WriteLine("GTosPMU to Data for openPDC Test"); // Create a new protocol parser parser = new MultiProtocolFrameParser(); // Attach to desired events parser.ConnectionAttempt += parser_ConnectionAttempt; parser.ConnectionEstablished += parser_ConnectionEstablished; parser.ConnectionException += parser_ConnectionException; parser.ParsingException += parser_ParsingException; parser.ReceivedConfigurationFrame += parser_ReceivedConfigurationFrame; parser.ReceivedDataFrame += parser_ReceivedDataFrame; // Define the connection string parser.ConnectionString = "phasorProtocol=IeeeC37_118V1; transportProtocol=Serial; accessID=2; " + "port=COM1; baudrate=115200; parity=None; stopbits=One; databits=8; " + "dtrenable=False; rtsenable=False; autoStartDataParsingSequence = false;"; // Start frame parser parser.AutoStartDataParsingSequence = true; parser.Start(); // Hold the console open until the operator hits the <Enter> key Console.ReadLine(); }
/// <summary> /// Intializes <see cref="PhasorMeasurementMapper"/>. /// </summary> public override void Initialize() { Dictionary<string, string> settings = Settings; ConfigurationCell definedDevice; string setting, signalReference; // Load required mapper specific connection parameters m_isConcentrator = settings["isConcentrator"].ParseBoolean(); m_accessID = ushort.Parse(settings["accessID"].ToString()); // Load optional mapper specific connection parameters if (settings.TryGetValue("virtual", out setting)) m_isVirtual = setting.ParseBoolean(); else m_isVirtual = false; if (settings.TryGetValue("timeZone", out setting)) m_timezone = TimeZoneInfo.FindSystemTimeZoneById(setting); else m_timezone = TimeZoneInfo.Utc; if (settings.TryGetValue("timeAdjustmentTicks", out setting)) m_timeAdjustmentTicks = long.Parse(setting); else m_timeAdjustmentTicks = 0; if (settings.TryGetValue("dataLossInterval", out setting)) m_dataStreamMonitor.Interval = double.Parse(setting) * 1000.0D; else m_dataStreamMonitor.Interval = 35000.0D; // Create a new phasor protocol frame parser for non-virtual connections if (!m_isVirtual) { MultiProtocolFrameParser frameParser = new MultiProtocolFrameParser(); // Most of the parameters in the connection string will be for the frame parser so we provide all of them, // other parameters will simply be ignored frameParser.ConnectionString = ConnectionString; // For captured data simulations we will inject a simulated timestamp and auto-repeat file stream... if (frameParser.TransportProtocol == TransportProtocol.File) { if (settings.TryGetValue("definedFrameRate", out setting)) frameParser.DefinedFrameRate = 1.0D / double.Parse(setting); else frameParser.DefinedFrameRate = 1.0D / 30.0D; if (settings.TryGetValue("simulateTimestamp", out setting)) frameParser.InjectSimulatedTimestamp = setting.ParseBoolean(); else frameParser.InjectSimulatedTimestamp = true; if (settings.TryGetValue("autoRepeatFile", out setting)) frameParser.AutoRepeatCapturedPlayback = setting.ParseBoolean(); else frameParser.AutoRepeatCapturedPlayback = true; } // Provide access ID to frame parser as this may be necessary to make a phasor connection frameParser.DeviceID = m_accessID; frameParser.SourceName = Name; // Assign reference to frame parser and attach to needed events this.FrameParser = frameParser; } // Load device list for this mapper connection m_definedDevices = new Dictionary<ushort, ConfigurationCell>(); if (m_isConcentrator) { StringBuilder deviceStatus = new StringBuilder(); int index = 0; deviceStatus.AppendLine(); deviceStatus.AppendLine(); deviceStatus.Append("Loading expected concentrator device list..."); deviceStatus.AppendLine(); deviceStatus.AppendLine(); // Making a connection to a concentrator that can support multiple devices foreach (DataRow row in DataSource.Tables["ActiveConcentratorDevices"].Select(string.Format("Acronym='{0}'", Name))) { definedDevice = new ConfigurationCell(ushort.Parse(row["AccessID"].ToString()), m_isVirtual); definedDevice.IDLabel = row["Acronym"].ToString(); definedDevice.Tag = uint.Parse(row["ID"].ToString()); m_definedDevices.Add(definedDevice.IDCode, definedDevice); // Create status display string for expected device deviceStatus.Append(" Device "); deviceStatus.Append((index++).ToString("00")); deviceStatus.Append(": "); deviceStatus.Append(definedDevice.IDLabel); deviceStatus.Append(" ("); deviceStatus.Append(definedDevice.IDCode); deviceStatus.Append(')'); deviceStatus.AppendLine(); } OnStatusMessage(deviceStatus.ToString()); } else { // Making a connection to a single device definedDevice = new ConfigurationCell(m_accessID, m_isVirtual); definedDevice.IDLabel = Name; definedDevice.Tag = ID; m_definedDevices.Add(definedDevice.IDCode, definedDevice); } // Load active device measurements for this mapper connection m_definedMeasurements = new Dictionary<string, IMeasurement>(); foreach (DataRow row in DataSource.Tables["ActiveDeviceMeasurements"].Select(string.Format("Acronym='{0}'", Name))) { signalReference = row["SignalReference"].ToString(); if (!string.IsNullOrEmpty(signalReference)) { try { m_definedMeasurements.Add(signalReference, new Measurement( uint.Parse(row["PointID"].ToString()), row["Historian"].ToString(), signalReference, double.Parse(row["Adder"].ToString()), double.Parse(row["Multiplier"].ToString()))); } catch (Exception ex) { OnProcessException(new InvalidOperationException(string.Format("Failed to load signal reference \"{0}\" due to exception: {1}", signalReference, ex.Message), ex)); } } } OnStatusMessage("Loaded {0} active device measurements...", m_definedMeasurements.Count); }
/// <summary> /// Releases the unmanaged resources used by the <see cref="PhasorMeasurementMapper"/> object and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!m_disposed) { try { if (disposing) { // Detach from frame parser events and set reference to null this.FrameParser = null; if (m_dataStreamMonitor != null) { m_dataStreamMonitor.Elapsed -= m_dataStreamMonitor_Elapsed; m_dataStreamMonitor.Dispose(); } m_dataStreamMonitor = null; } } finally { base.Dispose(disposing); // Call base class Dispose(). m_disposed = true; // Prevent duplicate dispose. } } }