Example #1
0
 public void UnregisterParameter(X parameterName)
 {
     if (NotifyParameters.Any(a => a.Key != parameterName))
     {
         return;
     }
     _tcClient.DeleteDeviceNotification((NotifyParameters.First(a => a.Key == parameterName).Value.NotifyID));
     NotifyParameters.Remove(NotifyParameters.First(a => a.Key == parameterName));
     ParametersValue.Remove(parameterName);
 }
Example #2
0
        public bool ConnectClose()
        {
            bool bl = false;

            try
            {
                if (tr != null)
                {
                    tr.Abort();
                }
                try
                {
                    foreach (int handle in notificationHandles)
                    {
                        _client.DeleteDeviceNotification(handle);
                    }
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
                notificationHandles.Clear();
                _client.Disconnect();
                ConnectFlag = false;
                bl          = true;
            }
            catch
            {
                bl = false;
            }
            return(bl);
        }
Example #3
0
        public void delete()
        {
            binRead.Close();
            tcClient.DeleteDeviceNotification(hConnect[0]);
            tcClient.Disconnect();

            hConnect[0] = 0;
        }
        /// <summary>
        /// Removes the specified <paramref name="tag"/> from observation.
        /// </summary>
        /// <param name="tag">The tag to remove.</param>
        public void RemoveTag(Tag tag)
        {
            Tuple <Tag, int> handleByTag = _notificationHandlesByTag.FirstOrDefault(t => Equals(t.Item1, tag));

            if (handleByTag == null)
            {
                return;
            }

            tag.ValueChanged -= TagValueChanged;

            _notificationHandlesByTag.Remove(handleByTag);

            if (_twinCatClient.IsConnected)
            {
                _twinCatClient.DeleteDeviceNotification(handleByTag.Item2);
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            string deviceDescription = "USB-4704,BID#0";
            string profilePath       = @"C:\Advantech\Profile\p2.xml";

            tcClient   = new TcAdsClient();
            dataStream = new AdsStream(1);

            instantDoCtrl = new InstantDoCtrl();
            binReader     = new BinaryReader(dataStream, System.Text.Encoding.ASCII);
            tcClient.Connect(851);

            try
            {
                instantDoCtrl.SelectedDevice = new DeviceInformation(deviceDescription);
                errorCode = instantDoCtrl.LoadProfile(profilePath);//Loads a profile to initialize the device.
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }

                hDigOutP0                 = tcClient.AddDeviceNotification("A4704.byDigOutP0", dataStream, 0, 1, AdsTransMode.OnChange, 10, 0, huValHandle);
                hEndA4704Program          = tcClient.AddDeviceNotification("A4704.bEndA4704Program", dataStream, 0, 1, AdsTransMode.OnChange, 10, 0, huValHandle);
                tcClient.AdsNotification += new AdsNotificationEventHandler(OnNotification);

                HeartbeatThread heartbeat = new HeartbeatThread(tcClient);
                heartbeatThread = new Thread(new ThreadStart(heartbeat.beat));
                heartbeatThread.Start();

                manualResetEvent = new ManualResetEvent(false);
                manualResetEvent.WaitOne();

                //Console.ReadKey(false);
            }
            catch (Exception e)
            {
                // Something is wrong
                string errStr = BioFailed(errorCode) ? " Some error occurred. And the last error code is " + errorCode.ToString()
                                                           : e.Message;
                //Console.WriteLine(errStr);
            }
            finally
            {
                instantDoCtrl.Dispose();
                heartbeatThread.Abort();
                heartbeatThread.Join();
                tcClient.DeleteDeviceNotification(hDigOutP0);
                tcClient.Dispose();
            }
        }
 public void Dispose()
 {
     try
     {
         _client.DeleteDeviceNotification(HandleId);
     }
     catch
     {
         // ignored. An exception may happen when the ADS connection is lost
     }
     finally
     {
         _client = null;
     }
 }
Example #7
0
 private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         for (int i = 0; i < hLamp.Length; i++)
         {
             client.DeleteDeviceNotification(hLamp[i]);
         }
     }
     catch (Exception err)
     {
         MessageBox.Show("Error: deleteDeviceNotification: " + err.Message);
     }
     client.Dispose();
 }
 private void DeleteCurrentNotification()
 {
     try
     {
         if (this.notificationHandle != 0)
         {
             adsClient.DeleteDeviceNotification(this.notificationHandle);
             this.notificationHandle = 0;
         }
     }
     catch (Exception err)
     {
         MessageBox.Show("Failed to delete notificationHandle. " + err.Message);
     }
 }
