/// <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); }
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); }
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); }