private void Send(SerialPort sp, ECMD command, byte[] data) { if (command == ECMD.RADIO_PROTOCOL_SET) { Console.WriteLine("pset"); } if (data == null) { Send(sp, command, null, 0, 0); } else { Send(sp, command, data, 0, data.Length); } }
public void Send(SerialPort sp, ECMD command, byte[] data, int startidx, int length) { if (sp.IsOpen == false) { return; } byte[] packet; UInt16 size = (UInt16)length; UInt16 cmd = (UInt16)command; // {0: stx, 1: datasize, 3: command, 4:data, etx} if (data != null) { packet = new byte[6 + size]; Array.Copy(data, startidx, packet, 5, size); } else { packet = new byte[6]; size = 0; } // stx packet[0] = 0x02; // size packet[1] = BitConverter.GetBytes(size)[0]; packet[2] = BitConverter.GetBytes(size)[1]; // command packet[3] = BitConverter.GetBytes(cmd)[0]; packet[4] = BitConverter.GetBytes(cmd)[1]; // etx packet[size + 5] = 0x03; if (sp.IsOpen) { sp.Write(packet, 0, packet.Length); } }
public void AddSend(ECMD cmd, byte[] data) { _list_send.Add(new s_comstack(cmd, data)); }
public s_comstack(ECMD cmd, byte[] data) { this.cmd = cmd; this.data = data; }
public void SerialSend(ECMD cmd, byte[] dat) { _serial.AddSend(cmd, dat); }
public void SerialSend(ECMD cmd) { SerialSend(cmd, null); }