/// <summary> /// 读整模块参数 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="data"></param> /// <param name="structure"></param> /// <param name="step"></param> /// <param name="count"></param> public void ReadRegister <T>(BaseData data, Object structure, ref int step, ref int count) { switch (step) { case 0: ushort number = (ushort)(BytesConverter.ObjToBytes(structure).Length / 2); ushort address = data.Address; data = new BaseData(address, number, DataType.Byte); ReadRegister(data); step = 1; break; case 1: if (data.Succeed) { structure = BytesConverter.BytesToObj <T>(data.ByteValue); } else if (Succeed) { count++; if (count > 15) { count = 0; step = 0; } } break; default: break; } }
public bool exe(int type, float xPos, float yPos, float zPos, float rPos, float tPos, SolderDef solderDef, int Rinse) { switch (StartStep) { case 0: List <byte> temp = new List <byte>(); temp.AddRange(Functions.NetworkBytes(1)); temp.AddRange(Functions.NetworkBytes(type)); temp.AddRange(Functions.NetworkBytes(1)); temp.AddRange(Functions.NetworkBytes(xPos)); temp.AddRange(Functions.NetworkBytes(yPos)); temp.AddRange(Functions.NetworkBytes(zPos)); temp.AddRange(Functions.NetworkBytes(rPos)); temp.AddRange(Functions.NetworkBytes(tPos)); byte[] aaa = BytesConverter.ObjToBytes(solderDef); byte[] tempdata = temp.ToArray(); byte[] _rinsedata = BitConverter.GetBytes(Rinse); for (int i = 0; i < _rinsedata.Length; i++) { if (i % 2 == 0) { byte rdata = _rinsedata[i]; _rinsedata[i] = _rinsedata[i + 1]; _rinsedata[i + 1] = rdata; } } byte[] ndata = new byte[tempdata.Length + aaa.Length + _rinsedata.Length]; tempdata.CopyTo(ndata, 0); aaa.CopyTo(ndata, tempdata.Length); _rinsedata.CopyTo(ndata, tempdata.Length + aaa.Length); CommData = new BaseData(Addr, ndata); movedriverZm.WriteRegister(CommData); StartOT.Restart(); StartStep = 1; return(false); case 1: if (CommData.Succeed == true) { StartStep = 0; CommData.Succeed = false; if (Addr == 4400) { FormMain.RunProcess.LogicData.RunData.leftSoldertintimes++; } else { FormMain.RunProcess.LogicData.RunData.rightSoldertintimes++; } return(true); } if (StartOT.ElapsedMilliseconds > 10000) { StartStep = 0; } return(false); default: StartStep = 0; CommData.Succeed = false; return(false); } }