0
public partial class Form1 : Form
{
public delegate void AddDataDelegate(String myString);
public AddDataDelegate myDelegate;
string[] Tags;
public Form1()
{
InitializeComponent();
SerialPort RFID = new SerialPort();
RFID.PortName = "COM5";
RFID.BaudRate = 9600;
RFID.DataBits = 8;
RFID.Parity = Parity.None;
RFID.StopBits = StopBits.One;
RFID.Open();
RFID.DataReceived += new SerialDataReceivedEventHandler(RFID_DataReceived);
this.myDelegate = new AddDataDelegate(AddDataMethod);
}
public void AddDataMethod(String myString)
{
textBox1.AppendText(myString);
}
public void RFID_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort RFID = (SerialPort)sender;
int buffer = RFID.ReadBufferSize;
byte[] data = new byte[buffer];
RFID.Read(data, 0, buffer);
string s;
for (int i = 0; i < 18; i++)
{
s = Convert.ToString(data[i], 16);
//Console.WriteLine(Convert.ToString(data[i], 16));
textBox1.Invoke(this.myDelegate, new Object[] { s });
}
//Console.WriteLine(Convert.ToString(i,16));
//textBox1.Invoke(this.myDelegate, new Object[] { s });
}
上面的內容將數據打印到文本框中。如何創建每兩個字符的空格,並在每次掃描的數據之間留出一行。需要知道如何在每次掃描時在每兩個字符之間插入一個空格,並在每次掃描時在文本之間插入一行空格
經過三次掃描電流輸出:
00e203027313032180000000605641acff00000000000000e20302731301716606c200001b5ff00000000000000000e203027313000000000001716606c21b5ff000000000
然後輸出只是0.然後每次我掃描其0和一個新的行。 :( –
這表明'data'只包含一個元素,而這個元素是'0'(並且你可能已經將'18'改爲'buffer'。)什麼調試器顯示'data'內容? –