private void ProcStartSend(object obj) { int index = (int)obj; FrameUnit frameUnit = FrameManager.CreateFrameUnit(0x03); byte[] frameData = new byte[20]; int frameLength = 0; try { SerialManager.Send(new byte[] { 0x18, 0x01 }, 0, 2); Thread.Sleep(500); SerialManager.Send(new byte[] { 0x03, (byte)(index + 1) }, 0, 2); string txt = ""; if (frameUnit.WaitData(15000)) { frameLength = frameUnit.ReadTotalData(frameData, frameData.Length); if (frameData[7] == 0x81) //返回成功 { } } ShowSendEnd(txt); } catch (ThreadAbortException) { } finally { FrameManager.DeleteFrameUnit(frameUnit); } }
private void ProcVersion() { FrameUnit frameUnit = FrameManager.CreateFrameUnit(0x01); byte[] frameData = new byte[20]; int frameLength = 0; try { SerialManager.Send(new byte[] { 0x01, 0x00 }, 0, 2); string txt = ""; if (frameUnit.WaitData(2000)) { frameLength = frameUnit.ReadTotalData(frameData, frameData.Length); if (frameData[4] == 0x77) //返回成功 { txt = "版本:" + frameData[6] + "." + frameData[7] + " 日期:" + frameData[8] + "月" + frameData[9] + "日"; } } ShowVersion(txt); } catch (ThreadAbortException) { } finally { FrameManager.DeleteFrameUnit(frameUnit); } }
private void ProcReadParam(object obj) { int index = (int)obj; FrameUnit frameUnit = FrameManager.CreateFrameUnit(0x24); byte[] frameData = new byte[50]; int frameLength = 0; byte[] bitArray = new byte[12 * 8]; try { for (int i = 0; i < 3; i++) { SerialManager.Send(new byte[] { 0x24, (byte)(((index + 1) << 4) + (i + 1)) }, 0, 2); if (frameUnit.WaitData(2000)) { frameLength = frameUnit.ReadTotalData(frameData, frameData.Length); if (frameData[4] == 0x77) //查询成功 { //显示数据 if (frameData[7] == 0x60) //12*8Bit { Tool.ByteArray2BitArray(bitArray, frameData, 8, 12); int state = Tool.FieldValue(bitArray, 0); switch (state) { case 0x1c: tablePSD[index].Rows[i]["TrainState"] = "L"; break; case 0x26: tablePSD[index].Rows[i]["TrainState"] = "G"; break; case 0x52: tablePSD[index].Rows[i]["TrainState"] = "R"; break; default: tablePSD[index].Rows[i]["TrainState"] = "--"; break; } int fzk = Tool.FieldValue(bitArray, 1); tablePSD[index].Rows[i]["FZK"] = fzk.ToString(); int crew = Tool.FieldValue(bitArray, 2); tablePSD[index].Rows[i]["Crew"] = crew; int trip = Tool.FieldValue(bitArray, 3) + Tool.FieldValue(bitArray, 5) * 1000; tablePSD[index].Rows[i]["Trip"] = trip; int dst = Tool.FieldValue(bitArray, 4); tablePSD[index].Rows[i]["Dst"] = dst; int res = Tool.FieldValue(bitArray, 6); tablePSD[index].Rows[i]["Res"] = res.ToString(); int dir = Tool.FieldValue(bitArray, 7); switch (dir) { case 0: tablePSD[index].Rows[i]["Dir"] = "EAB"; break; case 1: tablePSD[index].Rows[i]["Dir"] = "A"; break; case 2: tablePSD[index].Rows[i]["Dir"] = "B"; break; case 3: tablePSD[index].Rows[i]["Dir"] = "AB"; break; } int err = Tool.FieldValue(bitArray, 8); tablePSD[index].Rows[i]["Err"] = err.ToString(); int carId = Tool.FieldValue(bitArray, 9); tablePSD[index].Rows[i]["CarID"] = carId; int inf = Tool.FieldValue(bitArray, 10); tablePSD[index].Rows[i]["ErrInf"] = inf; int mil = Tool.FieldValue(bitArray, 11); tablePSD[index].Rows[i]["Mil"] = mil; int tel = Tool.FieldValue(bitArray, 12); tablePSD[index].Rows[i]["TelID"] = tel.ToString(); } } } } ShowReadParamDone(""); } catch (ThreadAbortException) { } finally { } }