//串口指令 读写
SerialPort sp = new SerialPort(comname, 115200);
public byte[] SendCommand(byte[] buffer)
{
sp.DiscardInBuffer();
sp.DiscardOutBuffer();
sp.Write(buffer, 0, buffer.Length);
System.Threading.Thread.Sleep(50);
byte[] rb = new byte[sp.ReadBufferSize];
byte[] result = new byte[] { };
int loc = 0;
int l = 0;
do
{
l = sp.Read(rb, 0, sp.ReadBufferSize);
Array.Resize<byte>(ref result, result.Length + l);
Array.Copy(rb, 0, result, loc, l);
loc += l;
System.Threading.Thread.Sleep(50);
} while (sp.BytesToRead > 0);
return result;
}