コード例 #1
0
        /// <summary>
        /// Saves the configuration.
        /// </summary>
        /// <returns><c>true</c>, if configuration was saved, <c>false</c> otherwise.</returns>
        /// <param name="path">Path.</param>
        public bool SaveConfiguration(string path = null)
        {
            try {
                Stream stream;
                if (path == null)
                {
                    if (File.Exists(Configuration.ConfigSavePath))
                    {
                        stream = File.Open(Configuration.ConfigSavePath, System.IO.FileMode.Create);
                    }
                    else
                    {
                        string folderpath   = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                        string filename     = Path.GetFileName(Configuration.ConfigSavePath);
                        string completepath = Path.Combine(folderpath, filename);
                        stream = File.Open(completepath, System.IO.FileMode.CreateNew);
                        Configuration.ConfigSavePath = completepath;
                    }
                }
                else
                {
                    stream = File.Open(path, System.IO.FileMode.Create);
                }
                var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                BoardConfiguration config = new BoardConfiguration();
                config = this.Configuration;

                formatter.Serialize(stream, config);

                if (LastConfigurationLocations.Contains(path))
                {
                    LastConfigurationLocations.Remove(path);
                    LastConfigurationLocations.Reverse();
                    LastConfigurationLocations.Add(path);
                    LastConfigurationLocations.Reverse();
                }
                else
                {
                    LastConfigurationLocations.Reverse();
                    LastConfigurationLocations.Add(path);
                    LastConfigurationLocations.Reverse();
                }
                while (LastConfigurationLocations.Count > 5)
                {
                    LastConfigurationLocations.RemoveAt(5);
                }

                stream.Close();
            } catch (Exception) {
                throw;
            }
            return(true);
        }
コード例 #2
0
ファイル: SerializeTests.cs プロジェクト: Onkeliroh/DSA
        public void SerializeBoardConfigTest1()
        {
            var conf = new BoardConfiguration ();
            conf.AddPin (new APin (){ Number = 42 });

            Formator.Serialize (MemStream, conf);
            MemStream.Seek (0, SeekOrigin.Begin);

            var confClone = (BoardConfiguration)Formator.Deserialize (MemStream);

            Assert.AreEqual (conf.Pins [0], confClone.Pins [0]);
        }
