private void GetConfigFrame()
        {
            if (m_Files.Count == 0)
            {
                m_ConfigFrameSource.SetResult(null);
            }

            if (m_ConfigFrameSource.Task.IsCompleted)
            {
                return;
            }

            MultiProtocolFrameParser parser = new MultiProtocolFrameParser();

            parser.PhasorProtocol    = PhasorProtocol.IEEEC37_Pdat;
            parser.TransportProtocol = Gemstone.Communication.TransportProtocol.File;
            parser.ConnectionString  = $"file={m_Files.First().Value}";

            parser.ReceivedConfigurationFrame += RecievedConfigFrame;
            parser.Start();

            m_ConfigFrameSource.Task.ContinueWith((t) => {
                parser.Stop();
            });
            return;
        }
        private void GenerateReader(List <string> files, Tuple <Channel <IDataFrame>, int, string> reader, CancellationToken cancellationToken)
        {
            Task.Run(() => {
                n_files = files.Count();

                for (int i = 0; i < files.Count; i++)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                    MultiProtocolFrameParser parser = new MultiProtocolFrameParser();
                    ManualResetEvent fileComplete   = new ManualResetEvent(false);
                    parser.PhasorProtocol           = PhasorProtocol.IEEEC37_Pdat;
                    parser.TransportProtocol        = Gemstone.Communication.TransportProtocol.File;
                    parser.ConnectionString         = $"file={files[i]}";
                    LogInfo($"reading File: {files[i]}");
                    parser.CompletedFileParsing += (object sender, EventArgs <int> conf) => { fileComplete.Set(); };
                    parser.ReceivedDataFrame    += (object sender, EventArgs <IDataFrame> conf) => {
                        reader.Item1.Writer.TryWrite(conf.Argument);
                    };
                    parser.DefinedFrameRate  = 10000000;
                    parser.DisconnectAtEOF   = true;
                    parser.ParsingException += ParsingException;
                    parser.Start();
                    WaitHandle.WaitAny(new WaitHandle[] { fileComplete, cancellationToken.WaitHandle }, 5000);
                    parser.Stop();
                    LogInfo($"Reading File {files[i]} complete");
                }
                reader.Item1.Writer.Complete();
            }, cancellationToken);
        }
