C#串口发送数据问题,字节数组
未知昵称 2017-11-23 06:08:53 private void bntSendFile_Click(object sender, EventArgs e)
{
string fileName = txtFileName.Text.Trim();
if (fileName == "")
{
MessageBox.Show("请选择要发送的文件!", "Error");
return;
}
else
{
sRead = new StreamReader(fileName,Encoding.Default);//解决中文乱码问题
}
timer1.Start();
}
//发送文件时钟
private void timer1_Tick(object sender, EventArgs e)
{
string str1;
str1 = sRead.ReadLine();
if (str1 == null)
{
timer1.Stop();
sRead.Close();
MessageBox.Show("文件发送成功!", "C#串口通讯");
this.toolStripStatusLabel5.Text = "";
return;
}
byte[] data = Encoding.Default.GetBytes(str1);
sp.Write(data, 0, data.Length);
this.toolStripStatusLabel5.Text = " 文件发送中...";
}
以上是一段串口发送一个文件里面的内容。
现在需求如下,,,
现在想把文件的内容按照字节分数组,temp[0],temp[1],temp[2]..........
每个数组里面存放258个字节的内容。其中前两个字节是固定的
temp[0]={0xFF+0xB5+256字节_0},
确认收到回复FF B5 开始发送下一个temp[1]
temp[1]={0xFF+0xB6+256字节_1},
确认收到回复FF B6 开始发送下一个temp[2]
temp[2]={0xFF+0xB5+256字节_2},
确认收到回复FF B5 开始发送下一个temp[3]
temp[3]={0xFF+0xB6+256字节_3}
确认收到回复FF B6 开始发送下一个temp[4]
temp[4]={0xFF+0xB6+256字节_4}
...............................................
直到所有文里面的所有字节内容发送完毕。结束。