private void OnGUI()
        {
            if (!CanShowGUI)
            {
                return;
            }
            GUILayout.Space(40);
            if (!DynaLinkHS.ServerLinkActBit && !MainCore.Instance.IsMachineDisabled)
            {
                if (GUILayout.Button("     重连     ", GUILayout.Width(160), GUILayout.Height(60)))
                {
                    StartCoroutine(OnReconnect());
                }
            }

            if (GUILayout.Button("     断开     ", GUILayout.Width(160), GUILayout.Height(60)))
            {
                if (!MainCore.Instance.IsMachineDisabled)
                {
                    DynaLinkHS.CmdServoOff();
                }
                DynaLinkCore.StopSocket();
                Application.Quit();
            }
        }
        //IEnumerator PassiveMoveToRespawnLoc()
        //{
        //    while (DynaLinkHS.MotionInProcess)
        //    {
        //        Debug.LogWarning("<color=orange>Motion in process! Waiting one frame!</color>");
        //        yield return "Wait for one frame";
        //    }
        //    Vector2 targetVec = new Vector2(81500, 35600);
        //    CommandFunctions.InitializeStartReset(targetVec, 150000, 300);
        //    Debug.Log(string.Format("<color=cyan>PassiveMoveTo:</color> ({0}, {1})", (int)targetVec.x, (int)targetVec.y));
        //    do
        //    {
        //        yield return new WaitForSeconds(1f);
        //    } while (!CommandFunctions.IsResetStartFinished || DynaLinkHS.MotionInProcess);

        //    CommandFunctions.IsResetStartFinished = false;
        //    Debug.Log("<color=yellow>End resetting!</color>");
        //    yield return "End resetting!";
        //    DynaLinkHS.CmdAssistLT(70);
        //}

        //IEnumerator CountDown()
        //{
        //    if (!MainCore.Instance.IsMachineDisabled)
        //    {
        //        while (!DynaLinkHS.ServerLinkActBit)
        //        {
        //            yield return "Wait Connectting!";
        //        }
        //        yield return StartCoroutine(PassiveMoveToRespawnLoc());
        //    }

        //    FollowerObj.gameObject.SetActive(true);
        //    //_canFollow = true;
        //}

        IEnumerator OnReconnect()
        {
            if (!DynaLinkHS.ServerLinkActBit)
            {
                DynaLinkCore.StopSocket();
                yield return(new WaitForSeconds(1f));

                DynaLinkCore.ConnectClick();
            }
        }
Exemple #3
0
    /// <summary>
    /// 开机连接到机器
    /// </summary>
    /// <returns></returns>
    IEnumerator InitializeConnection()
    {
        //如果机器还未连接,发送连接命名
        if (!DetectionManage.Instance.Connected)
        {
            Debug.Log("Begin Connect");
            DynaLinkCore.ConnectClick();
        }

        //三秒等待连接
        float initialTimeOut = 0;

        while (!DetectionManage.Instance.Connected)
        {
            if (initialTimeOut >= 3f)
            {
                //超过三秒,连接超时,断开连接准备重连
                DynaLinkCore.StopSocket();
                Debug.Log("Initialize connection Time-out!");
                Debug.Log("Disconnected!");
                //断开连接有一定的延迟
                yield return(new WaitForSeconds(1f));

                //开始监听连接和急停的事件
                DetectionManage.Instance.ActionReConnect    += OnReConnect;
                DetectionManage.Instance.ActionEmrgencyStop += OnEmrgencyStop;
                //由于未连接上执行断开连接的事件一次
                OnReConnect(false);
                IsFinished = true;
                yield break;
            }
            yield return(new WaitForSeconds(1f));

            initialTimeOut += 1f;
        }

        CommandFunctions.IsConnected = true;
        //如果连接上了,开始监听连接事件
        DetectionManage.Instance.ActionReConnect += OnReConnect;
        //判断机器是否有急停情况
        if (DetectionManage.Instance.EMstopBit)
        {
            OnEmrgencyStop(true);
        }
        //开始监听急停事件
        DetectionManage.Instance.ActionEmrgencyStop += OnEmrgencyStop;
        IsFinished = true;
    }
 void DisConnectNetBtnClick()
 {
     DynaLinkCore.StopSocket();
 }
 void ConnectNetBtnClick()
 {
     DynaLinkCore.ConnectClick();
 }
 private void OnDestroy()
 {
     DynaLinkCore.StopSocket();
     Thread.Sleep(100);
 }
Exemple #7
0
 void OnApplicationQuit()
 {
     DynaLinkCore.StopSocket();
     UdpBasicClass.UdpSocketClient.SocketQuit();
 }