Ejemplo n.º 1
0
 private void CheckPort()
 {
     if (string.IsNullOrEmpty(_portName))
     {
         IsConnected = false;
         return;
     }
     try
     {
         if (_commport.IsOpen)
         {
             _commport.Close();
         }
         _commport.PortName     = _portName;
         _commport.BaudRate     = 57600;
         _commport.DataBits     = 8;
         _commport.StopBits     = StopBits.One;
         _commport.Parity       = Parity.None;
         _commport.ReadTimeout  = 500;
         _commport.WriteTimeout = 500;
         using (var session = new SerialPortSession(_commport))
         {
             var checkCommand = new CheckRegSEPortCommand();
             checkCommand.Execute(session.Port);
             IsConnected = checkCommand.IsOk();
             if (IsConnected)
             {
                 Settings.Default.PortName = _portName;
                 Settings.Default.Save();
             }
         }
     }
     catch (Exception)
     {
         IsConnected = false;
     }
 }
 private void CheckPort()
 {
     if (string.IsNullOrEmpty(_portName))
     {
         IsConnected = false;
         return;
     }
     try
     {
         if (_commport.IsOpen)
         {
             _commport.Close();
         }
         _commport.PortName = _portName;
         _commport.BaudRate = 57600;
         _commport.DataBits = 8;
         _commport.StopBits = StopBits.One;
         _commport.Parity = Parity.None;
         _commport.ReadTimeout = 500;
         _commport.WriteTimeout = 500;
         using (var session = new SerialPortSession(_commport))
         {
             var checkCommand = new CheckRegSEPortCommand();
             checkCommand.Execute(session.Port);
             IsConnected = checkCommand.IsOk();
             if (IsConnected)
             {
                 Settings.Default.PortName = _portName;
                 Settings.Default.Save();
             }
         }
     }
     catch (Exception)
     {
         IsConnected = false;
     }
 }