private void Update(object sender, EventArgs e) { if (ct.receiveMessage != null) { SetText("Server: " + ct.receiveMessage); ct.receiveMessage = null; } if (ct.IsConnected) { isWaitingForConnection = false; ct.Receive(); } else { SetText("Server: Disconnected!"); if (!isWaitingForConnection || isWaitingForConnectionCounter > IsWaitingForConnectionCounterMax) { ct.StopConnect(); ct.StartConnect(); isWaitingForConnection = true; isWaitingForConnectionCounter = 0; } } if (isWaitingForConnection) { isWaitingForConnectionCounter++; } }
private void Update() { if (ct.receiveMessage != null) { Debug.Log(ct.receiveMessage); // Ting PlayerParam.Server = JsonUtility.FromJson <GameData>(ct.receiveMessage); // Debug.Log("get: " + PlayerParam.Server.Player_Pos_X); // Debug.Log("get: " + PlayerParam.Server.Player_Pos_Y); // rr = JsonUtility.FromJson<senddata>(ct.receiveMessage); // Debug.Log("get: " + rr.a); // Debug.Log("get: " + rr.b); Debug.Log("Server: success"); PlayerParam.Status_Update = true; // Debug.Log("Server:" + ct.receiveMessage); ct.receiveMessage = null; } if (isSend == true) { StartCoroutine(delaySend()); } ct.Receive(); }
private void Update() { if (ct.receiveMessage != null) { Debug.Log("Server:" + ct.receiveMessage); ct.receiveMessage = null; } if (Input.GetKeyDown("w")) { StartCoroutine(keySend("w")); } if (Input.GetKeyDown("a")) { StartCoroutine(keySend("a")); } if (Input.GetKeyDown("s")) { StartCoroutine(keySend("s")); } if (Input.GetKeyDown("d")) { StartCoroutine(keySend("d")); } ct.Receive(); }
private void Update() { if (ct != null) { c_btn.interactable = !ct.clientSocket.Connected; if (ct.receiveMessage != null) { Debug.Log("Server:" + ct.receiveMessage); chatmsg += ct.receiveMessage + Environment.NewLine; Chatbox.text = chatmsg; ct.receiveMessage = null; } ct.Receive(); } lock (mThreadTaskOnMain) { if (mThreadTaskOnMain.Count < 1) { return; } // 取出 var task = mThreadTaskOnMain.Dequeue(); // 執行 task(); } }
private void Update() { if (!ct.begin_flag) { if (!ct.rec) { ct.Receive(); } } if (ct.receiveMessage != null) { Debug.Log("Server:" + ct.receiveMessage); ct.receiveMessage = null; } /*if (ct.receive_joint != null) * { * Debug.Log("Server:" + ct.receive_joint); * ct.receive_joint = null; * }*/ if (ct.recieve_flag != 0) { //Debug.Log("Server:" + ct.frame_size.ToString()); if (ct.frame_img.Length != ct.dataLength_frame) { Debug.Log("Receive : " + ct.frame_img.Length.ToString() + ", len : " + ct.dataLength.ToString()); } Mat mat_img = new Mat(1, ct.frame_img.Length, CvType.CV_8U); mat_img.put(0, 0, ct.frame_img); Mat frame_img_mat = Imgcodecs.imdecode(mat_img, 1); Imgproc.cvtColor(frame_img_mat, frame_img_mat, Imgproc.COLOR_BGR2RGB); //Debug.Log(frame_img_mat.size()); byte[] image = new byte[252 * 448 * 3]; frame_img_mat.get(0, 0, image); var texture = rawImage.texture as Texture2D; texture.LoadRawTextureData(image); //TODO: Should be able to do this: texture.LoadRawTextureData(pointerToImage, 1280 * 720 * 4); texture.Apply(); ct.recieve_flag = 0; ct.rec = false; } }
private void Update() { if (ct.receiveMessage != null) { GameObject.Find("Canvas/Textbox").GetComponent <UnityEngine.UI.Text>().text = "Server:" + ct.receiveMessage; Debug.Log("Server:" + ct.receiveMessage); ct.receiveMessage = null; } if (isSend == true) { StartCoroutine(delaySend()); } ct.Receive(); }
private void Update() { ct.Receive(); if (ct.receiveMessage != null) //***** Update 'actual angle' ***** /// W/out protect yet! { string[] recv_msg = ct.receiveMessage.Split(','); //用逗號分割字串; using System; //string[] recv_msg = ct.receiveMessage.Split (new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); //用逗號分割字串; using System; ////Debug.Log ("Recv raw:" + ct.receiveMessage); if (recv_msg.Length > 6) { for (int i = 0; i < 6; i++) { theta_tar_a [i] = -float.Parse(recv_msg [i]) + theta_0 [i]; //Convert: string -> float } theta_tar_a [6] = float.Parse(recv_msg [6]); //update actual Gripper status } else { Debug.Log(" ![ERROR]! : recv_msg.Length = " + recv_msg.Length); } /*Debug.Log ("recv_msg.Length = " + recv_msg.Length); * for(int x=0; x<recv_msg.Length; x++) * Debug.Log (x + " ~ " + recv_msg [x]); */ ct.receiveMessage = null; } if (isSend == true) //***** Send 'target angle' to PC ***** //0509 { for (int i = 0; i < 6; i++) { theta_user [i] = -(Robot_jR.theta_tar [i] - theta_0 [i]); } StartCoroutine(SendTargetAngle()); //延遲發送訊息 //0508 Pick&Place /*if (devider % 5000 == 0) { //-----0508 Following----- * StartCoroutine (SendTargetAngle ());//延遲發送訊息 * devider = 0; * } else { * devider++; * }*/ } }
private void Update() { if (ct.receiveMessage != null) //***** Update 'actual angle' /// W/out protect yet! { string[] recv_msg = ct.receiveMessage.Split(','); //用逗號分割字串; using System; //string[] recv_msg = ct.receiveMessage.Split (new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); //用逗號分割字串; using System; Debug.Log("ct.receiveMessage:" + ct.receiveMessage); if (recv_msg.Length > 6) { for (int i = 0; i < 6; i++) { theta_tar_a [i] = -float.Parse(recv_msg [i]) + theta_0[i]; //Convert: string -> float } } else { //Debug.Log ("ct.receiveMessage ERROR: " + ct.receiveMessage); Debug.Log("ct.receiveMessage ERROR: recv_msg.Length = " + recv_msg.Length); } ct.receiveMessage = null; Debug.Log("recv_msg : " + recv_msg[0] + " // "); } if (isSend == true) //***** Send 'target angle' to PC { for (int i = 0; i < 6; i++) { theta_user [i] = -(Robot_jR.theta_tar [i] - theta_0 [i]); } /* * targetAngle[0] = 0; //range: ( -159.93 ~ +159.97 ) ; bound: +- 150 deg * targetAngle[1] = 0; //range: ( -45 ~ +93.71 ) ; bound: +- 40 deg * targetAngle[2] = 90; //range: ( +50.09 ~ +169.89 ) ; bound: +- 35 deg * targetAngle[3] = -25; //range: ( -159.87 ~ +138.11 ) ; bound: +- 130 deg * targetAngle[4] = 0; //range: ( -119.97 ~ +119.9 ) ; bound: +- 115 deg * targetAngle[5] = 0; //range: ( -199.88 ~ +200 ) ; bound: +- 190 deg */ SendTargetAngle(); } ct.Receive(); // -------------------------------------------------- // for (int i = 0; i < 6; i++) { dtheta_a [i] = theta_tar_a [i] - theta_now_a [i]; } joint1_a.transform.RotateAround(Vector3.zero, Vector3.up, dtheta_a [0]); joint2_a.transform.Rotate(Vector3.up, dtheta_a [1]); joint3_a.transform.Rotate(Vector3.up, dtheta_a [2]); joint4_a.transform.Rotate(Vector3.up, dtheta_a [3]); joint5_a.transform.Rotate(Vector3.up, dtheta_a [4]); joint6_a.transform.Rotate(Vector3.up, dtheta_a [5]); for (int i = 0; i < 6; i++) //refresh: after rotate { theta_now_a [i] = theta_tar_a [i]; } Debug.Log("~ theta_now_a = ( " + theta_now_a[0] + ", " + theta_now_a[1] + ", " + theta_now_a[2] + ", " + theta_now_a[3] + ", " + theta_now_a[4] + ", " + theta_now_a[5] + ")\n"); Debug.Log("~ theta_tar_a = ( " + theta_tar_a[0] + ", " + theta_tar_a[1] + ", " + theta_tar_a[2] + ", " + theta_tar_a[3] + ", " + theta_tar_a[4] + ", " + theta_tar_a[5] + ")\n"); Debug.Log("~~ theta_tar = ( " + Robot_jR.theta_tar[0] + ", " + Robot_jR.theta_tar[1] + ", " + Robot_jR.theta_tar[2] + ", " + Robot_jR.theta_tar[3] + ", " + Robot_jR.theta_tar[4] + ", " + Robot_jR.theta_tar[5] + ")\n"); Debug.Log("~ theta_user = ( " + theta_user[0] + ", " + theta_user[1] + ", " + theta_user[2] + ", " + theta_user[3] + ", " + theta_user[4] + ", " + theta_user[5] + ")\n\n"); }