public void Start()
 {
     try
     {
         m_adsClient.WriteControl(new StateInfo(AdsState.Run, m_adsClient.ReadState().DeviceState));
     }
     catch (Exception err)
     {
         throw (new SystemException(err.Message));
     }
 }
        }//generateBlockAct()

        private int checkForRunMode()
        {
            int result = 1;

            try
            {
                adsClient.Connect(sysMan.GetTargetNetId(), 10000);
                AdsErrorCode adsError;
                StateInfo    state;
                AdsState     adsState;
                if ((adsError = adsClient.TryReadState(out state)) == 0)
                {
                    if ((adsState = state.AdsState) == AdsState.Run)
                    {
                        state.AdsState = AdsState.Config;
                        adsClient.WriteControl(state);
                    }
                }
                else
                {
                    throw new Exception("Could not read Ads State of Target, AdsError code: " + adsError);
                }
            }catch (Exception ex)
            {
                result = -1;
                MessageBox.Show(ex.Message);
            }
            adsClient.Disconnect();
            return(result);
        }
Example #3
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 #4
0
        private static void SetConfigMode()
        {
            var client = new TcAdsClient();
            var mode   = new StateInfo();

            client.Connect((int)AmsPort.SystemService);
            mode.AdsState = client.ReadState().AdsState;
            mode.AdsState = AdsState.Reconfig;
            client.WriteControl(mode);
            client.Dispose();
        }