Example #1
0
        /// <summary>
        /// Write the data cycle into a XML file
        /// </summary>
        /// <param name="FilePath">Name and path of file to be created</param>
        public void WriteStreamCycle(string FilePath)
        {
            XmlDocument oXmlCycle = new XmlDocument();

            XmlElement nCycle = oXmlCycle.CreateElement("CANStreamCycle");

            oXmlCycle.AppendChild(nCycle);

            XmlElement nHeader = oXmlCycle.CreateElement("Header");

            nCycle.AppendChild(nHeader);

            XmlElement nName = oXmlCycle.CreateElement("CycleName");

            nName.InnerText = Name;
            nHeader.AppendChild(nName);

            XmlElement nComment = oXmlCycle.CreateElement("Comment");

            nComment.InnerText = Comment;
            nHeader.AppendChild(nComment);

            XmlElement nCanMap = oCanNodesMap.CreateCANConfigurationXmlNode(oXmlCycle, "CANConfiguration");

            nCycle.AppendChild(nCanMap);

            XmlElement nEvents = oXmlCycle.CreateElement("TimeEvents");

            nCycle.AppendChild(nEvents);

            foreach (CycleTimeEvent oEvent in TimeEvents)
            {
                XmlElement nSingleEvent = oXmlCycle.CreateElement("Event");

                XmlAttribute nAtrTime = oXmlCycle.CreateAttribute("TimeValue");
                nAtrTime.Value = oEvent.TimeEvent.ToString();
                nSingleEvent.Attributes.Append(nAtrTime);

                foreach (CANMessageData oMessage in oEvent.MessagesData)
                {
                    XmlElement nMessage = oXmlCycle.CreateElement("MessageData");

                    XmlAttribute nAtrMsgId = oXmlCycle.CreateAttribute("Identifier");
                    nAtrMsgId.Value = oMessage.uMessageId.ToString();
                    nMessage.Attributes.Append(nAtrMsgId);

                    for (int iByte = 0; iByte < oMessage.byteMessageData.Length; iByte++)
                    {
                        XmlElement nByte = oXmlCycle.CreateElement("Byte");

                        XmlAttribute nAtrByteId = oXmlCycle.CreateAttribute("ByteIndex");
                        nAtrByteId.Value = (oMessage.byteMessageData.Length - 1 - iByte).ToString();
                        nByte.Attributes.Append(nAtrByteId);

                        nByte.InnerText = oMessage.byteMessageData[iByte].ToString();
                        nMessage.AppendChild(nByte);
                    }

                    nSingleEvent.AppendChild(nMessage);
                }

                nEvents.AppendChild(nSingleEvent);
            }

            oXmlCycle.Save(FilePath);
        }
