How to send and receive 1024 Bits?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marwanharb
    New Member
    • Mar 2015
    • 3

    How to send and receive 1024 Bits?

    hello, I'm designing an interface using windows Forums and I want to send and receive 1024 bits using serial port, the number is in the hex-form, so what I did is the next:

    Code:
      private void button2_Click(object sender, EventArgs e)
                {
                    int i;
                    int a=0;
                    byte[] mychar;
                    mychar = new byte[128];
                    string M = textBox1.Text;
    
                    for (i = 0; i < 127; i++ ) {
                    mychar[i] = Convert.ToByte((M.Substring(a,2)),16);
                    a += 2;
                    }
                    serialPort1.Write(mychar,0,127);
                }
    and to check if the data is correct or not, I shorted out both the transmitter and receiver so I can see what I send from textbox1 to be shown in textbox5, the problem is the textbox is shown the output as ASCII, and I couldn't tell how to convert it to Hex again ,(see my attempt as commented bellow):

    Code:
    private void displaytext(object s, EventArgs e)
            {
                
                textBox5.Clear();
                 textBox5.AppendText(RXstring);
    //int value = Convert.ToInt32(RXstring, 16);
                 //string stringValue = Char.ConvertFromUtf32(value);
                 //textBox4.AppendText(stringValue);
            }
    so to summarize my problems:
    1- Is the code to send data is correct?
    2- How can I force the textbox to show the output as Hex?

    thank you very much.
Working...