示例#1
0
        public Frm_VirtualChannelTest(Frm_VirtualChannel FrmParent, CS_VirtualChannel TestChannel)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            FormParent    = FrmParent;
            bExprModified = false;

            if (!(TestChannel == null))
            {
                oChannel          = TestChannel;
                ChannelRefLibName = oChannel.ParentLibrary.Name;

                oTestLibrary           = new CS_VirtualChannelsLibrary();
                oChannel.ParentLibrary = oTestLibrary;
                oTestLibrary.Channels.Add(oChannel);

                oTestLibCollection = new CS_VCLibrariesCollection();
                oTestLibCollection.AddLibrary(oTestLibrary);
            }
        }
示例#2
0
        /// <summary>
        /// Read the cycle configuration in a XML file
        /// </summary>
        /// <param name="fPath">Path of the file to read</param>
        /// <returns>Reading error flag: True = No Error / False = Error</returns>
        public bool Read_CycleConfiguration(string fPath)
        {
            if (!(fPath.Equals("")))
            {
                XmlDocument oCycleConfig = new XmlDocument();
                oCycleConfig.Load(fPath);

                XmlNode xCycleCfg = oCycleConfig.SelectSingleNode("CycleConfiguration");

                if (!(xCycleCfg == null))
                {
                    //CAN Configuration
                    XmlNode xCanCfg = xCycleCfg.SelectSingleNode("CANConfiguration");

                    if (!(xCanCfg == null))
                    {
                        CanConfiguration = new CANMessagesConfiguration();

                        if (!(CanConfiguration.ReadCANConfigurationXmlNode(xCanCfg)))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);                         //Node CANConfiguration not found
                    }

                    //Virtual channels libraries
                    XmlNode xVirtualLib = xCanCfg.NextSibling;

                    if (xVirtualLib.Name.Equals("CS_VirtualChannelsLibrary"))
                    {
                        VirtualChannelLibCollection = new CS_VCLibrariesCollection();

                        while (xVirtualLib.Name.Equals("CS_VirtualChannelsLibrary"))
                        {
                            CS_VirtualChannelsLibrary oLib = new CS_VirtualChannelsLibrary();
                            oLib.ReadLibraryXmlNode(xVirtualLib);
                            VirtualChannelLibCollection.AddLibrary(oLib);

                            xVirtualLib = xVirtualLib.NextSibling;
                        }
                    }

                    //Built-In signals libraries
                    XmlNode xSignalLib = xVirtualLib;

                    if (xSignalLib.Name.Equals("CS_BuiltInSignalsLibrary"))
                    {
                        BuiltInSignalLibCollection = new CS_BuiltInSignalLibCollection();

                        while (xSignalLib.Name.Equals("CS_BuiltInSignalsLibrary"))
                        {
                            CS_BuiltInSignalLibrary oLib = new CS_BuiltInSignalLibrary();
                            oLib.ReadLibraryXmlNode(xSignalLib);
                            BuiltInSignalLibCollection.AddLibrary(oLib);

                            xSignalLib = xSignalLib.NextSibling;
                        }
                    }

                    //Cycle parts properties
                    XmlNode xPartProps = xCycleCfg.SelectSingleNode("CyclePartsProperties");
                    if (!(xPartProps == null))
                    {
                        //Pre-cycle
                        XmlNode xPreCycleProps = xPartProps.SelectSingleNode("PreCycleProperties");
                        if (!(xPreCycleProps == null))
                        {
                            XmlAttribute xAtr;

                            xAtr = xPreCycleProps.Attributes["TimeLength"];
                            if (!(xAtr == null))
                            {
                                double t = 0;
                                if (double.TryParse(xAtr.Value, out t))
                                {
                                    PreCycleProperties.TimeLength = t;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute TimeLength is not a number
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute TimeLength not found in node PreCycleProperties
                            }

                            xAtr = xPreCycleProps.Attributes["DataFile"];
                            if (!(xAtr == null))
                            {
                                PreCycleProperties.DataFile = xAtr.Value;
                            }
                            else
                            {
                                return(false);                                 //Attribute DataFile not found in node PreCycleProperties
                            }
                        }
                        else
                        {
                            return(false);                             //Node PreCycleProperties not found
                        }

                        //In-Cycle
                        XmlNode xInCycleProps = xPartProps.SelectSingleNode("InCycleProperties");
                        if (!(xInCycleProps == null))
                        {
                            XmlAttribute xAtr;

                            xAtr = xInCycleProps.Attributes["TimeLength"];
                            if (!(xAtr == null))
                            {
                                double t = 0;
                                if (double.TryParse(xAtr.Value, out t))
                                {
                                    InCycleProperties.TimeLength = t;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute TimeLength is not a number
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute TimeLength not found in node InCycleProperties
                            }

                            xAtr = xInCycleProps.Attributes["DataFile"];
                            if (!(xAtr == null))
                            {
                                InCycleProperties.DataFile = xAtr.Value;
                            }
                            else
                            {
                                return(false);                                 //Attribute DataFile not found in node InCycleProperties
                            }
                        }
                        else
                        {
                            return(false);                             //Node InCycleProperties not found
                        }

                        //Post-Cycle
                        XmlNode xPostCycleProps = xPartProps.SelectSingleNode("PostCycleProperties");
                        if (!(xPostCycleProps == null))
                        {
                            XmlAttribute xAtr;

                            xAtr = xPostCycleProps.Attributes["TimeLength"];
                            if (!(xAtr == null))
                            {
                                double t = 0;
                                if (double.TryParse(xAtr.Value, out t))
                                {
                                    PostCycleProperties.TimeLength = t;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute TimeLength is not a number
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute TimeLength not found in node PostCycleProperties
                            }

                            xAtr = xPostCycleProps.Attributes["DataFile"];
                            if (!(xAtr == null))
                            {
                                PostCycleProperties.DataFile = xAtr.Value;
                            }
                            else
                            {
                                return(false);                                 //Attribute DataFile not found in node PostCycleProperties
                            }
                        }
                        else
                        {
                            return(false);                             //Node PostCycleProperties not found
                        }
                    }
                    else
                    {
                        return(false);                         //Node CyclePartsProperties not found
                    }

                    //Cycle parameters
                    XmlNode xCycleParams = xCycleCfg.SelectSingleNode("CycleParameters");
                    if (!(xCycleParams == null))
                    {
                        Parameters = new List <CycleParameter>();

                        foreach (XmlNode xParam in xCycleParams.ChildNodes)
                        {
                            CycleParameter oParam = new CycleParameter();

                            XmlAttribute xAtr;
                            XmlNode      xData;

                            //Parameter Name
                            xAtr = xParam.Attributes["Name"];
                            if (!(xAtr == null))
                            {
                                if (!(xAtr.Value.Equals("")))
                                {
                                    oParam.Name = xAtr.Value;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute Name is empty
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute Name not found in node xParam
                            }

                            //Parameter Message Id
                            xAtr = xParam.Attributes["MessageId"];
                            if (!(xAtr == null))
                            {
                                if (!(xAtr.Value.Equals("")))
                                {
                                    oParam.MsgId = xAtr.Value;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute MessageId is empty
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute MessageId not found in node xParam
                            }

                            //Pre-Cycle data
                            xData = xParam.SelectSingleNode("PreCycleData");
                            if (!(xData == null))
                            {
                                //Source
                                xAtr = xData.Attributes["Source"];
                                if (!(xAtr == null))
                                {
                                    CycleDataSource Src = CycleDataSource.None;

                                    if (Enum.TryParse(xAtr.Value, out Src))
                                    {
                                        oParam.PreCycle.Source = Src;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Source is not part of enumeration
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Source not found in node PreCycleData
                                }

                                //Data
                                xAtr = xData.Attributes["Data"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PreCycle.Data = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Data is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Data not found in node PreCycleData
                                }

                                //Library
                                xAtr = xData.Attributes["Library"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PreCycle.Library = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Library is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Library not found in node PreCycleData
                                }
                            }
                            else
                            {
                                return(false);                                 //Node PreCycleData not found
                            }

                            //In-cycle data
                            xData = xParam.SelectSingleNode("InCycleData");
                            if (!(xData == null))
                            {
                                //Source
                                xAtr = xData.Attributes["Source"];
                                if (!(xAtr == null))
                                {
                                    CycleDataSource Src = CycleDataSource.None;

                                    if (Enum.TryParse(xAtr.Value, out Src))
                                    {
                                        oParam.InCycle.Source = Src;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Source is not part of enumeration
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Source not found in node InCycleData
                                }

                                //Data
                                xAtr = xData.Attributes["Data"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.InCycle.Data = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Data is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Data not found in node InCycleData
                                }

                                //Library
                                xAtr = xData.Attributes["Library"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.InCycle.Library = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Library is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Library not found in node InCycleData
                                }
                            }
                            else
                            {
                                return(false);                                 //Node InCycleData not found
                            }

                            xData = xParam.SelectSingleNode("PostCycleData");
                            if (!(xData == null))
                            {
                                //Source
                                xAtr = xData.Attributes["Source"];
                                if (!(xAtr == null))
                                {
                                    CycleDataSource Src = CycleDataSource.None;

                                    if (Enum.TryParse(xAtr.Value, out Src))
                                    {
                                        oParam.PostCycle.Source = Src;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Source is not part of enumeration
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Source not found in node PostCycleData
                                }

                                //Data
                                xAtr = xData.Attributes["Data"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PostCycle.Data = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Data is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Data not found in node PostCycleData
                                }

                                //Library
                                xAtr = xData.Attributes["Library"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PostCycle.Library = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Library is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Library not found in node PostCycleData
                                }
                            }
                            else
                            {
                                return(false);                                 //Node PostCycleData not found
                            }

                            Parameters.Add(oParam);
                        }
                    }
                    else
                    {
                        return(false);                         //Node CycleParameters not found
                    }
                }
                else
                {
                    return(false);                     //Node CycleConfiguration not found
                }
            }
            else
            {
                return(false);                 //Path empty
            }

            FilePath  = fPath;
            bModified = false;
            return(true);             //No Error
        }