public void SerialPortSettingsToStringException()
        {
            SerialPortSettings s = new SerialPortSettings(BaudRate.BR_57600,
                Parity.Even, StopBits.One, 0xA0, 0xA1);

            Console.WriteLine(s.ToString("F", null));
        }
        public void UpdateXElement()
        {
            SerialPortSettings serialPortSettings = new SerialPortSettings(BaudRate.BR_57600,
                Parity.Odd, StopBits.One, 0xAA, 0xA5);

            string xElementSerialPortSettings =
                "<serialPortSettings>" + "\r\n  " +
                "<baudrate>9600</baudrate>" + "\r\n  " +
                "<parity>1</parity>" + "\r\n  " +
                "<stopbit>2</stopbit>" + "\r\n  " +
                "<headerTx>0x8A</headerTx>" + "\r\n  " +
                "<headerRx>0x85</headerRx>" + "\r\n" +
                "</serialPortSettings>";

            XElement xElement = XElement.Parse(xElementSerialPortSettings);

            xElement.UpdateXElement(serialPortSettings, XNamespace.None);

            string xExpectedElementSerialPortSettings =
                "<serialPortSettings>" + "\r\n  " +
                "<baudrate>57600</baudrate>" + "\r\n  " +
                "<parity>1</parity>" + "\r\n  " +
                "<stopbit>1</stopbit>" + "\r\n  " +
                "<headerTx>0xAA</headerTx>" + "\r\n  " +
                "<headerRx>0xA5</headerRx>" + "\r\n" +
                "</serialPortSettings>";

            Assert.AreEqual(xExpectedElementSerialPortSettings, xElement.ToString());
        }
 internal static void UpdateXElement(this XElement element, SerialPortSettings serialPortSettings, XNamespace ns)
 {
     element.Element(ns + "baudrate").Value = ((int)Enum.Parse(typeof(BaudRate), serialPortSettings.BaudRate.ToString())).ToString();
     element.Element(ns + "parity").Value = ((int)Enum.Parse(typeof(Parity), serialPortSettings.Parity.ToString())).ToString();
     element.Element(ns + "stopbit").Value = ((int)Enum.Parse(typeof(StopBits), serialPortSettings.StopBits.ToString())).ToString();
     element.Element(ns + "headerTx").Value = "0x" + serialPortSettings.HeaderTX.ToString("X2");
     element.Element(ns + "headerRx").Value = "0x" + serialPortSettings.HeaderRX.ToString("X2");
 }
Example #4
0
        public ReadLockViewModel(string portName, SerialPortSettings serialPortSettings, ILoggerFacade logger, byte locks)
            : base(portName, serialPortSettings, logger)
        {
            Text = "Read Lock";
            taskm = new TaskManager<bool>((taskManager) =>
            {
                return (new ReadLockWorkerSlave(portName, serialPortSettings, logger, locks).Run(taskManager));
            });

            taskm.Canceled += taskm_Canceled;
            taskm.Completed += taskm_Completed;
            taskm.Faulted += taskm_Faulted;
            taskm.Started += taskm_Started;
        }
        public ConnectionViewModel(string portName, SerialPortSettings serialPortSettings, ILoggerFacade logger, int version, DateTime date)
            : base(portName, serialPortSettings, logger)
        {
            Text = "Connection";
            taskm = new TaskManager<bool>((taskManager) =>
            {
                return (new ConnectionWorkerSlave(portName, serialPortSettings, logger, version, date).Run(taskManager));
            });

            taskm.Canceled += taskm_Canceled;
            taskm.Completed += taskm_Completed;
            taskm.Faulted += taskm_Faulted;
            taskm.Started += taskm_Started;
        }
