// private bool DoWaitReadyStatus() // { // var st = DateTime.Now; // // while (true) // { // Thread.Sleep(100); // // byte[] ret; // // if (PortDataComm.SendCommand(0x66, out ret) != PortDataComm.CommandStatus.OK || ret == null || ret.Length != 1) // { // SetStatus(-1, 0, 1); // return false; // } // // if (ret[0] == 1) return true; // // if ((DateTime.Now - st).TotalSeconds > 30) // { // SetStatus(-2, 0, 1); // return false; // } // } // } // private bool SendChunk(ref int startFrom) { var len = Math.Min(ProgramCode.Length - startFrom, 32); if (len == 0) { return(true); } var pbuff = new byte[len + 5]; Array.Copy(BitConverter.GetBytes(startFrom), 0, pbuff, 0, 4); Array.Copy(ProgramCode, startFrom, pbuff, 4, len); pbuff[len + 4] = 0; pbuff[len + 4] = pbuff.Aggregate <byte, byte>(0, (current, b1) => (byte)(current ^ b1)); byte[] ret; if (PortDataComm.SendLongRunCommand(0x67, out ret, 500, pbuff) != PortDataComm.CommandStatus.OK || ret == null || ret.Length != 1) { SetStatus(-3, 0, 1); return(false); } startFrom += len; return(true); }
private bool DoErasePrepareCommand() { Thread.Sleep(100); byte[] ret; if (PortDataComm.SendLongRunCommand(0x61, out ret, 5000) != PortDataComm.CommandStatus.OK || ret == null || ret.Length != 1 || ret[0] != 1) { SetStatus(-2, 0, 1); return(false); } return(true); }