コード例 #1
0
ファイル: SerialPortManager.cs プロジェクト: sundfar/Windman3
        public SerialPortManager(MeasureManager pMeasureManager)
        {
            _measureManager = pMeasureManager;
            _currentSerialSettings = SerialSettings.NewFromConfigFile();
            // Finding installed serial ports on hardware
            //_currentSerialSettings.PortNameCollection = SerialPort.GetPortNames();
            //_currentSerialSettings.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_currentSerialSettings_PropertyChanged);

            // If serial ports is found, we select the first found
            //if (_currentSerialSettings.PortNameCollection.Length > 0)
            //    _currentSerialSettings.PortName = _currentSerialSettings.PortNameCollection[0];
        }
コード例 #2
0
ファイル: SerialSettings.cs プロジェクト: sundfar/Windman3
 public static SerialSettings NewFromConfigFile()
 {
     SerialSettings ss = new SerialSettings();
     ss.PortName = ConfigurationManager.AppSettings["PortName"];
     ss.BaudRate = int.Parse(ConfigurationManager.AppSettings["BaudRate"]);
     ss.DataBits = int.Parse(ConfigurationManager.AppSettings["DataBits"]);
     switch (ConfigurationManager.AppSettings["Parity"])
     {
         case "Odd":
             ss.Parity = Parity.Odd;
             break;
         case "Even":
             ss.Parity = Parity.Even;
             break;
         case "Mark":
             ss.Parity = Parity.Mark;
             break;
         case "None":
             ss.Parity = Parity.None;
             break;
         case "Space":
             ss.Parity = Parity.Space;
             break;
         default:
             break;
     }
     switch (ConfigurationManager.AppSettings["StopBits"])
     {
         case "None":
             ss.StopBits = StopBits.None;
             break;
         case "One":
             ss.StopBits = StopBits.One;
             break;
         case "OnePointFive":
             ss.StopBits = StopBits.OnePointFive;
             break;
         case "Two":
             ss.StopBits = StopBits.Two;
             break;
         default:
             break;
     }
     return ss;
 }