コード例 #3
0
        /// <summary>
        /// Opens the configuration.
        /// </summary>
        /// <returns><c>true</c>, if configuration was opened, <c>false</c> otherwise.</returns>
        /// <param name="path">Path.</param>
        public bool OpenConfiguration(string path)
        {
            if (File.Exists(path))
            {
                try {
                    Stream stream    = File.Open(path, System.IO.FileMode.Open, FileAccess.Read, FileShare.Write);
                    var    formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                    var config = formatter.Deserialize(stream);

                    Configuration = (BoardConfiguration)config;

                    stream.Close();

                    if (LastConfigurationLocations.Contains(path))
                    {
                        LastConfigurationLocations.Remove(path);
                        LastConfigurationLocations.Reverse();
                        LastConfigurationLocations.Add(path);
                        LastConfigurationLocations.Reverse();
                    }
                    else
                    {
                        LastConfigurationLocations.Reverse();
                        LastConfigurationLocations.Add(path);
                        LastConfigurationLocations.Reverse();
                    }
                    WritePreferences();

                    if (OnOnfigurationLoaded != null)
                    {
                        OnOnfigurationLoaded.Invoke(this, new ConfigurationLoadedArgs(path, true));
                    }
                } catch (Exception) {
                    throw;
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        public void DPinCloneTest2()
        {
            string name = "TestPin";

            conf = new BoardConfiguration ();
            conf.AddPin (new DPin () {
                Number = 5,
                Name = name
            });

            conf.ClonePin (conf.DigitalPins [0]);

            Assert.AreEqual (2, conf.DigitalPins.Count);
            Assert.AreEqual (name, conf.DigitalPins [0].Name);
            Assert.AreEqual (name, conf.DigitalPins [1].Name);

            conf.DigitalPins [0].Name = string.Empty;
            Assert.AreEqual (name, conf.DigitalPins [1].Name);
        }
コード例 #5
0
ファイル: SerializeTests.cs プロジェクト: Onkeliroh/DSA
        public void SerializeBoardConfigTest2()
        {
            var conf = new BoardConfiguration ();
            conf.Board.AnalogReferenceVoltageType = "INTERNAL";
            conf.Board.AnalogReferenceVoltage = 4.24;

            var pin = new APin (){ Number = 42 };

            var MeCom = new MeasurementCombination ();
            MeCom.AddPin (pin);

            conf.AddPin (pin);
            conf.AddMeasurementCombination (MeCom);

            Formator.Serialize (MemStream, conf);
            MemStream.Seek (0, SeekOrigin.Begin);

            var confClone = (BoardConfiguration)Formator.Deserialize (MemStream);

            Assert.AreEqual (conf.Pins [0], confClone.Pins [0]);
            Assert.AreEqual (conf.MeasurementCombinations [0], confClone.MeasurementCombinations [0]);
            Assert.AreEqual (4.24, conf.Board.AnalogReferenceVoltage, 0.000000001);
            Assert.AreEqual (4.24, confClone.Board.AnalogReferenceVoltage, 0.000000001);
            Assert.AreEqual ("INTERNAL", conf.Board.AnalogReferenceVoltageType);
            Assert.AreEqual ("INTERNAL", confClone.Board.AnalogReferenceVoltageType);
            Assert.AreSame (conf.Pins [0], conf.MeasurementCombinations [0].Pins [0]);
            Assert.AreSame (confClone.Pins [0], confClone.MeasurementCombinations [0].Pins [0]);

            conf.Pins [0].Name = "Dulli";
            Assert.AreEqual (conf.Pins [0].Name, conf.MeasurementCombinations [0].Pins [0].Name);
            Assert.AreEqual (19, confClone.AvailableDigitalPins.Length);
            Assert.AreEqual (6, confClone.AvailableAnalogPins.Length);

            conf.ClearPins ();
            Assert.AreEqual (0, conf.Pins.Count);
            Assert.AreEqual (0, conf.MeasurementCombinations.Count);
        }
コード例 #6
0
ファイル: ControllerTests.cs プロジェクト: Onkeliroh/DSA
        public void CSVMappingTest()
        {
            var con = new BoardConfiguration ();
            con.AddPin (new APin (){ Number = 1, Name = "Pin1" });
            con.AddPin (new APin (){ Number = 2, Name = "Pin2" });
            con.AddPin (new APin (){ Number = 3, Name = "Pin3" });

            var res = con.CreateMapping ();

            Assert.AreEqual (3, res.Keys.Count);
            Assert.AreEqual (0, res [con.Pins [0].DisplayName]);
            Assert.AreEqual (1, res [con.Pins [1].DisplayName]);
            Assert.AreEqual (2, res [con.Pins [2].DisplayName]);

            con.AddMeasurementCombination (new MeasurementCombination () {
                Pins = new System.Collections.Generic.List<APin> (){ con.Pins [0] as APin, con.Pins [1] as APin },
                Name = "MeCom"
            });

            res = con.CreateMapping ();

            Assert.AreEqual (4, res.Keys.Count);
            Assert.AreEqual (3, res [con.MeasurementCombinations [0].DisplayName]);
        }
コード例 #7
0
ファイル: SequenceTests.cs プロジェクト: Onkeliroh/DSA
        public void GroupTest()
        {
            var conf = new BoardConfiguration ();

            for (uint i = 0; i < 10; i++)
            {
                conf.AddPin (new DPin () {
                    Number = i
                });
                conf.AddSequence (new Sequence () {
                    Pin = conf.DigitalPins [(int)i],
                    GroupName = i.ToString ()
                });
            }

            Assert.AreEqual (10, conf.SequenceGroups.Count);

            conf.RemoveSequence (5);
            Assert.AreEqual (9, conf.SequenceGroups.Count);

            conf.Sequences [2].GroupName = conf.Sequences [0].GroupName;
            Assert.AreEqual (8, conf.SequenceGroups.Count);
        }
コード例 #8
0
ファイル: Controller.cs プロジェクト: Onkeliroh/DSA
        /// <summary>
        /// Saves the configuration.
        /// </summary>
        /// <returns><c>true</c>, if configuration was saved, <c>false</c> otherwise.</returns>
        /// <param name="path">Path.</param>
        public bool SaveConfiguration(string path = null)
        {
            try {
                Stream stream;
                if (path == null) {
                    if (File.Exists (Configuration.ConfigSavePath)) {
                        stream = File.Open (Configuration.ConfigSavePath, System.IO.FileMode.Create);
                    } else {
                        string folderpath = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
                        string filename = Path.GetFileName (Configuration.ConfigSavePath);
                        string completepath = Path.Combine (folderpath, filename);
                        stream = File.Open (completepath, System.IO.FileMode.CreateNew);
                        Configuration.ConfigSavePath = completepath;
                    }
                } else {
                    stream = File.Open (path, System.IO.FileMode.Create);
                }
                var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter ();

                BoardConfiguration config = new BoardConfiguration ();
                config = this.Configuration;

                formatter.Serialize (stream, config);

                if (LastConfigurationLocations.Contains (path)) {
                    LastConfigurationLocations.Remove (path);
                    LastConfigurationLocations.Reverse ();
                    LastConfigurationLocations.Add (path);
                    LastConfigurationLocations.Reverse ();
                } else {
                    LastConfigurationLocations.Reverse ();
                    LastConfigurationLocations.Add (path);
                    LastConfigurationLocations.Reverse ();
                }
                while (LastConfigurationLocations.Count > 5) {
                    LastConfigurationLocations.RemoveAt (5);
                }

                stream.Close ();
            } catch (Exception) {
                throw;
            }
            return true;
        }
コード例 #9
0
ファイル: Controller.cs プロジェクト: Onkeliroh/DSA
        /// <summary>
        /// Opens the configuration.
        /// </summary>
        /// <returns><c>true</c>, if configuration was opened, <c>false</c> otherwise.</returns>
        /// <param name="path">Path.</param>
        public bool OpenConfiguration(string path)
        {
            if (File.Exists (path)) {
                try {
                    Stream stream = File.Open (path, System.IO.FileMode.Open, FileAccess.Read, FileShare.Write);
                    var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter ();

                    var config = formatter.Deserialize (stream);

                    Configuration = (BoardConfiguration)config;

                    stream.Close ();

                    if (LastConfigurationLocations.Contains (path)) {
                        LastConfigurationLocations.Remove (path);
                        LastConfigurationLocations.Reverse ();
                        LastConfigurationLocations.Add (path);
                        LastConfigurationLocations.Reverse ();
                    } else {
                        LastConfigurationLocations.Reverse ();
                        LastConfigurationLocations.Add (path);
                        LastConfigurationLocations.Reverse ();
                    }
                    WritePreferences ();

                    if (OnOnfigurationLoaded != null) {
                        OnOnfigurationLoaded.Invoke (this, new ConfigurationLoadedArgs (path, true));
                    }
                } catch (Exception) {
                    throw;
                }

                return true;
            } else {
                return false;
            }
        }
コード例 #10
0
ファイル: Controller.cs プロジェクト: Onkeliroh/DSA
        /// <summary>
        /// Initializes a new instance of the <see cref="Backend.Controller"/> class.
        /// </summary>
        /// <param name="ConfigurationPath">Configuration path.</param>
        public Controller(string ConfigurationPath = null)
        {
            Configuration = new BoardConfiguration ();
            using (MemoryStream memstream = new MemoryStream (Encoding.ASCII.GetBytes (Resources.Boards))) {
                using (StreamReader str = new StreamReader (memstream)) {
                    BoardConfigs = ConfigurationManager.ParseBoards (str);
                }
            }

            LastConfigurationLocations [0] = Backend.Properties.Settings.Default.Config1;
            LastConfigurationLocations [1] = Backend.Properties.Settings.Default.Config2;
            LastConfigurationLocations [2] = Backend.Properties.Settings.Default.Config3;
            LastConfigurationLocations [3] = Backend.Properties.Settings.Default.Config4;
            LastConfigurationLocations [4] = Backend.Properties.Settings.Default.Config5;

            #if DEBUG
            ConLogger = new InfoLogger (Resources.LogFileName, true, false, Settings.Default.LogLevel, Settings.Default.LogFilePath);
            #endif
            #if !DEBUG
            ConLogger = new InfoLogger (Resources.LogFileName, true, false, LogLevel.INFO, Settings.Default.LogFilePath);
            #endif
            ConLogger.LogToFile = Settings.Default.LogToFile;
            ConLogger.Start ();

            ArduinoController.AutoConnect = Settings.Default.AutoConnect;
            ArduinoController.Init ();
            ArduinoController.OnReceiveMessage += (sender, e) => ConLogger.Log ("IN < " + e.Message, LogLevel.DEBUG);
            ArduinoController.OnSendMessage += (sender, e) => ConLogger.Log ("OUT > " + e.Message, LogLevel.DEBUG);
            ArduinoController.OnConnectionChanged += ((o, e) => {
                if (e.Connected) {
                    ConLogger.Log ("Connected to: " + ArduinoController.Board.ToString (), LogLevel.INFO);
                } else {
                    ConLogger.Log ("Disconnected", LogLevel.INFO);
                }
            });

            Configuration.OnPinsUpdated += (o, e) => {
                if (e.UpdateOperation == UpdateOperation.Change)
                    ConLogger.Log ("Pin Update: [" + e.UpdateOperation + "] " + e.OldPin + " to " + e.NewPin);
                else
                    ConLogger.Log ("Pin Update: [" + e.UpdateOperation + "] " + e.OldPin);
            };
            Configuration.OnSequencesUpdated += (o, e) => {
                if (e.UpdateOperation == UpdateOperation.Change)
                    ConLogger.Log ("Sequence Update: [" + e.UpdateOperation + "] " + e.OldSeq + " to " + e.OldSeq);
                else
                    ConLogger.Log ("Sequence Update: [" + e.UpdateOperation + "] " + e.OldSeq);
            };
            Configuration.OnSignalsUpdated += (o, e) => {
                if (e.UpdateOperation == UpdateOperation.Change)
                    ConLogger.Log ("Sequence Update: [" + e.UpdateOperation + "] " + e.OldMeCom + " to " + e.NewMeCom);
                else
                    ConLogger.Log ("Sequence Update: [" + e.UpdateOperation + "] " + e.OldMeCom);
            };
        }
コード例 #11
0
        public void SetupSequence()
        {
            conf = new BoardConfiguration ();
            conf.AddPin (new DPin (){ Number = 0 });
            conf.AddPin (new DPin (){ Number = 1 });

            conf.AddSequence (new Sequence () { Pin = conf.DigitalPins [0],
                Chain = new List<SequenceOperation> () {
                    new SequenceOperation () {
                        Duration = TimeSpan.FromSeconds (1),
                        State = DPinState.HIGH
                    },
                    new SequenceOperation () {
                        Duration = TimeSpan.FromSeconds (1),
                        State = DPinState.HIGH
                    }
                }
            });
        }
コード例 #12
0
        public void SetupMeasurementCombination()
        {
            conf = new BoardConfiguration ();
            conf.AddPin (new APin (){ Number = 0 });
            conf.AddPin (new APin (){ Number = 1 });

            conf.AddMeasurementCombination (new MeasurementCombination () {
                Pins = new List<APin> (){ conf.AnalogPins [0], conf.AnalogPins [1] },
            });
        }
コード例 #13
0
        public void Setup()
        {
            conf = new BoardConfiguration ();

            for (int i = 0; i < 5; i++)
            {
                conf.AddPin (new APin (){ Number = (uint)i });
                conf.AddPin (new DPin (){ Number = (uint)i });
            }
        }
コード例 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Backend.Controller"/> class.
        /// </summary>
        /// <param name="ConfigurationPath">Configuration path.</param>
        public Controller(string ConfigurationPath = null)
        {
            Configuration = new BoardConfiguration();
            using (MemoryStream memstream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.Boards))) {
                using (StreamReader str = new StreamReader(memstream)) {
                    BoardConfigs = ConfigurationManager.ParseBoards(str);
                }
            }

            LastConfigurationLocations [0] = Backend.Properties.Settings.Default.Config1;
            LastConfigurationLocations [1] = Backend.Properties.Settings.Default.Config2;
            LastConfigurationLocations [2] = Backend.Properties.Settings.Default.Config3;
            LastConfigurationLocations [3] = Backend.Properties.Settings.Default.Config4;
            LastConfigurationLocations [4] = Backend.Properties.Settings.Default.Config5;


                        #if DEBUG
            ConLogger = new InfoLogger(Resources.LogFileName, true, false, Settings.Default.LogLevel, Settings.Default.LogFilePath);
                        #endif
                        #if !DEBUG
            ConLogger = new InfoLogger(Resources.LogFileName, true, false, LogLevel.INFO, Settings.Default.LogFilePath);
                        #endif
            ConLogger.LogToFile = Settings.Default.LogToFile;
            ConLogger.Start();


            ArduinoController.AutoConnect = Settings.Default.AutoConnect;
            ArduinoController.Init();
            ArduinoController.OnReceiveMessage    += (sender, e) => ConLogger.Log("IN < " + e.Message, LogLevel.DEBUG);
            ArduinoController.OnSendMessage       += (sender, e) => ConLogger.Log("OUT > " + e.Message, LogLevel.DEBUG);
            ArduinoController.OnConnectionChanged += ((o, e) => {
                if (e.Connected)
                {
                    ConLogger.Log("Connected to: " + ArduinoController.Board.ToString(), LogLevel.INFO);
                }
                else
                {
                    ConLogger.Log("Disconnected", LogLevel.INFO);
                }
            });

            Configuration.OnPinsUpdated += (o, e) => {
                if (e.UpdateOperation == UpdateOperation.Change)
                {
                    ConLogger.Log("Pin Update: [" + e.UpdateOperation + "] " + e.OldPin + " to " + e.NewPin);
                }
                else
                {
                    ConLogger.Log("Pin Update: [" + e.UpdateOperation + "] " + e.OldPin);
                }
            };
            Configuration.OnSequencesUpdated += (o, e) => {
                if (e.UpdateOperation == UpdateOperation.Change)
                {
                    ConLogger.Log("Sequence Update: [" + e.UpdateOperation + "] " + e.OldSeq + " to " + e.OldSeq);
                }
                else
                {
                    ConLogger.Log("Sequence Update: [" + e.UpdateOperation + "] " + e.OldSeq);
                }
            };
            Configuration.OnSignalsUpdated += (o, e) => {
                if (e.UpdateOperation == UpdateOperation.Change)
                {
                    ConLogger.Log("Sequence Update: [" + e.UpdateOperation + "] " + e.OldMeCom + " to " + e.NewMeCom);
                }
                else
                {
                    ConLogger.Log("Sequence Update: [" + e.UpdateOperation + "] " + e.OldMeCom);
                }
            };
        }