public byte[] downloadflash(short length)
{
if (!this.IsOpen)
{
throw new Exception("Port Not Open");
}
byte[] data = new byte[length];
this.ReadTimeout = 1000;
byte[] command = new byte[] { (byte)'t', (byte)(length >> 8), (byte)(length & 0xff), (byte)'F', (byte)' ' };
this.Write(command, 0, command.Length);
if (this.ReadByte() == 0x14)
{ // 0x14
int read = length;
while (read > 0)
{
//Console.WriteLine("offset {0} read {1}", length - read, read);
read -= this.Read(data, length - read, read);
//System.Threading.Thread.Sleep(1);
}
if (this.ReadByte() != 0x10) // 0x10
throw new Exception("Lost Sync 0x10");
}
else
{
throw new Exception("Lost Sync 0x14");
}
return data;
}