System.IO.Ports.SerialPort com ; private void Form1_Load(object sender, EventArgs e)
{
com = new System.IO.Ports.SerialPort("COM7", 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.Two);
com.Open();
} private void button1_Click(object sender, EventArgs e)
{
Byte[] buf = { 0x01, 0x03, 0x01, 0xF4, 0x00, 0x01, 0xC4, 0x04 };
com.Write(buf, 0, buf.Length);
textBox2.Text = buf.Length.ToString(); Byte[] readBuf = new Byte[512]; System.Threading.Thread.Sleep(1000) ;
int readlen = com.Read(readBuf, 0, readBuf.Length); if (readlen > 0)
{
string str = "", temp; for (int i = 0; i < readlen; i++)
{
temp = String.Format("{0:X2}", readBuf[i]);
str = str + temp + " ";
}
textBox1.Text = str;
}
}
我这样写了一帧报文 可是在没有仪器表的时候执行以下窗体就卡住了
这是问什么呢? 请高手赐教 谢谢
{
com = new System.IO.Ports.SerialPort("COM7", 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.Two);
com.Open();
} private void button1_Click(object sender, EventArgs e)
{
Byte[] buf = { 0x01, 0x03, 0x01, 0xF4, 0x00, 0x01, 0xC4, 0x04 };
com.Write(buf, 0, buf.Length);
textBox2.Text = buf.Length.ToString(); Byte[] readBuf = new Byte[512]; System.Threading.Thread.Sleep(1000) ;
int readlen = com.Read(readBuf, 0, readBuf.Length); if (readlen > 0)
{
string str = "", temp; for (int i = 0; i < readlen; i++)
{
temp = String.Format("{0:X2}", readBuf[i]);
str = str + temp + " ";
}
textBox1.Text = str;
}
}
我这样写了一帧报文 可是在没有仪器表的时候执行以下窗体就卡住了
这是问什么呢? 请高手赐教 谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货