コード例 #1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            if (UDP.Connected)
            {
                // Envia os dados como um array de bytes, devem ser separados por espaço
                if (chkHex.Checked)
                {
                    //
                    string[] bytesASCII = txtComando.Text.Split(' ');
                    //
                    byte        result;
                    List <byte> listBytes = new List <byte>();
                    // Cria a lista de bytes para enviar.
                    foreach (var item in bytesASCII)
                    {
                        //
                        if (byte.TryParse(item, NumberStyles.HexNumber, null, out result))
                        {
                            listBytes.Add(result);
                        }
                    }

                    // Mostra o que foi enviado.
                    txtReport.AppendText("\r\nByte:");
                    foreach (var item in listBytes)
                    {
                        txtReport.AppendText(string.Format(" {0:X2}", item));
                    }

                    UDP.Send(listBytes.ToArray());
                }
                // Envia como string em formato ASCII
                else
                {
                    //
                    txtReport.AppendText(string.Format("\r\nString: {0}", txtComando.Text));
                    //
                    UDP.Send(txtComando.Text);
                }
            }
            else
            {
                // Aviso de conectar!
            }
        }
コード例 #2
0
    public Proxy()
    {
        OnRecv += (object s, ServerMsgEventArgs e) =>
        {
            Debug.Log("Proxy received " + e.Len + " bytes");
            p.Send(e.Buffer, e.Len);
        };

        p.Start("127.0.0.1", 33334);
    }
コード例 #3
0
        private async void Search_TCP232()
        {
            // Classe usada para listar o ARP (Todos os IP's registrados no gateway)
            ArpHelper arp = new ArpHelper();

            // Gera a lista ARP com IPs, MACs e Types dos Equipamentos Registrados na Rede.
            listArp = arp.GetArpResult();
            //
            byte[] searchCommand = { 0xFF, 0x01, 0x01, 0x02 };
            //
            byte[] basicCommmand = { 0x55, 0xC6 };

            //
            lstListDevices.Items.Clear();
            // Roda a lista ARP enviando o comando de "Search" na porta 1901.
            foreach (var device in listArp)
            {
                lstListDevices.Items.Add(GetListViewItem(device));

                // Conecta via UDP ao Device
                UDP.Connect(device.Ip, 1901, 1901);
                //
                UDP.DataReceivedInBackGround += UDP_DataReceivedInBackGround;
                // Envia um comando de busca, caso o device responda corretamente, então trata-se de um módulo USR-TCP232
                UDP.Send(searchCommand);
                //
                await Task.Delay(800);

                //
                UDP.DataReceivedInBackGround -= UDP_DataReceivedInBackGround;
                //
                UDP.Disconnect();
                //
                await Task.Delay(50);
            }
        }