Beispiel #1
0
 public InSignal(int port, string name, string path, HiCoreClient hiCore)
 {
     _hiCore     = hiCore;
     _portNumber = port;
     _portName   = name;
     _pDll       = DllMethods.LoadLibrary(path);
 }
 public OutSignal(int port, string name, string path, HiCoreClient hiCore, string channelName)
 {
     _hiCore      = hiCore;
     _portNumber  = port;
     _portName    = name;
     _pDll        = DllMethods.LoadLibrary(path);
     _channelName = channelName;
 }
        public SimulinkModel(string path, HiCoreClient hicore, XmlHelper xmlHelper)
        {
            _hiCore        = hicore;
            _pDll          = DllMethods.LoadLibrary(path);
            _path          = path;
            _directoryPath = Path.GetDirectoryName(path);
            _name          = new DirectoryInfo(_directoryPath).Name;

            Initialze();
            ReadXml();
        }
        public SimulinkModel(string path, HiCoreClient hicore, List <ISignal> inSignals, List <ISignal> outSignals)
        {
            _hiCore        = hicore;
            _pDll          = DllMethods.LoadLibrary(path);
            _path          = path;
            _directoryPath = Path.GetDirectoryName(path);
            _name          = new DirectoryInfo(_directoryPath).Name;

            Initialze();
            _inSignals  = inSignals;
            _outSignals = outSignals;
        }
        public List <SimulinkModel> LoadProject(string fileName, HiCoreClient hicore)
        {
            List <SimulinkModel> models = new List <SimulinkModel>();

            XmlTextReader reader = new XmlTextReader(fileName);
            //reader.Read();
            string         path           = "";
            string         modelName      = "";
            List <ISignal> inSignals      = new List <ISignal>();
            List <ISignal> outSignals     = new List <ISignal>();
            bool           IsFirstElement = true;

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    if (IsFirstElement)
                    {
                        if (reader.Name == "ProjectFile")
                        {
                            IsFirstElement = false;
                        }
                        else
                        {
                            OnMessageReadingXml("Could not load project, invalid xml file.");
                            return(null);
                        }
                    }
                    if (reader.Name == "Model" && modelName != "")
                    {
                        SimulinkModel m = new SimulinkModel(path, hicore, inSignals, outSignals);
                        models.Add(m);
                        inSignals  = new List <ISignal>();
                        outSignals = new List <ISignal>();
                    }
                    if (reader.Name == "ModelName")
                    {
                        modelName = reader.ReadString();
                    }
                    if (reader.Name == "Path")
                    {
                        path = reader.ReadString();
                    }
                    if (reader.IsStartElement())
                    {
                        if (reader.Name == "InSignal")
                        {
                            reader.Read();
                            string signalName = "";
                            if (reader.Name == "Name")
                            {
                                signalName = reader.ReadString();
                            }

                            reader.Read();
                            int port = -1;
                            if (reader.Name == "Port")
                            {
                                port = Convert.ToInt32(reader.ReadString());
                            }
                            reader.Read();
                            string channelName = "";
                            if (reader.Name == "ChannelName")
                            {
                                channelName = reader.ReadString();
                            }
                            InSignal inSignal = new InSignal(port, signalName, path, hicore, channelName);
                            inSignals.Add(inSignal);
                        }
                        else if (reader.Name == "OutSignal")
                        {
                            string signalName = "";
                            int    port       = 0;
                            reader.Read();
                            if (reader.Name == "Name")
                            {
                                signalName = reader.ReadString();
                            }
                            reader.Read();
                            if (reader.Name == "Port")
                            {
                                port = Convert.ToInt32(reader.ReadString());
                            }
                            reader.Read();
                            string channelName = "";
                            if (reader.Name == "ChannelName")
                            {
                                channelName = reader.ReadString();
                            }
                            OutSignal outSignal = new OutSignal(port, signalName, path, hicore, channelName);
                            outSignals.Add(outSignal);
                        }
                    }
                }
            }

            SimulinkModel mod = new SimulinkModel(path, hicore, inSignals, outSignals);

            models.Add(mod);
            OnMessageReadingXml("Project successfully loaded.");
            return(models);
        }
        public List <ISignal> ReadXmlSimulinkModel(string _directoryPath, string _path, HiCoreClient _hiCore)
        {
            List <ISignal> signals = new List <ISignal>();

            XmlTextReader reader = new XmlTextReader(_directoryPath + "\\modelXML.xml");

            reader.Read();
            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    if (reader.Name == "InSignal")
                    {
                        reader.Read();
                        string name = "";
                        if (reader.Name == "Name")
                        {
                            name = reader.ReadString();
                        }

                        reader.Read();
                        int port = -1;
                        if (reader.Name == "Port")
                        {
                            port = Convert.ToInt32(reader.ReadString());
                        }
                        InSignal inSignal = new InSignal(port, name, _path, _hiCore);
                        //inSignal.SetSignal(5);
                        signals.Add(inSignal);
                    }
                    else if (reader.Name == "OutSignal")
                    {
                        string Name = "";
                        int    port = 0;
                        reader.Read();
                        if (reader.Name == "Name")
                        {
                            Name = reader.ReadString();
                        }
                        reader.Read();
                        if (reader.Name == "Port")
                        {
                            port = Convert.ToInt32(reader.ReadString());
                        }
                        OutSignal outSignal = new OutSignal(port, Name, _path, _hiCore);
                        signals.Add(outSignal);
                    }
                }
            }
            return(signals);
        }