Exemplo n.º 1
0
 void Disconnect(System.Windows.Forms.Control sender, object[] parameters)
 {
     try
     {
         int pos = 0;
         int cnt;
         object obj = parameters[0];
         if (obj is GXDLMSDeviceCollection)
         {
             cnt = ((GXDLMSDeviceCollection)obj).Count;
             foreach (GXDLMSDevice it in (GXDLMSDeviceCollection)obj)
             {
                 sender.BeginInvoke(new ProgressEventHandler(this.OnProgress), null, "Disconnecting", ++pos, cnt);
                 it.Disconnect();
             }
         }
         else if (obj is GXDLMSDevice)
         {
             sender.BeginInvoke(new ProgressEventHandler(this.OnProgress), null, "Disconnecting", 0, 1);
             ((GXDLMSDevice)obj).Disconnect();
         }
         else if (obj is GXDLMSObjectCollection)
         {
             GXDLMSObjectCollection tmp = obj as GXDLMSObjectCollection;
             GXDLMSDeviceCollection devices = new GXDLMSDeviceCollection();
             foreach (GXDLMSObject it in tmp)
             {
                 GXDLMSDevice dev = it.Parent.Tag as GXDLMSDevice;
                 if (!devices.Contains(dev))
                 {
                     devices.Add(dev);
                 }
             }
             Disconnect(sender, new object[] { devices });
         }
         else
         {
             sender.BeginInvoke(new ProgressEventHandler(this.OnProgress), null, "Disconnecting", 0, 1);
             GXDLMSObject tmp = obj as GXDLMSObject;
             GXDLMSDevice dev = tmp.Parent.Tag as GXDLMSDevice;
             dev.Disconnect();
         }
     }
     catch (ThreadAbortException)
     {
         //User has cancel action. Do nothing.
     }
     catch (Exception Ex)
     {
         GXDLMS.Common.Error.ShowError(sender, Ex);
     }
     finally
     {
         sender.BeginInvoke(new ProgressEventHandler(this.OnProgress), null, "", 1, 1);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 GXDLMSDeviceCollection GetDevices()
 {
     GXDLMSDeviceCollection devices = new GXDLMSDeviceCollection();
     foreach (GXDLMSObject it in SelectedListItems.Values)
     {
         GXDLMSDevice dev = it.Parent.Tag as GXDLMSDevice;
         if (!devices.Contains(dev))
         {
             devices.Add(dev);
         }
     }
     //If no device item is selected return all devices.
     if (devices.Count == 0)
     {
         return this.Devices;
     }
     return devices;
 }
Exemplo n.º 3
0
 void Connect(System.Windows.Forms.Control sender, object[] parameters)
 {
     try
     {
         object obj = parameters[0];
         int pos = 0;
         int cnt;
         if (obj is GXDLMSDeviceCollection)
         {
             cnt = ((GXDLMSDeviceCollection)obj).Count;
             foreach (GXDLMSDevice it in (GXDLMSDeviceCollection)obj)
             {
                 if (!it.Media.IsOpen)
                 {
                     this.OnProgress(null, "Connecting", ++pos, cnt);
                     it.InitializeConnection();
                 }
             }
         }
         else if (obj is GXDLMSDevice)
         {
             if (!((GXDLMSDevice)obj).Media.IsOpen)
             {
                 this.OnProgress(null, "Connecting", 0, 1);
                 ((GXDLMSDevice)obj).InitializeConnection();
             }
         }
         else if (obj is GXDLMSObjectCollection)
         {
             GXDLMSObjectCollection tmp = obj as GXDLMSObjectCollection;
             GXDLMSDeviceCollection devices = new GXDLMSDeviceCollection();
             foreach (GXDLMSObject it in tmp)
             {
                 GXDLMSDevice dev = it.Parent.Tag as GXDLMSDevice;
                 if (!devices.Contains(dev))
                 {
                     devices.Add(dev);
                 }
             }
             Connect(sender, new object[] { devices });
         }
         else
         {
             this.OnProgress(null, "Connecting", 0, 1);
             GXDLMSObject tmp = obj as GXDLMSObject;
             GXDLMSDevice dev = tmp.Parent.Tag as GXDLMSDevice;
             if (!dev.Media.IsOpen)
             {
                 dev.InitializeConnection();
             }
         }
     }
     catch (ThreadAbortException)
     {
         //User has cancel action. Do nothing.
     }
     catch (Exception Ex)
     {
         GXDLMS.Common.Error.ShowError(sender, Ex);
     }
     finally
     {
         this.OnProgress(null, "Connecting", 1, 1);
     }
 }