Exemple #1
0
        public void TCPRecv_DeviceInit()
        {
            bool result      = false;
            int  LastSendCmd = myApi.CurrentSendCmd;
            int  retry       = 0;

            try
            {
                while (!myApi.Connect())
                {
                    Thread.Sleep(1000);
                    retry++;

                    if (retry >= 3)
                    {
                        retry = 0;
                        showErrorMessageBox("阵线探测器服务器连接失败");

                        return;
                    }
                }

                if (DEVICE_STATE.DEVICE_INIT == myUart.DeviceState)
                {
                    if (DEVICE_CMD_ID.RESET == myApi.CurrentSendCmd)
                    {
                        result = myApi.RecvTCPCmdResultCheck(myApi.TCPRecvBytes, out TCPReturnCode);
                        if (result)
                        {
                            timerTCPRecv.Enabled = false;
                            string name;
                            if (0 == myApi.TargetType)
                            {
                                name = "Cr";
                            }
                            else
                            {
                                name = "Cu";
                            }

                            myApi.SetTarget(name);
                            result = myApi.RecvTCPCmdResultCheck(myApi.TCPRecvBytes, out TCPReturnCode);
                            if (result)
                            {
                                timerTCPRecv.Enabled = false;
                                // init end
                                DetectorInitFinish();
                            }
                        }
                    }
                    //else if (DEVICE_CMD_ID.SET_TARGET == myApi.CurrentSendCmd)
                    //{
                    //    result = myApi.RecvTCPCmdResultCheck(myApi.TCPRecvBytes, out TCPReturnCode);
                    //    if (result)
                    //    {
                    //        timerTCPRecv.Enabled = false;
                    //        // init end
                    //        DetectorInitFinish();
                    //    }
                    //}
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                myUart.Pack_Debug_out(null, "Exception" + "[" + ex.ToString() + "]");
            }
        }