Example #3
0
        public static void Main(string[] args)
        {
            m_definedMeasurements = new ConcurrentDictionary <string, MeasurementMetadata>();
            m_definedDevices      = new ConcurrentDictionary <ushort, ConfigurationCell>();

            if (WriteLogs)
            {
                m_exportFile = new StreamWriter(FilePath.GetAbsolutePath("InputTimestamps.csv"));
            }

            if (TestConcentrator)
            {
                // Create a new concentrator
                concentrator = new Concentrator(WriteLogs, FilePath.GetAbsolutePath("OutputTimestamps.csv"));
                concentrator.TimeResolution  = 333000;
                concentrator.FramesPerSecond = 30;
                concentrator.LagTime         = 3.0D;
                concentrator.LeadTime        = 9.0D;
                concentrator.PerformTimestampReasonabilityCheck = false;
                concentrator.ProcessByReceivedTimestamp         = true;
                concentrator.Start();
            }

            // Create a new protocol parser
            parser = new MultiProtocolFrameParser();
            parser.AllowedParsingExceptions = 500;
            parser.ParsingExceptionWindow   = 5;

            // 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;
            parser.ReceivedFrameBufferImage   += parser_ReceivedFrameBufferImage;
            parser.ConnectionTerminated       += parser_ConnectionTerminated;

            // Define the connection string
            //parser.ConnectionString = @"phasorProtocol=IeeeC37_118V1; transportProtocol=UDP; localport=5000; server=233.123.123.123:5000; interface=0.0.0.0";
            //parser.ConnectionString = @"phasorProtocol=Ieee1344; transportProtocol=File; file=D:\Projects\Applications\openPDC\Synchrophasor\Current Version\Build\Output\Debug\Applications\openPDC\Sample1344.PmuCapture";
            //parser.ConnectionString = @"phasorProtocol=Macrodyne; accessID=1; transportProtocol=File; skipDisableRealTimeData = true; file=C:\Users\Ritchie\Desktop\Development\Macrodyne\ING.out; iniFileName=C:\Users\Ritchie\Desktop\Development\Macrodyne\BCH18Aug2011.ini; deviceLabel=ING1; protocolVersion=G";
            //parser.ConnectionString = @"phasorProtocol=Iec61850_90_5; accessID=1; transportProtocol=UDP; skipDisableRealTimeData = true; localPort=102; interface=0.0.0.0; commandChannel={transportProtocol=TCP; server=172.21.1.201:4712; interface=0.0.0.0}";
            //parser.ConnectionString = @"phasorProtocol=FNET; transportProtocol=TCP; server=172.21.4.100:4001; interface=0.0.0.0; isListener=false";
            //parser.ConnectionString = @"phasorProtocol=Macrodyne; transportProtocol=Serial; port=COM6; baudrate=38400; parity=None; stopbits=One; databits=8; dtrenable=False; rtsenable=False;";
            //parser.ConnectionString = @"phasorProtocol=SelFastMessage; transportProtocol=Serial; port=COM5; baudrate=57600; parity=None; stopbits=One; databits=8; dtrenable=False; rtsenable=False;";
            //parser.ConnectionString = @"phasorProtocol=IEEEC37_118v1; transportProtocol=File; file=C:\Users\Ritchie\Desktop\MTI_Test_3phase.PmuCapture; checkSumValidationFrameTypes=DataFrame,HeaderFrame,CommandFrame";
            //parser.ConnectionString = @"phasorProtocol=IEEEC37_118V1; transportProtocol=tcp; accessID=105; server=172.31.105.135:4712; interface=0.0.0.0; isListener=false";
            parser.ConnectionString = @"phasorProtocol=IEEEC37_118V1; transportProtocol=Serial; port=COM6; baudRate=115200; dataBits=8; stopBits=One; parity=None; dtrEnable=false; rtsEnable=false; autoStartDataParsingSequence=false; disableRealTimeDataOnStop=false";

            Dictionary <string, string> settings = parser.ConnectionString.ParseKeyValuePairs();
            string setting;

            // TODO: These should be optional picked up from connection string inside of MPFP
            // Apply other settings as needed
            if (settings.TryGetValue("accessID", out setting))
            {
                parser.DeviceID = ushort.Parse(setting);
            }

            if (settings.TryGetValue("simulateTimestamp", out setting))
            {
                parser.InjectSimulatedTimestamp = setting.ParseBoolean();
            }

            if (settings.TryGetValue("allowedParsingExceptions", out setting))
            {
                parser.AllowedParsingExceptions = int.Parse(setting);
            }

            if (settings.TryGetValue("parsingExceptionWindow", out setting))
            {
                parser.ParsingExceptionWindow = Ticks.FromSeconds(double.Parse(setting));
            }

            if (settings.TryGetValue("autoStartDataParsingSequence", out setting))
            {
                parser.AutoStartDataParsingSequence = setting.ParseBoolean();
            }

            if (settings.TryGetValue("skipDisableRealTimeData", out setting))
            {
                parser.SkipDisableRealTimeData = setting.ParseBoolean();
            }

            if (settings.TryGetValue("disableRealTimeDataOnStop", out setting))
            {
                parser.DisableRealTimeDataOnStop = setting.ParseBoolean();
            }

            // When connecting to a file based resource you may want to loop the data
            //parser.AutoRepeatCapturedPlayback = true;

            Console.WriteLine("ConnectionString: {0}", parser.ConnectionString);

            parser.Start();

            Console.WriteLine("Press <enter> to terminate application...");
            Console.ReadLine();

            parser.Stop();

            // Stop concentrator
            if (TestConcentrator)
            {
                concentrator.Stop();
            }

            if (WriteLogs)
            {
                m_exportFile.Close();
            }
        }
        public IConfigurationFrame RequestDeviceConfiguration(string connectionString, int idCode, ScanParameters scanParams, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                ShowUpdateMessage($"{Tab2}ERROR: No connection string was specified, request for configuration canceled.");
                return(new ConfigurationErrorFrame());
            }

            try
            {
                int responseTimeout    = scanParams.ResponseTimeout;
                int configFrameTimeout = scanParams.ConfigFrameTimeout;

                // Most of the parameters in the connection string will be for the data source in the frame parser
                // so we provide all of them, other parameters will simply be ignored
                m_frameParser.ConnectionString = connectionString;

                // Provide access ID to frame parser as this may be necessary to make a phasor connection
                m_frameParser.DeviceID = (ushort)idCode;

                // Clear any existing configuration frame
                m_configurationFrame = null;

                // Set auto-start parsing sequence for scan state
                m_autoStartParsingSequenceForScan = scanParams.AutoStartParsingSequenceForScan;

                // Inform user of temporary loss of command access
                ShowUpdateMessage($"{Tab2}Requesting device configuration...");

                // Make sure the wait handles are not set
                m_configurationWaitHandle.Reset();
                m_bytesReceivedWaitHandle.Reset();

                // Start the frame parser - this will attempt connection
                m_frameParser.Start();

                // Wait for any bytes received within configured response timeout
                if (!m_bytesReceivedWaitHandle.Wait(responseTimeout, cancellationToken))
                {
                    ShowUpdateMessage($"{Tab2}Timed-out waiting for device response.");
                }
                else
                {
                    // Wait to receive the configuration frame
                    if (!m_configurationWaitHandle.Wait(configFrameTimeout, cancellationToken))
                    {
                        ShowUpdateMessage($"{Tab2}Timed-out waiting to receive remote device configuration.");
                    }
                }

                // Terminate connection to device
                m_frameParser.Stop();

                if (m_configurationFrame is null)
                {
                    m_configurationFrame = new ConfigurationErrorFrame();
                    ShowUpdateMessage($"{Tab2}Failed to retrieve remote device configuration.");
                }

                return(m_configurationFrame);
            }
            catch (Exception ex)
            {
                ShowUpdateMessage($"{Tab2}ERROR: Failed to request configuration due to exception: {ex.Message}");
            }

            return(new ConfigurationErrorFrame());
        }