/// <summary> /// Read CycleDataAssociation file /// </summary> /// <param name="FilePath">Path of the file to read</param> /// <returns>Reading error flag: True = No Error / False = Error</returns> public bool ReadCycleDataAssociation(string FilePath) { XmlDocument oXmlAssociation = new XmlDocument(); oXmlAssociation.Load(FilePath); XmlNode xAssociations = oXmlAssociation.FirstChild; if (xAssociations.Name.Equals("CycleDataAssociation")) { XmlNode xCanConfig = xAssociations.SelectSingleNode("CANConfigFile"); if (!(xCanConfig == null)) { CANConfigFile = xCanConfig.InnerText; } XmlNode xDataFile = xAssociations.SelectSingleNode("DataFileTemplate"); if (!(xDataFile == null)) { DataFileTemplate = xDataFile.InnerText; } XmlNode xAssociationCollection = xAssociations.SelectSingleNode("Associations"); if (!(xAssociationCollection == null)) { Associations = new List <DataAssociation>(); foreach (XmlNode xAssociation in xAssociationCollection.ChildNodes) { if (xAssociation.Name.Equals("Association")) { DataAssociation oAssociation = new DataAssociation(); //CAN Parameter name XmlNode xCANParam = xAssociation.SelectSingleNode("CANParameterName"); if (!(xCANParam == null)) { oAssociation.CANParameterName = xCANParam.InnerText; } else { return(false); } //CAN Parameter message identifier XmlNode xCANParamMsgId = xAssociation.SelectSingleNode("CANParameterMessageIdentifier"); if (!(xCANParamMsgId == null)) { oAssociation.CANParameterMessageIdentifier = xCANParamMsgId.InnerText; } else { return(false); } //Data column title XmlNode xColumnTitle = xAssociation.SelectSingleNode("DataColumnTitle"); if (!(xColumnTitle == null)) { oAssociation.DataColumnTitle = xColumnTitle.InnerText; } else { return(false); } //Default value XmlNode xDefaultValue = xAssociation.SelectSingleNode("DefaultValue"); if (!(xDefaultValue == null)) { double DefaultValue = 0; if (Double.TryParse(xDefaultValue.InnerText, out DefaultValue)) { oAssociation.DefaultValue = DefaultValue; } else { return(false); } } else { return(false); } XmlNode xAssociationType = xAssociation.SelectSingleNode("AssociationType"); CS_DataAssociationType eAsso = CS_DataAssociationType.None; if (Enum.TryParse(xAssociationType.InnerText, out eAsso)) { oAssociation.AssociationType = eAsso; } else { return(false); } XmlNode xSigLib = xAssociation.SelectSingleNode("BuiltInSignal_Library"); if (!(xSigLib == null)) { oAssociation.SignalLibrary = xSigLib.InnerText; } else { return(false); } XmlNode xSigName = xAssociation.SelectSingleNode("BuiltInSignal_Name"); if (!(xSigName == null)) { oAssociation.SignalName = xSigName.InnerText; } else { return(false); } Associations.Add(oAssociation); } } } else { return(false); } } else { return(false); } return(true); }
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()); }
private void SaveAssociationConfiguration() { if (Grid_Association.Rows.Count == 0) { return; } if (CheckAssociationConfiguration()) { saveFileDialog1.FileName = ""; saveFileDialog1.Filter = "Cycle Data Association|*.cda"; saveFileDialog1.InitialDirectory = CANStreamTools.MyDocumentPath + "\\CANStream\\Cycle Data Association"; if (saveFileDialog1.ShowDialog().Equals(DialogResult.OK)) { oAssociations = new CycleDataAssociation(); oAssociations.CANConfigFile = Txt_CANConfig.Text; oAssociations.DataFileTemplate = Txt_DataFile.Text; for (int iRow = 0; iRow < Grid_Association.Rows.Count; iRow++) { DataAssociation oAsso = new DataAssociation(); DataGridViewTextBoxCell CanParam = (DataGridViewTextBoxCell)Grid_Association.Rows[iRow].Cells[0]; DataGridViewComboBoxCell TypeAssociation = (DataGridViewComboBoxCell)Grid_Association.Rows[iRow].Cells[1]; DataGridViewComboBoxCell ChannelCell = (DataGridViewComboBoxCell)Grid_Association.Rows[iRow].Cells[2]; DataGridViewComboBoxCell SignalCell = (DataGridViewComboBoxCell)Grid_Association.Rows[iRow].Cells[3]; DataGridViewTextBoxCell DefaultValCell = (DataGridViewTextBoxCell)Grid_Association.Rows[iRow].Cells[4]; oAsso.CANParameterName = CanParam.Value.ToString(); oAsso.CANParameterMessageIdentifier = Grid_Association.Rows[iRow].HeaderCell.Value.ToString(); oAsso.AssociationType = (CS_DataAssociationType)Enum.Parse(typeof(CS_DataAssociationType), TypeAssociation.EditedFormattedValue.ToString()); switch (oAsso.AssociationType) { case CS_DataAssociationType.AcqData: oAsso.DataColumnTitle = ChannelCell.EditedFormattedValue.ToString(); oAsso.SignalName = ""; oAsso.SignalLibrary = ""; oAsso.DefaultValue = 0; break; case CS_DataAssociationType.BuiltSignal: string[] SignalProps = SignalCell.EditedFormattedValue.ToString().Split(':'); oAsso.DataColumnTitle = ""; oAsso.SignalName = SignalProps[1]; oAsso.SignalLibrary = SignalProps[0]; oAsso.DefaultValue = Convert.ToDouble(DefaultValCell.Value);; break; case CS_DataAssociationType.FixedValue: oAsso.DataColumnTitle = ""; oAsso.SignalName = ""; oAsso.SignalLibrary = ""; oAsso.DefaultValue = Convert.ToDouble(DefaultValCell.Value); break; default: oAsso.DataColumnTitle = ""; oAsso.SignalName = ""; oAsso.SignalLibrary = ""; oAsso.DefaultValue = 0; break; } #region Old version /* * DataGridViewTextBoxCell CanParam = (DataGridViewTextBoxCell)Grid_Association.Rows[iRow].Cells[0]; * DataGridViewComboBoxCell ChannelCell = (DataGridViewComboBoxCell)Grid_Association.Rows[iRow].Cells[1]; * DataGridViewCheckBoxCell UseDefaultCell = (DataGridViewCheckBoxCell)Grid_Association.Rows[iRow].Cells[2]; * DataGridViewTextBoxCell DefaultValCell = (DataGridViewTextBoxCell)Grid_Association.Rows[iRow].Cells[3]; * * oAsso.CANParameterName = CanParam.Value.ToString(); * oAsso.CANParameterMessageIdentifier = Grid_Association.Rows[iRow].HeaderCell.Value.ToString(); * oAsso.DataColumnTitle = ChannelCell.EditedFormattedValue.ToString(); * oAsso.UseDefaultValue = (bool)UseDefaultCell.EditedFormattedValue; * * if (!(DefaultValCell.Value == null)) * { * oAsso.DefaultValue = Convert.ToDouble(DefaultValCell.Value); * } * else * { * oAsso.DefaultValue = 0; * } */ #endregion oAssociations.Associations.Add(oAsso); } oAssociations.WriteCycleDataAssociation(saveFileDialog1.FileName); ConfigModified = false; MessageBox.Show("Association saved !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }