private void SendCommand(byte[] cmd, uint expectCnt, bool writeLog = true) { bool connected = robot.isConnected; cmd[8] = UTIL.CalUBTCheckSum(cmd); cmd[9] = 0xED; if (writeLog) { AppendLog("\n" + (connected ? ">> " : "") + UTIL.GetByteString(cmd) + "\n"); } robot.ClearRxBuffer(); if (connected) { robot.SendCommand(cmd, 10, expectCnt); if (writeLog) { string msg = "<< "; if (robot.Available > 0) { byte[] result = robot.PeekAll(); msg += UTIL.GetByteString(result); } AppendLog(msg); } } }
private bool GetCommand(out byte[] command) { string sCommand = txtCommand.Text.Trim(); command = new byte[10]; try { Regex rx = new Regex("\\s+"); string input = rx.Replace(sCommand, " "); string[] sData = input.Split(' '); command[0] = 0xFA; command[1] = 0xAF; for (int i = 0; i < 6; i++) { if (i < sData.Length) { command[2 + i] = UTIL.GetInputByte(sData[i]); } else { command[2 + i] = 0x00; } } if (command[3] == 0x01) { if (command[5] > command[7]) { command[7] = command[5]; } } command[8] = UTIL.CalUBTCheckSum(command); command[9] = 0xED; txtPreview.Text = UTIL.GetByteString(command); } catch (Exception) { txtPreview.Text = ""; return(false); } return(true); }