110,529
社区成员
发帖
与我相关
我的任务
分享
private void button3_Click(object sender, EventArgs e)
{
if (richTextBox2.Text == "")
{
MessageBox.Show("请检查输入!");
}
byte[] a = System.Text.Encoding.Default.GetBytes(richTextBox2.Text);
byte[] b = new byte[data.Length + 5];
a.CopyTo(buf, 3);
int count = a.Length;
buf[0] = 0;
buf[1] = Convert.ToByte(count);
Byte fcs = buf[1];
for (int i = 2; i <= count; i++)
{
buf[i] = a[i - 2];
fcs ^= Convert.ToByte(buf[i]);
}
buf[a.Length + 3] = fcs;
buf[a.Length + 4] = Convert.ToByte("FF", 16);
this.serialPort1.Write(buf, 0, a.Length+5);
}