Ejemplo n.º 1
0
 internal void Connect()
 {
     try
     {
         upsd.Connect();
         this.Status            &= ~UPSMonStatus.COMMBAD;
         this.Status            |= UPSMonStatus.COMMOK;
         this.Device.Description = upsd.GetUPSDescription(this.Device.Name);
         upsd.SetUsername(this.Username);
         upsd.SetPassword(this.Password);
         upsd.Login(this.Device.Name);
     }
     catch (SocketException sockex)
     {
         UPSMonThreads.AppendLog("Could not connect to UPS " + this.Device.ToString() + "! " + sockex.Message);
         if (this.Status != UPSMonStatus.NOCOMMS)
         {
             this.Status &= ~UPSMonStatus.COMMOK;
             this.Status |= UPSMonStatus.COMMBAD;
         }
         upsd.Disconnect();
     }
     catch (UPSException upsex)
     {
         UPSMonThreads.AppendLog("Error on UPS " + this.Device.ToString() + "! " + upsex.Code.ToString() + ":" + upsex.Description
                                 + (String.IsNullOrEmpty(upsex.Message) ? "" : " (" + upsex.Message + ")"));
         if (this.Status != UPSMonStatus.NOCOMMS)
         {
             this.Status &= ~UPSMonStatus.COMMOK;
             this.Status |= UPSMonStatus.COMMBAD;
         }
     }
 }