Example #9
0
 //add notifac
 public void removeNotifications()
 {
     try
     {
         foreach (int handle in notificationHandles)
         {
             adsClient.DeleteDeviceNotification(handle);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     notificationHandles.Clear();
 }
Example #10
0
 public static void Disconnect()
 {
     try
     {
         foreach (int handle in NotificationHandles)
         {
             TwinCat3Client.DeleteDeviceNotification(handle);
         }
         TwinCat3Client.Dispose();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     NotificationHandles.Clear();
     TwinCat3Client.Dispose();
 }
Example #11
0
 private void btnDeleteNotifications_Click(object sender, System.EventArgs e)
 {
     //delete registered notifications.
     try
     {
         foreach (int handle in notificationHandles)
         {
             adsClient.DeleteDeviceNotification(handle);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     notificationHandles.Clear();
     btnAddNotifications.Enabled    = true;
     btnDeleteNotifications.Enabled = false;
 }
Example #12
0
 public void StopNotice()
 {
     mNotice = false;
     for (int i = 0; i < ToNotice.Count; i++)
     {
         try
         {
             if (ToNotice[i].CoilNoticeHandle != 0)
             {
                 adsClient.DeleteDeviceNotification(ToNotice[i].CoilNoticeHandle);
                 ToNotice[i].CoilNoticeHandle = 0;
             }
         }
         catch (Exception ex)
         {
             Trace.Write(ex, "StopNotice");
         }
     }
 }
Example #13
0
 public override bool Close()
 {
     try
     {
         if (bInitOK)
         {
             clientStateInfo.AdsState = AdsState.Stop;
             tcClient.WriteControl(clientStateInfo);
         }
         for (int i = 0; i < 3; i++)
         {
             tcClient.DeleteDeviceNotification(posInt[i]);
             tcClient.DeleteDeviceNotification(isMovingInt[i]);
             tcClient.DeleteDeviceNotification(alarmInt[i]);
             tcClient.DeleteDeviceNotification(homeDoneInt[i]);
             //tcClient.DeleteDeviceNotification(cwInt[i]);
             //tcClient.DeleteDeviceNotification(ccwInt[i]);
             //tcClient.DeleteDeviceNotification(homeInt[i]);
             tcClient.DeleteDeviceNotification(isMoveDoneInt[i]);
         }
         for (int i = 1; i <= 6; i++)
         {
             for (int j = 1; j <= 16; j++)
             {
                 tcClient.DeleteDeviceNotification(inputIntNot[i, j]);
                 tcClient.DeleteDeviceNotification(outputIntNot[i, j]);
             }
         }
         Global.bPLCConnected = false;
         bInitOK = false;
         if (tcClient != null)
         {
             tcClient.Disconnect();
             tcClient.Dispose();
         }
     }
     catch (Exception ex)
     {
         Global.bPLCConnected = false;
         bInitOK = false;
     }
     return(true);
 }
Example #14
0
        //------------------------------------------------------
        // wird beim Beenden des Programms aufgerufen
        // is activated when ending the program
        //------------------------------------------------------
        private void Close(object sender, EventArgs e)
        {
            try
            {
                // Löschen der Notifications und Handles
                // Deleting of the notifications and handles
                tcClient.DeleteDeviceNotification(hEngine);
                tcClient.DeleteDeviceNotification(hDeviceUp);
                tcClient.DeleteDeviceNotification(hDeviceDown);
                tcClient.DeleteDeviceNotification(hSteps);
                tcClient.DeleteDeviceNotification(hCount);
                tcClient.DeleteDeviceNotification(hSwitchNotify);

                tcClient.DeleteVariableHandle(hSwitchWrite);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            tcClient.Dispose();
        }