/// <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); }
/// <summary> /// Convert the DBC object into a CANStream CAN configuration object /// </summary> /// <param name="Rate">CAN bus Baud rate</param> /// <param name="CanNodeName">CAN device name</param> /// <returns>CANStream CAN configuration object of the DBC</returns> public CANMessagesConfiguration Convert_DBC_to_XCC(int Rate, string CanNodeName) { CANMessagesConfiguration oXCC = new CANMessagesConfiguration(); //Bus Baud rate oXCC.CanRate = Rate; //Config name oXCC.Name = "DBC:"; if (!(BusComponents == null)) { for (int i = 0; i < BusComponents.Length; i++) { oXCC.Name = oXCC.Name + " " + BusComponents[i]; } } foreach (DBCFrame oFrame in Frames) { CANMessage oCSMsg = new CANMessage(); oCSMsg.Identifier = NumberBaseConverter.Dec2Hex(oFrame.Identifier); oCSMsg.DLC = oFrame.ByteLength; oCSMsg.Name = oFrame.Name; oCSMsg.Comment = oFrame.GetNodeComments(); oCSMsg.Period = 1000; //Default value //oCSMsg.RxTx=CanMsgRxTx.Tx; //Default value if (oFrame.Transmitter.Equals(CanNodeName)) { oCSMsg.RxTx = CanMsgRxTx.Tx; } else { oCSMsg.RxTx = CanMsgRxTx.Rx; } oCSMsg.MultiplexerName = oFrame.GetMultiplexerSignalName(); foreach (DBCSignal oSignal in oFrame.Signals) { if ((oCSMsg.RxTx.Equals(CanMsgRxTx.Tx)) || (oCSMsg.RxTx.Equals(CanMsgRxTx.Rx) && oSignal.Destination.Equals(CanNodeName))) { CANParameter oCSParam = new CANParameter(); oCSParam.Name = oSignal.Name; oCSParam.Comment = oSignal.GetSignalComments(); oCSParam.Unit = oSignal.Unit; oCSParam.StartBit = oSignal.StartBit; oCSParam.Length = oSignal.Length; oCSParam.Endianess = (CanParameterEndianess)Enum.Parse(typeof(CanParameterEndianess), oSignal.Endianess.ToString()); oCSParam.Signed = oSignal.Signed; oCSParam.Gain = oSignal.Gain; oCSParam.Zero = oSignal.Zero; if (!(oSignal.Multiplexer == null)) { if (!(oSignal.Multiplexer.IsMultiplexerSignal)) { oCSParam.IsMultiplexed = true; oCSParam.MultiplexerValue = oSignal.Multiplexer.MultiplexerValue; } } oCSMsg.Parameters.Add(oCSParam); } } if (oCSMsg.Parameters.Count > 0) { oXCC.Messages.Add(oCSMsg); } } return(oXCC); }