/// <summary> /// 解析从升降机发送到服务端的指令 /// </summary> private COMMAND_FROME2S readCommandFromE2S(byte[] response) { COMMAND_FROME2S outCommand = COMMAND_FROME2S.LIFT_OUT_COMMAND_MIN; int i = 0; for (i = 0; i < response.Length; i++) { if ((COMMAND_FROME2S)response[i] < COMMAND_FROME2S.LIFT_OUT_COMMAND_MAX && (COMMAND_FROME2S)response[i] > COMMAND_FROME2S.LIFT_OUT_COMMAND_MIN) { outCommand = (COMMAND_FROME2S)response[i]; } } if (outCommand != COMMAND_FROME2S.LIFT_OUT_COMMAND_MIN) { } return(outCommand); }
private void handleDataSerialPort() { try { int count; byte[] response = null; sp.Write(common, 0, 4); while (!isStop) { byte[] readBuffer = new byte[1]; count = sp.BytesToRead; if (count != 8) { Thread.Sleep(1000); continue; } response = new byte[count]; sp.Read(response, 0, count); outCommand = readCommandFromE2S(response); //如果读取到升降机异常, 不再向升降机发送命令 if (outCommand > COMMAND_FROME2S.LIFT_OUT_COMMAND_UP_DOWN) { AGVLog.WriteInfo("升降机异常 " + outCommand, new StackFrame(true)); continue; } if (dataCommand[0] > 0) //清空数据 { sendCommand(dataCommand); dataCommand[0] = 0; dataCommand[1] = 0; } Thread.Sleep(200); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); handleLiftComException(); } }