system.indexOutOfRangeException索引超出了数组界限
有大神能帮我解决一下问题吗我不知道这样复制出来对不对privatevoidbutton7_Click(objectsender,EventArgse){bytechaxu...
有大神能帮我解决一下问题吗
我不知道这样复制出来对不对
private void button7_Click(object sender, EventArgs e)
{
byte chaxun;
char[] xinxi = new char[16];
for (int i = 0; i < 50; i++)
{
Wrbuffer[i] = 0;
}
Wrbuffer[0] = 0x07;
Wrbuffer[1] = 0x02;
Wrbuffer[2] = 0x47;
Wrbuffer[3] = 0x01;
Wrbuffer[4] = ((byte)Convert.ToInt32(textBox2.Text));
Wrbuffer[5] = bcccode(Wrbuffer, 5);
Wrbuffer[6] = 0x03;
sp.Write(Wrbuffer, 0, 17);
sp.Read(Rdbuffer, 0, 1);
if (Rdbuffer[0] == 0x16)
{
for (int i = 1; i < 0x16; i++)
{
sp.Read(Rdbuffer, i, 1);
textBox1.Text = "查询成功。";
chaxun = Rdbuffer[4];
for (i = 0; i < chaxun; i++)
{
xinxi[i] = (char)Rdbuffer[5 + i];
}
string str = new String(xinxi);
label14.Text = textBox5.Text;
sp.DiscardInBuffer();
}
}
else
{
textBox1.Text = "查询失败!";
sp.DiscardInBuffer();
}
} 展开
我不知道这样复制出来对不对
private void button7_Click(object sender, EventArgs e)
{
byte chaxun;
char[] xinxi = new char[16];
for (int i = 0; i < 50; i++)
{
Wrbuffer[i] = 0;
}
Wrbuffer[0] = 0x07;
Wrbuffer[1] = 0x02;
Wrbuffer[2] = 0x47;
Wrbuffer[3] = 0x01;
Wrbuffer[4] = ((byte)Convert.ToInt32(textBox2.Text));
Wrbuffer[5] = bcccode(Wrbuffer, 5);
Wrbuffer[6] = 0x03;
sp.Write(Wrbuffer, 0, 17);
sp.Read(Rdbuffer, 0, 1);
if (Rdbuffer[0] == 0x16)
{
for (int i = 1; i < 0x16; i++)
{
sp.Read(Rdbuffer, i, 1);
textBox1.Text = "查询成功。";
chaxun = Rdbuffer[4];
for (i = 0; i < chaxun; i++)
{
xinxi[i] = (char)Rdbuffer[5 + i];
}
string str = new String(xinxi);
label14.Text = textBox5.Text;
sp.DiscardInBuffer();
}
}
else
{
textBox1.Text = "查询失败!";
sp.DiscardInBuffer();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询