コード例 #1
0
 private void SetPortConfiguration(ComPortConfiguration comPortConfiguration)
 {
     _speedCb.SelectedItem    = AllBaudRates[comPortConfiguration.BaudRateProperty];
     _stopBitsCb.SelectedItem = AllStopBits[comPortConfiguration.StopBitsProperty];
     _parityCb.SelectedItem   = Paritys[comPortConfiguration.ParityProperty];
     _writeTimeOut.Text       = comPortConfiguration.WriteTimeOut.ToString();
     _readTimeOut.Text        = comPortConfiguration.ReadTimeOut.ToString();
     _dataBitsCb.SelectedItem = comPortConfiguration.DataBitsProperty;
 }
コード例 #2
0
 public static void AddComConfiguration(byte number, ComPortConfiguration configuration)
 {
     if (_comPortConfigurations.ContainsKey(number))
     {
         _comPortConfigurations[number] = configuration;
     }
     else
     {
         _comPortConfigurations.Add(number, configuration);
     }
 }
コード例 #3
0
        private ComPortConfiguration GetPortConfiguration()
        {
            ComPortConfiguration res = new ComPortConfiguration();

            res.BaudRateProperty = AllBaudRates.Keys.First(o => AllBaudRates[o] == _speedCb.SelectedItem.ToString());
            res.StopBitsProperty = AllStopBits.Keys.First(o => AllStopBits[o] == _stopBitsCb.SelectedItem.ToString());
            res.ParityProperty   = Paritys.Keys.First(o => Paritys[o] == _parityCb.SelectedItem.ToString());
            res.ReadTimeOut      = int.Parse(_readTimeOut.Text);
            res.WriteTimeOut     = int.Parse(_writeTimeOut.Text);
            res.DataBitsProperty = Convert.ToInt32(_dataBitsCb.SelectedItem);
            return(res);
        }
コード例 #4
0
        private void _portCb_SelectedIndexChanged(object sender, EventArgs e)
        {
            var portNum = byte.Parse(_portCb.SelectedItem.ToString());

            ComPortConfiguration config = ConnectionManager.GetComConfig(portNum);

            if (config == null)
            {
                config = GetPortConfiguration();
                ConnectionManager.AddComConfiguration(Convert.ToByte(_portCb.Text), config);
            }
            SetPortConfiguration(config);
        }
コード例 #5
0
        public void UpdateConfiguration()
        {
            _comPortConfiguration = ConnectionManager.GetComConfig(_portNumber);
            if (_comPortConfiguration == null)
            {
                _comPortConfiguration = new ComPortConfiguration();

                ConnectionManager.AddComConfiguration(_portNumber, _comPortConfiguration);
            }
            Serialport.BaudRate     = (int)_comPortConfiguration.BaudRateProperty;
            Serialport.StopBits     = _comPortConfiguration.StopBitsProperty;
            Serialport.Parity       = _comPortConfiguration.ParityProperty;
            Serialport.DataBits     = _comPortConfiguration.DataBitsProperty;
            Serialport.ReadTimeout  = _comPortConfiguration.ReadTimeOut;
            Serialport.WriteTimeout = _comPortConfiguration.WriteTimeOut;
        }