前台我放了一个SerialPort控件 id是sp1;
还放了一个按钮,id是button1
button1点击事件是:
try
{
sp1.ReadTimeout = 3000;
sp1.PortName="com1";
sp1.BaudRate=9600;
sp1.DataBits=8;
sp1.Open();
tb_data.Text = sp1.IsOpen.ToString();
string temp=sp1.ReadLine();
sp1.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
我用另一台仪器通过com1传数据近来,怎么传不进来啊??提示错误超时(sp1.IsOpen()的值是true)我郁闷了当我在button1的事件里把接受改为发送的时候
string temp=sp1.ReadLine(); 换成 sp1.Write("fly")
仪器那边有反应这是怎么回事呀?
还放了一个按钮,id是button1
button1点击事件是:
try
{
sp1.ReadTimeout = 3000;
sp1.PortName="com1";
sp1.BaudRate=9600;
sp1.DataBits=8;
sp1.Open();
tb_data.Text = sp1.IsOpen.ToString();
string temp=sp1.ReadLine();
sp1.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
我用另一台仪器通过com1传数据近来,怎么传不进来啊??提示错误超时(sp1.IsOpen()的值是true)我郁闷了当我在button1的事件里把接受改为发送的时候
string temp=sp1.ReadLine(); 换成 sp1.Write("fly")
仪器那边有反应这是怎么回事呀?
我用了接受事件 private void sp1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
MessageBox.Show("hello");
tb_data.Text= e.ToString();
sp1.Close();
}可是tb_data的内容没有变哦 ...
是不是我需要触发这个 事件?怎么触发?
BUFF只要有数据就会触发此事件的
不用人为追加的
1)你怎么接收完了就关端口?
2)9600 正确吗?
3)有的设备 需要开启串口控件的dtr rts