public void SendCommand(ToolWrench toolwrench) { this.PsetID = toolwrench.PsetId; //dData = new List<DesoutterData>() //{ // new DesoutterData(20,1,0,""), // new DesoutterData(23, 18, 0, PsetID.ToString().PadLeft(3, '0')), // new DesoutterData(20, 60, 1, "") // // n,ew DesoutterData(20,62,1,"") //}; ////开始连接 //DesoutterProtocol desoutterProtocol = new DesoutterProtocol(20, 1, 0, ""); //byte[] bb = desoutterProtocol.GetProtocol(); //Thread.Sleep(500); //SendData(new DesoutterData(20, 43, 1, "")); Thread.Sleep(500); SendedData = new DesoutterData(20, 1, 0, ""); SendData(SendedData); Thread.Sleep(500); SendData(new DesoutterData(20, 43, 1, "")); Thread.Sleep(500); SendedData = new DesoutterData(23, 18, 0, PsetID.ToString().PadLeft(3, '0')); SendData(SendedData); Thread.Sleep(500); SendedData = new DesoutterData(20, 60, 1, ""); SendData(SendedData); }
private void SendData(DesoutterData PsetData, bool isHandler = true) { byte[] senddata = PsetData.GetDesoutterData(); if (isHandler) { //发送事件通知 ReciveEventArgs asEventArgs = new ReciveEventArgs(senddata); SendHandler(this, asEventArgs); } client.SendData(senddata); }
private void byteToObj(byte[] data) { DesoutterData ddata = new DesoutterData(); //返回数据解密 try { ddata.SetDesoutterEntity(data); RdataSend(ddata); int dDataLen = Convert.ToInt32(ddata.Length) + 1; if (data.Length > dDataLen) { byte[] otherData = data.ToList().Skip(dDataLen).ToArray(); byteToObj(otherData); } } catch (Exception ex) { LogUtil.WriteLog(typeof(OpenProtocol), "byteToObj" + ex.Message); } }
public void timer_Elapsed(object obj) { var keepAliveData = new DesoutterData(20, 9999, 0, ""); SendData(keepAliveData); }
private void RdataSend(DesoutterData ddata) { switch (ddata.MID) { //case "0002": // { // Thread.Sleep(500); // SendedData = new DesoutterData(23, 18, 0, PsetID.ToString().PadLeft(3, '0')); // SendData(SendedData); // } // break; //case "0004": // { // if (ddata.DataField.Contains("0001")) // { // Thread.Sleep(500); // SendedData = new DesoutterData(23, 18, 0, PsetID.ToString().PadLeft(3, '0')); // SendData(SendedData); // } // } // break; //case "0005": // { // if (ddata.DataField == "0018") // { // Thread.Sleep(500); // SendedData = new DesoutterData(20, 60, 1, ""); // SendData(SendedData); // } // } // break; case "0061": { // send = true; byte[] resutData = Encoding.ASCII.GetBytes(ddata.DataField); byte TighteningStatus = resutData[106 - 21 + 2]; //数组第106位-107位为 09 标志,108位为状态 byte[] Torque = new byte[6]; Buffer.BlockCopy(resutData, 141 - 21, Torque, 0, 6); byte[] Angle = new byte[5]; Buffer.BlockCopy(resutData, 170 - 21, Angle, 0, 5); double RealTor = Convert.ToInt32(Encoding.ASCII.GetString(Torque)) / 100.00; int realAng = Convert.ToInt32(Encoding.ASCII.GetString(Angle)); TestResult testResult = new TestResult() { RealTar = RealTor.ToString(), RealAgi = realAng.ToString(), AddDate = DateTime.Now }; if (TighteningStatus == 0x31) { testResult.IsOk = true; } else { testResult.IsOk = false; } string requestData = JsonConvert.SerializeObject(testResult); ReciveEventArgs asEventArgs = new ReciveEventArgs(Encoding.ASCII.GetBytes(requestData)); RequestHandler(this, asEventArgs); SendData(new DesoutterData(20, 62, 1, "")); //Thread.Sleep(500); //SendData(new DesoutterData(20, 42, 1, "")); } break; default: //SendData(SendedData); break; } }