/// <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 CANMessageData BuildCANMessageData(string MsgIdentifier, long TimeValue) { CANMessage oMsgDef = oCanConfig.GetCANMessage(MsgIdentifier, MessageResearchOption.Identifier); //Get engeneering value for each parameter of the message foreach (CANParameter oParamDef in oMsgDef.Parameters) { DataAssociation oParamAssociation = oAssociations.GetAssociation(MsgIdentifier, oParamDef.Name); double DataValue = 0; //Retrieve formated value if (!(oParamAssociation == null)) { switch (oParamAssociation.AssociationType) { case CS_DataAssociationType.AcqData: if (!(oDataFile.GetValueAtTime(oParamAssociation.DataColumnTitle, TimeValue, out DataValue))) { return(null); } break; case CS_DataAssociationType.BuiltSignal: DataValue = oSignalLibCollection.GetSignalValueAtTime(oParamAssociation.SignalLibrary, oParamAssociation.SignalName, TimeValue); break; case CS_DataAssociationType.FixedValue: DataValue = oParamAssociation.DefaultValue; break; default: DataValue = 0; break; } } else { if (TimeValue == 0) { DialogResult Rep = MessageBox.Show("No association found for CAN parameter " + oParamDef.Name + " of message ID " + MsgIdentifier + "\nDo you want to continue cycle creation anyway ?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (Rep.Equals(DialogResult.No)) { MessageBox.Show("Cycle creation abort !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return(null); } } } oParamDef.DecodedValue = DataValue; } //Encode the message CANMessageEncoded oMsgEncoded = new CANMessageEncoded(oMsgDef); oMsgEncoded.EncodeMessage(); return(oMsgEncoded.GetCANMessageData()); }
/// <summary> /// Decodes the PCAN trace file CAN messages in raw format into the engineering format according to the specified CAN Configuration /// </summary> /// <returns>Decoding result (True: OK / False: Error)</returns> private bool DecodeTrcFile() { bool bComputeVirtuals = false; long iRecord = 0; if (!(VCLibraries == null)) { VCLibraries.InitLibrariesComputation(); bComputeVirtuals = true; } foreach (TraceRecord Record in Records) { iRecord++; if (oCanConfig.IsUsedIdentifier(Record.MessageIdentifier)) { CANMessage oMessage = oCanConfig.GetCANMessage(Record.MessageIdentifier, MessageResearchOption.Identifier); if (!(oMessage == null)) { CANMessageDecoded oMsgDecoded = new CANMessageDecoded(oMessage, Record); if (oMsgDecoded.bMessageDecoded) { foreach (CANParameter oParam in oMsgDecoded.Parameters) { AddDataSample(oParam.Name, Record.TimeOffset, oParam.DecodedValue); if (bComputeVirtuals) { VCLibraries.UpDateVariableElement(oParam.Name, oParam.DecodedValue); } } if (bComputeVirtuals) { VCLibraries.ComputeLibraries(); foreach (CS_VirtualChannelsLibrary oLib in VCLibraries.Libraries) { foreach (CS_VirtualChannel oVirtual in oLib.Channels) { if (oVirtual.bComputed && (oVirtual.bNewValue | iRecord == Records.Count)) //Virtual channel computation for the last record in order to have value until the end { oVirtual.bNewValue = false; if (!oVirtual.InError) { if (!Double.IsNaN(oVirtual.Value)) { AddDataSample(oVirtual.Name, Record.TimeOffset, oVirtual.Value); } } } } } } } } } } return(true); }