none
现在TEXT 控件上显示接收到的是数字,如何进行判断下,让TEXT显示字符呢? RRS feed

  • 问题

  • 哈喽,哈喽

           亲爱的朋友们,过来啦

          我现在接受了一串数字,但是我想做一个判断,就是当S= {0x02,0x30,0x30,0x46,0x46,0x30,0x03}时,TEXT上显示,马达正在原点中,这应该如何写代码呢?

     private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
            {
               
    
                string B01 = "马达正在原点中";
                //string B02 = "";
               /* byte[] data = Convert.FromBase64String(serialPort1.ReadLine());
                textBox1.Text = Encoding.Unicode.GetString(data);*/
                serialPort1.DataReceived  +=  new SerialDataReceivedEventHandler(serialPort1_DataReceived);
                string s = "";
                int count = serialPort1.BytesToRead;
                byte[] data = new byte[count];
                serialPort1.Read(data, 0, count);
                foreach (byte item in data)
                {
    
                    s += Convert.ToString(item);
                    //B02 += Convert.ToString(item);
    
                }
             
                this.Invoke(new MethodInvoker(delegate { this.textBox1.Text = s; }));

    2018年1月11日 8:42

答案

全部回复