예제 #1
0
        static void SendCommand(DQCommand myCommand, string Dest = null, int delay = 100)
        {
            byte[] data0 = BitConverter.GetBytes(myCommand.ID);
            byte[] data1 = BitConverter.GetBytes(myCommand.PublicKey);
            byte[] data2 = BitConverter.GetBytes(myCommand.Command);
            byte[] data3 = BitConverter.GetBytes(myCommand.Par1);
            byte[] data4 = BitConverter.GetBytes(myCommand.Par2);
            byte[] data5 = BitConverter.GetBytes(myCommand.Par3);
            byte[] data6 = Encoding.ASCII.GetBytes(myCommand.Payload);
            int    i;

            byte[] udpdata = new byte[data0.Length + data1.Length + data2.Length + data3.Length + data4.Length + data5.Length + data6.Length];

            i = 0;
            Buffer.BlockCopy(data0, 0, udpdata, i, data0.Length);
            i = i + data0.Length;
            Buffer.BlockCopy(data1, 0, udpdata, i, data1.Length);
            i = i + data1.Length;
            Buffer.BlockCopy(data2, 0, udpdata, i, data2.Length);
            i = i + data2.Length;
            Buffer.BlockCopy(data3, 0, udpdata, i, data3.Length);
            i = i + data3.Length;
            Buffer.BlockCopy(data4, 0, udpdata, i, data4.Length);
            i = i + data4.Length;
            Buffer.BlockCopy(data5, 0, udpdata, i, data5.Length);
            i = i + data5.Length;
            Buffer.BlockCopy(data6, 0, udpdata, i, data6.Length);

            IPEndPoint EndPoint;

            if (Dest == null)
            {
                EndPoint = new IPEndPoint(IPAddress.Broadcast, COMMAND_PORT);
            }
            else
            {
                EndPoint = CreateIPEndPoint(Dest);
            }


            UdpBroadcaster.EnableBroadcast = true;

            UdpBroadcaster.Send(udpdata, udpdata.Length, EndPoint);

            System.Threading.Thread.Sleep(delay);
        }
예제 #2
0
 private void Send2Device(DQCommand dq)
 {
     SendCommand(dq, DestIP.Text + sync1.Text + ":51235");
 }