Example #2
0
        /// <summary>
        /// Save the cycle configuration in a XML file
        /// </summary>
        /// <param name="fPath">Path of destination file</param>
        public void Save_CycleConfiguration(string fPath)
        {
            if (!(fPath.Equals("")))
            {
                XmlDocument oCycleConfig = new XmlDocument();

                //Root node
                XmlElement xCycleCfg = oCycleConfig.CreateElement("CycleConfiguration");
                oCycleConfig.AppendChild(xCycleCfg);

                //CAN Message configuration
                XmlElement xCanCfg = null;

                if (!(CanConfiguration == null))
                {
                    xCanCfg = CanConfiguration.CreateCANConfigurationXmlNode(oCycleConfig, "CANConfiguration");
                }
                else
                {
                    xCanCfg = oCycleConfig.CreateElement("CANConfiguration");
                }

                xCycleCfg.AppendChild(xCanCfg);

                //Virtual channels libraries
                if (!(VirtualChannelLibCollection == null))
                {
                    foreach (CS_VirtualChannelsLibrary oLib in VirtualChannelLibCollection.Libraries)
                    {
                        XmlElement xVirtualLib = oCycleConfig.CreateElement("CS_VirtualChannelsLibrary");
                        xCycleCfg.AppendChild(xVirtualLib);
                        oLib.CreateLibraryXmlNode(oCycleConfig);
                    }
                }

                //Built-In signals libraries
                if (!(BuiltInSignalLibCollection == null))
                {
                    foreach (CS_BuiltInSignalLibrary oLib in BuiltInSignalLibCollection.Libraries)
                    {
                        XmlElement xSignalLib = oCycleConfig.CreateElement("CS_BuiltInSignalsLibrary");
                        xCycleCfg.AppendChild(xSignalLib);
                        oLib.CreateLibraryXmlNode(oCycleConfig);
                    }
                }

                //Cycle parts properties
                XmlElement xPartProps = oCycleConfig.CreateElement("CyclePartsProperties");
                xCycleCfg.AppendChild(xPartProps);

                XmlAttribute xAtrLen, xAtrDataFile;

                //Pre-cycle
                XmlElement xPreCycleProps = oCycleConfig.CreateElement("PreCycleProperties");

                xAtrLen       = oCycleConfig.CreateAttribute("TimeLength");
                xAtrLen.Value = PreCycleProperties.TimeLength.ToString();
                xPreCycleProps.Attributes.Append(xAtrLen);

                xAtrDataFile       = oCycleConfig.CreateAttribute("DataFile");
                xAtrDataFile.Value = PreCycleProperties.DataFile;
                xPreCycleProps.Attributes.Append(xAtrDataFile);

                xPartProps.AppendChild(xPreCycleProps);

                //In-cycle
                XmlElement xInCycleProps = oCycleConfig.CreateElement("InCycleProperties");

                xAtrLen       = oCycleConfig.CreateAttribute("TimeLength");
                xAtrLen.Value = InCycleProperties.TimeLength.ToString();
                xInCycleProps.Attributes.Append(xAtrLen);

                xAtrDataFile       = oCycleConfig.CreateAttribute("DataFile");
                xAtrDataFile.Value = InCycleProperties.DataFile;
                xInCycleProps.Attributes.Append(xAtrDataFile);

                xPartProps.AppendChild(xInCycleProps);

                //Post-cycle
                XmlElement xPostCycleProps = oCycleConfig.CreateElement("PostCycleProperties");

                xAtrLen       = oCycleConfig.CreateAttribute("TimeLength");
                xAtrLen.Value = PostCycleProperties.TimeLength.ToString();
                xPostCycleProps.Attributes.Append(xAtrLen);

                xAtrDataFile       = oCycleConfig.CreateAttribute("DataFile");
                xAtrDataFile.Value = PostCycleProperties.DataFile;
                xPostCycleProps.Attributes.Append(xAtrDataFile);

                xPartProps.AppendChild(xPostCycleProps);

                //Cycle parameters
                XmlElement xCycleParameters = oCycleConfig.CreateElement("CycleParameters");
                xCycleCfg.AppendChild(xCycleParameters);

                foreach (CycleParameter oCycleParam in Parameters)
                {
                    XmlAttribute xAtrSrc, xAtrData, xAtrLib;

                    //Parameter properties
                    XmlElement xParam = oCycleConfig.CreateElement("Parameter");

                    XmlAttribute xAtrName = oCycleConfig.CreateAttribute("Name");
                    xAtrName.Value = oCycleParam.Name;
                    xParam.Attributes.Append(xAtrName);

                    XmlAttribute xAtrMsg = oCycleConfig.CreateAttribute("MessageId");
                    xAtrMsg.Value = oCycleParam.MsgId;
                    xParam.Attributes.Append(xAtrMsg);

                    //Paramter Pre-Cycle data properties
                    XmlElement xPreCycleData = oCycleConfig.CreateElement("PreCycleData");
                    xParam.AppendChild(xPreCycleData);

                    xAtrSrc       = oCycleConfig.CreateAttribute("Source");
                    xAtrSrc.Value = oCycleParam.PreCycle.Source.ToString();
                    xPreCycleData.Attributes.Append(xAtrSrc);

                    xAtrData       = oCycleConfig.CreateAttribute("Data");
                    xAtrData.Value = oCycleParam.PreCycle.Data;
                    xPreCycleData.Attributes.Append(xAtrData);

                    xAtrLib       = oCycleConfig.CreateAttribute("Library");
                    xAtrLib.Value = oCycleParam.PreCycle.Library;
                    xPreCycleData.Attributes.Append(xAtrLib);

                    //Paramter In-Cycle data properties
                    XmlElement xInCycleData = oCycleConfig.CreateElement("InCycleData");
                    xParam.AppendChild(xInCycleData);

                    xAtrSrc       = oCycleConfig.CreateAttribute("Source");
                    xAtrSrc.Value = oCycleParam.InCycle.Source.ToString();
                    xInCycleData.Attributes.Append(xAtrSrc);

                    xAtrData       = oCycleConfig.CreateAttribute("Data");
                    xAtrData.Value = oCycleParam.InCycle.Data;
                    xInCycleData.Attributes.Append(xAtrData);

                    xAtrLib       = oCycleConfig.CreateAttribute("Library");
                    xAtrLib.Value = oCycleParam.InCycle.Library;
                    xInCycleData.Attributes.Append(xAtrLib);

                    //Paramter Post-Cycle data properties
                    XmlElement xPostCycleData = oCycleConfig.CreateElement("PostCycleData");
                    xParam.AppendChild(xPostCycleData);

                    xAtrSrc       = oCycleConfig.CreateAttribute("Source");
                    xAtrSrc.Value = oCycleParam.PostCycle.Source.ToString();
                    xPostCycleData.Attributes.Append(xAtrSrc);

                    xAtrData       = oCycleConfig.CreateAttribute("Data");
                    xAtrData.Value = oCycleParam.PostCycle.Data;
                    xPostCycleData.Attributes.Append(xAtrData);

                    xAtrLib       = oCycleConfig.CreateAttribute("Library");
                    xAtrLib.Value = oCycleParam.PostCycle.Library;
                    xPostCycleData.Attributes.Append(xAtrLib);

                    xCycleParameters.AppendChild(xParam);
                }

                oCycleConfig.Save(fPath);
                FilePath  = fPath;
                bModified = false;
            }
        }