Beispiel #1
0
        public Frm_DataViewer(string VCLibsFile)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            DataFilePathes = null;
            LastFilePath   = "";
            oConcatData    = null;
            RecordEvents   = new List <CS_RecordEvent>();

            ViewerBook = new CS_DataViewerBook();

            VCLibCollectionPath = VCLibsFile;
            VCLibraries         = null;

            if (!(VCLibCollectionPath.Equals("")))
            {
                VCLibraries = new CS_VCLibrariesCollection();
                VCLibraries.LoadLibrariesList(VCLibCollectionPath);
            }

            NextViewerPageKeyId = 1;
            ContextTabPage      = null;

            Dlg_OpenViewerBook.InitialDirectory = CANStreamTools.MyDocumentPath + "\\CANStream\\Data Viewers";
            Dlg_OpenViewerPage.InitialDirectory = CANStreamTools.MyDocumentPath + "\\CANStream\\Data Viewers";
            Dlg_SaveViewerBook.InitialDirectory = CANStreamTools.MyDocumentPath + "\\CANStream\\Data Viewers";
            Dlg_SaveViewerPage.InitialDirectory = CANStreamTools.MyDocumentPath + "\\CANStream\\Data Viewers";
        }
Beispiel #2
0
        private void UpDate_PagesSeries(GW_DataFile oData)
        {
            foreach (TabPage oPage in Tab_Viewers.TabPages)
            {
                if (!(oPage.Equals(Tab_NewViewer)))
                {
                    Ctrl_WaveForm oWave = oPage.Controls[0] as Ctrl_WaveForm;

                    oWave.Set_DataFile(oData);
                    oWave.Refresh_Graphic();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Create the graphic data file of the current cycle for the Ctrl_GraphWindow control
        /// </summary>
        /// <returns>Ctrl_GraphWindow data file</returns>
        public GW_DataFile CreateCycleGraphData()
        {
            GW_DataFile oGraphData = new GW_DataFile();

            oGraphData.DataSamplingMode = SamplingMode.MultipleRates;

            if (!(oCanNodesMap == null))
            {
                foreach (CycleTimeEvent TxEvent in TimeEvents)
                {
                    foreach (CANMessageData MsgData in TxEvent.MessagesData)
                    {
                        CANMessage MsgCfg = oCanNodesMap.GetCANMessage(NumberBaseConverter.Dec2Hex(MsgData.uMessageId), MessageResearchOption.Identifier);

                        if (!(MsgCfg == null))
                        {
                            TPCANMsg sTPMsg = new TPCANMsg();
                            sTPMsg.DATA = MsgData.byteMessageData;

                            CANMessageDecoded oMsgDecoded = new CANMessageDecoded(MsgCfg, sTPMsg);

                            if (oMsgDecoded.bMessageDecoded)
                            {
                                foreach (CANParameter oParam in oMsgDecoded.Parameters)
                                {
                                    GW_DataChannel oGraphChan = oGraphData.Get_DataChannel(oParam.Name);

                                    if (oGraphChan == null)
                                    {
                                        oGraphChan = new GW_DataChannel(oParam.Name, SamplingMode.MultipleRates);
                                        oGraphData.Channels.Add(oGraphChan);
                                    }

                                    SerieSample sSample = new SerieSample();
                                    sSample.SampleTime  = (double)TxEvent.TimeEvent / 1000;
                                    sSample.SampleValue = oParam.DecodedValue;

                                    oGraphChan.Add_ChannelValue(sSample);
                                }
                            }
                        }
                    }
                }
            }

            return(oGraphData);
        }
Beispiel #4
0
        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

                        #if DEBUG
            GraphWindowProperties oProperties = new GraphWindowProperties();
            oProperties.Open_Properties(Application.StartupPath + "\\GraphConfigTest_Overlay.xgw");

            GW_DataFile oData = new GW_DataFile();
            //oData.Load_DataFile(Application.StartupPath + "\\DataTest.csv");	//FR: Decimal separator ','
            oData.Load_DataFile(Application.StartupPath + "\\DataTest2.csv");                   //US: Decimal separator '.'

            this.ctrl_WaveForm1.Properties = oProperties;
            this.ctrl_WaveForm1.Set_DataFile(oData);
                        #endif
        }
Beispiel #5
0
        private void Load_DataFiles()
        {
            LastFilePath = "";

            if (!(DataFilePathes == null))
            {
                GW_DataFile[] oDataFiles  = new GW_DataFile[DataFilePathes.Length];
                bool          XmlDataFile = Path.GetExtension(DataFilePathes[0]).Equals(".xrdf");


                for (int iFile = 0; iFile < DataFilePathes.Length; iFile++)
                {
                    oDataFiles[iFile] = new GW_DataFile();

                    if (XmlDataFile)
                    {
                        oDataFiles[iFile].Load_XmlDataFile(DataFilePathes[iFile], false);
                    }
                    else
                    {
                        oDataFiles[iFile].Load_DataFile(DataFilePathes[iFile]);
                    }
                }

                if (XmlDataFile)
                {
                    UpDate_PagesSeries(Concat_XmlDataFiles(oDataFiles));
                }
                else
                {
                    UpDate_PagesSeries(Concat_DataFiles(oDataFiles));
                }

                LastFilePath = Path.GetDirectoryName(DataFilePathes[DataFilePathes.Length - 1]);
            }
        }
Beispiel #6
0
        private GW_DataFile Concat_XmlDataFiles(GW_DataFile[] oDataFiles)
        {
            if (oDataFiles == null)
            {
                return(null);
            }

            //Concatened data file creation
            oConcatData = new GW_DataFile();
            oConcatData.DataSamplingMode = SamplingMode.MultipleRates;

            //Complete channel list creation
            foreach (GW_DataFile oFile in oDataFiles)
            {
                foreach (GW_DataChannel oChan in oFile.Channels)
                {
                    //Create the data channel into the concatenated data file if it does not exist already
                    if (!(oConcatData.DataChannelExists(oChan.Name)))
                    {
                        GW_DataChannel oConcatChan = new GW_DataChannel(oChan.Name, SamplingMode.MultipleRates);

                        //Copy XML data channel properties
                        oConcatChan.Description   = oChan.Description;
                        oConcatChan.Unit          = oChan.Unit;
                        oConcatChan.GraphicFormat = oChan.GraphicFormat.Get_Clone();

                        foreach (GraphReferenceLine oRefLine in oChan.ChannelReferenceLines)
                        {
                            oConcatChan.ChannelReferenceLines.Add(oRefLine.Get_Clone());
                        }

                        oConcatData.Channels.Add(oConcatChan);
                    }
                }
            }

            //Append current file channel samples to the concatenated data file channel
            foreach (GW_DataChannel oConcatChan in oConcatData.Channels)
            {
                double Concat_T = 0;

                foreach (GW_DataFile oFile in oDataFiles)
                {
                    GW_DataChannel oDataChan = oFile.Get_DataChannel(oConcatChan.Name);

                    if (!(oDataChan == null))
                    {
                        if (oDataChan.Samples.Count > 1)
                        {
                            for (int iSample = 0; iSample < oDataChan.Samples.Count; iSample++)
                            {
                                if (oConcatChan.Samples.Count > 0)
                                {
                                    if (iSample > 0)
                                    {
                                        Concat_T += (oDataChan.Samples[iSample].SampleTime - oDataChan.Samples[iSample - 1].SampleTime);
                                    }
                                    else
                                    {
                                        Concat_T += (oDataChan.Samples[1].SampleTime - oDataChan.Samples[0].SampleTime);
                                    }
                                }

                                SerieSample sNewSample = new SerieSample();
                                sNewSample.SampleTime  = Concat_T;
                                sNewSample.SampleValue = oDataChan.Samples[iSample].SampleValue;

                                oConcatChan.Samples.Add(sNewSample);

                                if (oConcatChan.Samples.Count == 1)
                                {
                                    oConcatChan.Min = oDataChan.Samples[iSample].SampleValue;
                                    oConcatChan.Max = oDataChan.Samples[iSample].SampleValue;
                                }
                                else
                                {
                                    if (oDataChan.Samples[iSample].SampleValue < oConcatChan.Min)
                                    {
                                        oConcatChan.Min = oDataChan.Samples[iSample].SampleValue;
                                    }
                                    if (oDataChan.Samples[iSample].SampleValue > oConcatChan.Max)
                                    {
                                        oConcatChan.Max = oDataChan.Samples[iSample].SampleValue;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //Virtual channels computations
            if (!(VCLibraries == null))
            {
                VCLibraries.InitLibrariesComputation(); //Virtual channels libraries initialization

                foreach (CS_VirtualChannel oVirtChan in VCLibraries.ChannelsComputationList)
                {
                    bool           bComputeVirtual = true;
                    GW_DataChannel oCarrierChannel = null;

                    foreach (string ChanVar in oVirtChan.ChannelVariables)
                    {
                        GW_DataChannel oDataChan = oConcatData.Get_DataChannel(ChanVar);

                        if (!(oDataChan == null))
                        {
                            if (oCarrierChannel == null)
                            {
                                oCarrierChannel = oDataChan;
                            }
                            else
                            {
                                if (oDataChan.Samples.Count > oCarrierChannel.Samples.Count)
                                {
                                    oCarrierChannel = oDataChan;
                                }
                            }
                        }
                        else
                        {
                            bComputeVirtual = false;
                            break;
                        }
                    }

                    if (oCarrierChannel != null && bComputeVirtual)
                    {
                        GW_DataChannel oVirtualData = new GW_DataChannel(oVirtChan.Name, SamplingMode.MultipleRates);

                        oVirtualData.Unit                  = oVirtChan.Unit;
                        oVirtualData.Description           = oVirtChan.Comment;
                        oVirtualData.GraphicFormat         = CANStreamTools.Convert_CSSignalFormatToSerieValueFormat(oVirtChan.ValueFormat);
                        oVirtualData.ChannelReferenceLines = CANStreamTools.Convert_CSAlarmsToSerieReferenceLines(oVirtChan.Alarms);

                        foreach (SerieSample sCarrierSample in oCarrierChannel.Samples)
                        {
                            SerieSample sVirtSample = new SerieSample();

                            sVirtSample.SampleTime = sCarrierSample.SampleTime;

                            foreach (string ChanVar in oVirtChan.ChannelVariables)
                            {
                                VCLibraries.UpDateVariableElement(ChanVar, oConcatData.Get_ChannelValueAtTime(ChanVar, sVirtSample.SampleTime));
                            }

                            oVirtChan.ComputeChannelValue();

                            if (oVirtChan.bComputed && oVirtChan.bNewValue)
                            {
                                sVirtSample.SampleValue = oVirtChan.Value;
                                oVirtualData.Samples.Add(sVirtSample);

                                if (oVirtualData.Samples.Count == 1)
                                {
                                    oVirtualData.Min = sVirtSample.SampleValue;
                                    oVirtualData.Max = sVirtSample.SampleValue;
                                }
                                else
                                {
                                    if (sVirtSample.SampleValue < oVirtualData.Min)
                                    {
                                        oVirtualData.Min = sVirtSample.SampleValue;
                                    }
                                    if (sVirtSample.SampleValue > oVirtualData.Max)
                                    {
                                        oVirtualData.Max = sVirtSample.SampleValue;
                                    }
                                }
                            }
                        }

                        if (oVirtualData.Samples.Count > 1)
                        {
                            oConcatData.Channels.Add(oVirtualData);
                        }
                    }
                }
            }

            oDataFiles = null; //Free up memory
            return(oConcatData);
        }
Beispiel #7
0
        private GW_DataFile Concat_DataFiles(GW_DataFile[] oDataFiles)
        {
            bool bComputeVirtuals = false;

            if (oDataFiles == null)
            {
                return(null);
            }

            //Virtual channels libraries initialization
            if (!(VCLibraries == null))
            {
                VCLibraries.InitLibrariesComputation();
                bComputeVirtuals = true;
            }

            //Complete channel list creation
            List <string> ChannelList = new List <string>();

            foreach (GW_DataFile oFile in oDataFiles)
            {
                foreach (GW_DataChannel oChan in oFile.Channels)
                {
                    if (!(ChannelList.Contains(oChan.Name)))
                    {
                        ChannelList.Add(oChan.Name);
                    }
                }
            }

            //Concatened data file creation
            oConcatData = new GW_DataFile();
            foreach (string sChan in ChannelList)
            {
                GW_DataChannel oChan = new GW_DataChannel();
                oChan.Name = sChan;
                oConcatData.Channels.Add(oChan);
            }

            //Data file concatenation
            double Concat_T     = 0;
            bool   bFirstSample = true;

            foreach (GW_DataFile oFile in oDataFiles)
            {
                if (bFirstSample)
                {
                    oConcatData.StepTimeMin = oFile.StepTimeMin;
                    oConcatData.StepTimeMax = oFile.StepTimeMax;
                }
                else
                {
                    if (oFile.StepTimeMin < oConcatData.StepTimeMin)
                    {
                        oConcatData.StepTimeMin = oFile.StepTimeMin;
                    }
                    if (oFile.StepTimeMax > oConcatData.StepTimeMax)
                    {
                        oConcatData.StepTimeMax = oFile.StepTimeMax;
                    }
                }

                for (int iSample = 0; iSample < oFile.Time.Values.Count; iSample++)
                {
                    //Time value
                    if (!bFirstSample)                     //Not the first sample of the concatenated data file
                    {
                        if (!(iSample == 0))               //Not the first sample of the file
                        {
                            Concat_T += (oFile.Time.Values[iSample] - oFile.Time.Values[iSample - 1]);
                        }
                        else                         //First sample of the file
                        {
                            Concat_T += oFile.StepTimeMin;
                        }
                    }

                    oConcatData.Time.Add_ChannelValue(Concat_T);

                    //Data
                    foreach (string sChan in ChannelList)
                    {
                        GW_DataChannel oDataChan = oConcatData.Get_DataChannel(sChan);
                        GW_DataChannel oSrcChan  = oFile.Get_DataChannel(sChan);

                        if (!(oSrcChan == null))
                        {
                            oDataChan.Add_ChannelValue(oSrcChan.Values[iSample]);

                            if (bComputeVirtuals)
                            {
                                VCLibraries.UpDateVariableElement(oDataChan.Name, oSrcChan.Values[iSample]);
                            }
                        }
                        else
                        {
                            oDataChan.Values.Add(0);                             //Default value if channel is missing in the current data file

                            if (bComputeVirtuals)
                            {
                                VCLibraries.UpDateVariableElement(oDataChan.Name, 0);
                            }
                        }
                    }

                    //Virtual channels
                    if (bComputeVirtuals)
                    {
                        VCLibraries.ComputeLibraries();

                        foreach (CS_VirtualChannelsLibrary oLib in VCLibraries.Libraries)
                        {
                            foreach (CS_VirtualChannel oVirtual in oLib.Channels)
                            {
                                if (!(ChannelList.Contains(oVirtual.Name)))
                                {
                                    GW_DataChannel oVirtualDataChan = oConcatData.Get_DataChannel(oVirtual.Name);

                                    if (oVirtualDataChan == null && oVirtual.bNewValue)                                     //The virtual channel doesn't exist in the data file and it has a value
                                    {
                                        oVirtualDataChan = new GW_DataChannel(oVirtual.Name);

                                        if (oConcatData.DataChannelExists(oVirtual.Name))
                                        {
                                            oVirtualDataChan.Name = Name_VirtualChannel(oVirtual.Name);
                                        }

                                        oConcatData.Channels.Add(oVirtualDataChan);
                                    }

                                    if (!(oVirtualDataChan == null))
                                    {
                                        if (!(oVirtual.InError || double.IsNaN(oVirtual.Value)))
                                        {
                                            oVirtualDataChan.Add_ChannelValue(oVirtual.Value);
                                        }
                                        else
                                        {
                                            oVirtualDataChan.Add_ChannelValue(0);
                                        }
                                    }
                                }

                                oVirtual.bNewValue = false;
                            }
                        }
                    }

                    bFirstSample = false;
                }
            }

            oDataFiles = null;             //Free up memory
            return(oConcatData);
        }
Beispiel #8
0
        /// <summary>
        /// Converts the decoded PCAN trace file into a XML data file
        /// </summary>
        /// <param name="OutputFolder">Output file folder</param>
        /// <returns>Converion result (True: OK / False: Error)</returns>
        private bool WriteXmlRecordData(string OutputFolder)
        {
            if (Channels.Count == 0)
            {
                return(false);
            }

            GW_DataFile oDataFile = new GW_DataFile();

            oDataFile.DataSamplingMode = SamplingMode.MultipleRates;

            //Set data file properties
            oDataFile.DataStartTime = this.AbsDTStartTime;
            oDataFile.UserComment   = "Data file created "
                                      + DateTime.Now.ToShortDateString()
                                      + " "
                                      + DateTime.Now.ToShortTimeString();

            //Data file custom properties
            GW_XmlDataFileCustomProperty oCustProp;

            oCustProp               = new GW_XmlDataFileCustomProperty();
            oCustProp.Name          = "Base PCAN Trc file";
            oCustProp.PropertyValue = Path.GetFileName(this.BaseTrcFilePath);
            oDataFile.XmlDataFileCustomProperties.Add(oCustProp);

            oCustProp               = new GW_XmlDataFileCustomProperty();
            oCustProp.Name          = "Data decode CAN Configuration";
            oCustProp.PropertyValue = Path.GetFileName(this.oCanConfig.ConfigFilePath);
            oDataFile.XmlDataFileCustomProperties.Add(oCustProp);

            for (int i = 0; i < this.VCLibraries.Libraries.Count; i++)
            {
                oCustProp               = new GW_XmlDataFileCustomProperty();
                oCustProp.Name          = "Data decode virtual channels library #" + (i + 1).ToString();
                oCustProp.PropertyValue = Path.GetFileName(VCLibraries.Libraries[i].Name);
                oDataFile.XmlDataFileCustomProperties.Add(oCustProp);
            }

            //Set data channels
            foreach (RecordDataChannel oRecChan in Channels)
            {
                GW_DataChannel oDataChan = new GW_DataChannel(oRecChan.Name, SamplingMode.MultipleRates);

                //Channel properties
                CANParameter oCANSig = this.oCanConfig.GetCANParameter(oRecChan.Name);

                if (!(oCANSig == null)) //A CAN parameter has been found, GW_DataChannel properties will be filled using properties of the CAN Parameter
                {
                    oDataChan.Description           = oCANSig.Comment;
                    oDataChan.Unit                  = oCANSig.Unit;
                    oDataChan.GraphicFormat         = CANStreamTools.Convert_CSSignalFormatToSerieValueFormat(oCANSig.ValueFormat);
                    oDataChan.ChannelReferenceLines = CANStreamTools.Convert_CSAlarmsToSerieReferenceLines(oCANSig.Alarms);
                }
                else //No CAN parameter found, search among virtual channels
                {
                    CS_VirtualChannel oVirtual = null;

                    foreach (CS_VirtualChannelsLibrary oVirtLib in this.VCLibraries.Libraries)
                    {
                        oVirtual = oVirtLib.GetVirtualChannel(oRecChan.Name);

                        if (!(oVirtual == null))
                        {
                            break;
                        }
                    }

                    if (!(oVirtual == null)) //A virtual channel has been found, GW_DataChannel properties will be filled using properties of the virtual channel
                    {
                        oDataChan.Description           = oVirtual.Comment;
                        oDataChan.Unit                  = oVirtual.Unit;
                        oDataChan.GraphicFormat         = CANStreamTools.Convert_CSSignalFormatToSerieValueFormat(oVirtual.ValueFormat);
                        oDataChan.ChannelReferenceLines = CANStreamTools.Convert_CSAlarmsToSerieReferenceLines(oVirtual.Alarms);
                    }
                    else //No virtual channel found, GW_DataChannel will keeps its default properties values
                    {
                        //Nothing to do
                    }
                }

                //Channel samples value
                foreach (RecordDataSample oRecSample in oRecChan.Samples)
                {
                    SerieSample sDataSample = new SerieSample();

                    sDataSample.SampleTime  = oRecSample.TimeStamp / 1000;
                    sDataSample.SampleValue = oRecSample.SampleValue;

                    oDataChan.Samples.Add(sDataSample);
                }

                oDataFile.Channels.Add(oDataChan);
            }


            string OutFilePath = BuildOutputFilePtah(OutputFolder, RecordConversionFormat.Xml);

            oDataFile.Write_XmlDataFile(OutFilePath);

            return(true);
        }