コード例 #1
0
ファイル: Dispatcher.cs プロジェクト: daniel-ehsure/Packing
        private const int READ_INTERVAL  = 3000;//毫秒

        /// <summary>
        /// 连接
        /// </summary>
        /// <returns>1、成功;2、失败;3、非上位运行;4、存在警报;5、完成总数不为0;6、读取完成数失败;10、异常</returns>
        public int Connect()
        {
            ShowInfo("开始连接...", Key);
            int result = 0;

            try
            {
                int rtn = axActUtlType.Open();
                if (rtn == 0)
                {
                    ShowInfo("连接成功!", Key);
                    result = 1;
                }
                else
                {
                    Status = 2;
                    ShowInfo("连接失败!", Key);
                    result = 2;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                Status = 2;
                ShowInfo(ex.Message, Key);
                result = 10;
                return(result);
            }

            if (result == 1)
            {
                //连接成功后,建立timer,发心跳包
                SendHeartbeat();

                //上位运行选择
                int res = GetHostFlag();

                if (res == 1)
                {
                    //读报警
                    res = GetWarning();

                    if (res == 1)
                    {
                        //读完成总数
                        result = GetDoneCount();
                    }
                }

                result = res;
            }

            return(result);
        }
コード例 #2
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     //Set the value of 'LogicalStationNumber' to the property.
     //與Communication Setup Utility設定值相同
     axActUtlType1.ActLogicalStationNumber = 1;
     //Set the value of 'Password'.
     //沒有密碼就給它空值
     axActUtlType1.ActPassword = "";
     //The Open method is executed.
     //回傳值0等於成功
     iReturnCode  = axActUtlType1.Open();
     labInfo.Text = (iReturnCode == 0) ? "連線PLC成功" : "連線PLC失敗";
 }