コード例 #1
0
        private void ShowTrcFiles()
        {
            LV_TrcFiles.Items.Clear();
            CANStreamTools.ResetTrcFileInfoEventSession();

            if (Directory.Exists(RecordsFolder))
            {
                DirectoryInfo RecDirInfo = new DirectoryInfo(RecordsFolder);

                TrcFilesInfos = CANStreamTools.GetTrcFileInfoList(RecDirInfo.FullName);

                if (!(TrcFilesInfos == null))
                {
                    for (int iTrc = 0; iTrc < TrcFilesInfos.Length; iTrc++)
                    {
                        PcanTrcFileInfo TrcInfo = TrcFilesInfos[iTrc];

                        ListViewItem TrcIt = LV_TrcFiles.Items.Add(TrcInfo.TrcFileInfo.Name);
                        TrcIt.Tag = iTrc;

                        if (!(TrcInfo.TrcFileEvent == null || TrcInfo.TrcFileSession == null))
                        {
                            ListViewGroup oEventSessionGroup = Get_EventSessionGroup(TrcInfo.TrcFileEvent.Name, TrcInfo.TrcFileSession.Name);

                            if (oEventSessionGroup == null)
                            {
                                oEventSessionGroup = LV_TrcFiles.Groups.Add(LV_TrcFiles.Groups.Count.ToString(), TrcInfo.TrcFileEvent.Name + " :: " + TrcInfo.TrcFileSession.Name);
                            }

                            TrcIt.Group = oEventSessionGroup;
                        }

                        TrcIt.SubItems.Add(TrcInfo.TrcFileInfo.LastWriteTime.ToShortDateString() + " " + TrcInfo.TrcFileInfo.LastWriteTime.ToShortTimeString());
                        TrcIt.SubItems.Add(CANStreamTools.GetScaledFileSize(TrcInfo.TrcFileInfo.Length));
                    }

                    LV_TrcFiles.Sort();
                }
            }
            else
            {
                MessageBox.Show("Records folder doesn't exist or is not available !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #2
0
        private void UpDate_FileList(string fPath, CS_RecordSession oSession, CS_RecordEvent oEvent)
        {
            ListViewGroup oSessionGrp = null;

            if (!(fPath.Equals("")))
            {
                DirectoryInfo oDirInfo = new DirectoryInfo(fPath);

                if (!(oSession == null))
                {
                    oSessionGrp = new ListViewGroup("Session: " + oSession.Name);
                    LV_Files.Groups.Add(oSessionGrp);
                }

                if (!(oDirInfo == null))
                {
                    FileInfo[] oDirFiles = oDirInfo.GetFiles();
                    LV_Files.Tag = fPath;

                    if (!(oDirFiles == null))
                    {
                        foreach (FileInfo oFile in oDirFiles)
                        {
                            int iIcone = 0;

                            if (oFile.Extension.Equals(".csv"))                             //Converted record file
                            {
                                iIcone = 2;
                            }
                            else if (oFile.Extension.Equals(".xrdf")) //XML Converted record file
                            {
                                iIcone = 4;
                            }
                            else if (oFile.Extension.Equals(".trc")) //Raw record file
                            {
                                iIcone = 3;
                            }

                            if (!(iIcone == 0))
                            {
                                ListViewItem ItFile = LV_Files.Items.Add(oFile.Name, iIcone);
                                ItFile.SubItems.Add(oFile.LastWriteTime.ToShortDateString() + " " + oFile.LastWriteTime.ToShortTimeString());
                                ItFile.SubItems.Add(CANStreamTools.GetScaledFileSize(oFile.Length));

                                object[] FileTag = new object[3];
                                FileTag[0] = oFile.FullName;
                                FileTag[1] = oSession;
                                FileTag[2] = oEvent;

                                ItFile.Tag = FileTag;

                                if (!(oSessionGrp == null))
                                {
                                    ItFile.Group = oSessionGrp;
                                }
                            }
                        }

                        Color_FileItems();

                        LV_Files.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                    }
                }
            }
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: RecordDataFile.cs プロジェクト: ywwjzsf/CANStream
        /// <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);
        }