2014-03-13 27 views
0

數據接收的輸出http://postimg.org/image/5hvqgosc7/我可以將從串行端口收到的數據轉換爲只有空格和符號的數字嗎?

這是RFID標籤號碼的字符串顯示。 這真的是一個顯示所有rfid或我可以改變它顯示數字只有沒有空格和符號?

或者在我的代碼中有問題。

這是我的代碼:

private void Form1_Load(object sender, EventArgs e) 
    { 
     cn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Thesis\Desktop\Projects\Employees.accdb;Persist Security Info=True"; 
     cmd.Connection = cn; 
     this.myDelegate = new AddDataDelegate(AddDataMethod); 
     rfidbox.Enabled = true; 

     string[] ports = SerialPort.GetPortNames(); 
     foreach (string port in ports) 
     { 
      SerialPort mySerialPort = new SerialPort(port); 
      mySerialPort.BaudRate = 9600; 
      mySerialPort.Parity = Parity.None; 
      mySerialPort.StopBits = StopBits.One; 
      mySerialPort.DataBits = 8; 
      mySerialPort.ReadTimeout = 3000; 
      mySerialPort.Handshake = Handshake.None; 

      mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler); 

      mySerialPort.Open(); 
     } 



    } 

    private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) 
    { 
     SerialPort sp = (SerialPort)sender; 
     string s = sp.ReadExisting(); 

     rfidbox.Invoke(this.myDelegate, new Object[]{s}); 

    } 

    public void AddDataMethod(String myString) 
    { 
     rfidbox.AppendText(myString); 


    } 

感謝提前的幫助。

回答

0

我會假設你的數據在ASCII值後面的幾個字節後面有一個二進制部分。您可能需要查閱有關數據結構的硬件文檔。如果部分是二進制的,您需要使用二進制讀取例程(如SerialPort.ReadByte()n次)並手動從字節組合字符串。字符串之後的字節需要根據含義來解釋;注意二進制整數的潛在字節順序問題,如果有的話包含在數據中。

+0

非常感謝你,我得到了主意上帝保佑 – user3410770

+0

呃:-))很高興能有所幫助。 –

相關問題