说来搞笑,这么简单的设置我搞了一两个小时,可能受单片机影响,总想写延时函数外加debug算时间。
我用的是vs用C#开发上位机
2.可以通过事件函数来实现修改
public void SetTime()
{
timer1.Enabled = true;//设置度为truetimer1_Tick实践就会执行,开始计时
timer1.Interval = 1000;//设置timer1的timer1_Tick实践执行周期为1000毫秒
}
private void timer1_Tick(object sender, EventArgs e)//每1000毫秒执行一次
{
MessageBox.Show("定时执行");//弹出对话框告诉你
timer1.Enabled = false;//不需要重复调用回
}
然后直接在timer处理事件中使用就好,一次触发就是你设置的时间。
private void timer1_Tick(object sender, EventArgs e)
{
if (Take_off_state == 1)
{
my_control = 1;
}
if (timecount < 1)
{
SendmgOnetakeoff(serialPort2, textBox2);
}
else if (timecount >= 1)
{
Sendmg(serialPort2, CH_filter_UGV1, textBox2);
Receive_Sendmg(serialPort1,textBox1);
}
timecount++;
}
评论已关闭