Example #6
0
        public EraseViewModel(string portName, SerialPortSettings serialPortSettings, ILoggerFacade logger, MemoryType type, IMemory memory)
            : base(portName, serialPortSettings, logger)
        {
            Text = "Erase " + ((type == MemoryType.FLASH) ? "FLASH" : "EEPROM");
            taskm = new TaskManager<bool>((taskManager) =>
            {
                return (new ErasePageWorkerSlave(portName, serialPortSettings, logger, type, memory).Run(taskManager));
            });

            taskm.Canceled += taskm_Canceled;
            taskm.Completed += taskm_Completed;
            taskm.Faulted += taskm_Faulted;
            taskm.Started += taskm_Started;
        }
        public void Create()
        {
            SerialPortSettings s1 = new SerialPortSettings(BaudRate.BR_57600,
                Parity.Even, StopBits.One, 0xA0, 0xA5);
            SerialPortSettings s2 = new SerialPortSettings(BaudRate.BR_57600,
                Parity.Even, StopBits.One, 0xA0, 0xA5);

            Assert.IsTrue(s1.Equals(s2));

            foreach (var h in SerialPortSettings.AllowableHeadersList)
            {
                if (h % 0x10 == 0 && h != SerialPortSettings.MinAllowableHeaderValue)
                    Console.WriteLine();
                Console.Write("0x{0:X2} ", h);
            }
        }
        public void ToXElement()
        {
            SerialPortSettings serialPortSettings = new SerialPortSettings(BaudRate.BR_57600,
                Parity.Odd, StopBits.One, 0xAA, 0xA5);

            XElement xElement = serialPortSettings.ToXElement("namespace");

            string xElementSerialPortSettings =
                "<serialPortSettings xmlns=\"namespace\">" + "\r\n  " +
                "<baudrate>57600</baudrate>" + "\r\n  " +
                "<parity>1</parity>" + "\r\n  " +
                "<stopbit>1</stopbit>" + "\r\n  " +
                "<headerTx>0xAA</headerTx>" + "\r\n  " +
                "<headerRx>0xA5</headerRx>" + "\r\n" +
                "</serialPortSettings>";

            Assert.AreEqual(xElementSerialPortSettings, xElement.ToString());
        }
        public void ToSerialPortSettings()
        {
            string xElementSerialPortSettings =
                "<serialPortSettings>" + "\r\n  " +
                "<baudrate>57600</baudrate>" + "\r\n  " +
                "<parity>1</parity>" + "\r\n  " +
                "<stopbit>1</stopbit>" + "\r\n  " +
                "<headerTx>0xAA</headerTx>" + "\r\n" +
                "<headerRx>0xA5</headerRx>" + "\r\n" +
                "</serialPortSettings>";

            XElement xElement = XElement.Parse(xElementSerialPortSettings);
            SerialPortSettings serialPortSettings = xElement.ToSerialPortSettings(XNamespace.None);
            SerialPortSettings expectedSerialPortSettings = new SerialPortSettings(BaudRate.BR_57600,
                Parity.Odd, StopBits.One, 0xAA, 0xA5);

            Assert.IsTrue(expectedSerialPortSettings.Equals(serialPortSettings));
        }
Example #10
0
 public IOWorkerBase(string portName, SerialPortSettings serialPortSettings, ILoggerFacade logger)
 {
     this.portName = portName;
     this.serialPortSettings = serialPortSettings;
     this.logger = logger;
 }
        public virtual SettingsInfo GetNewSettingsInfo()
        {
            var processor = ListOfProcessors.ElementAt(IndexOfTheSelectedProcessor);
            var serialPortSettings = new SerialPortSettings(ListOfBaudRates.ElementAt(IndexOfTheSelectedBaudRate),
                ListOfParities.ElementAt(IndexOfTheSelectedParity), ListOfStopBits.ElementAt(IndexOfTheSelectedStopBits),
                ListOfAllowableHeaders.ElementAt(IndexOfTheSelectedHeaderTx), ListOfAllowableHeaders.ElementAt(IndexOfTheSelectedHeaderRx));

            var s = new SettingsInfo(0, string.Empty, processor, serialPortSettings);

            return s;
        }
Example #12
0
        private void LoadSettings()
        {
            Text = @"Bliksem Control Center (2016)" + (Settings.Default.WindowCaption != "" ? " - " + Settings.Default.WindowCaption : "");

            using (FileStream reader = new FileStream(_dataFile, FileMode.Open, FileAccess.Read))
            {
                DataContractSerializer ser = new DataContractSerializer(typeof(List<Channels>));
                _outputs = (List<Channels>)ser.ReadObject(reader);
            }

            if (File.Exists(_scheduleFile))
            {
                using (FileStream reader = new FileStream(_scheduleFile, FileMode.Open, FileAccess.Read))
                {
                    DataContractSerializer ser = new DataContractSerializer(typeof(List<Schedule>));
                    _schedules = (List<Schedule>)ser.ReadObject(reader);
                }
            }

            if (!File.Exists(_serialportFile)) return;

            using (FileStream reader = new FileStream(_serialportFile, FileMode.Open, FileAccess.Read))
            {
                DataContractSerializer ser = new DataContractSerializer(typeof(SerialPortSettings));
                _portSettings = (SerialPortSettings)ser.ReadObject(reader);
            }
            _port.PortName = _portSettings.PortName ?? _port.PortName;
            _port.BaudRate = _portSettings.BaudRate == 0 ? 9600 : _portSettings.BaudRate;
            _port.Parity = _portSettings.Parity;
            _port.DataBits = _portSettings.DataBits == 0 ? 8 : _portSettings.DataBits;
            _port.StopBits = _portSettings.StopBits == StopBits.None ? StopBits.One : _portSettings.StopBits;
        }
 public void CreateHeaderTXException()
 {
     SerialPortSettings s = new SerialPortSettings(BaudRate.BR_57600,
         Parity.Even, StopBits.One, 0x7F, 0xA5);
 }