代码如下:按下按钮执行下面的方法,这个方法是和下位机通讯的,然后执行chooseChannel.Goto(response.StepId + 1, 30000) 的动作,但是因为下位机没有反馈,导致方法要等待整个动作完成,这就导致无法再次调用,必须等待完成。
现在就是我写了两个软件去执行这个动作,就可以达到连续执行的操作,只不过两个软件都是需要等待!这种情况,我想的是,是否可以动作执行,不等待它的反馈就结束动作,然后下次执行就继续调用!各位大神帮忙看看怎么更改!
private void button1_Click_1(object sender, EventArgs e)
{
thread = new Thread(new ParameterizedThreadStart(Jump));
thread.IsBackground = true;
NewareChannel chooseChannel = new NewareChannel(22, 19, 1, 1);
thread.Start(chooseChannel);
Thread.Sleep(100);
}
private void Jump(object obj)
{
lock (locker)
{
NewareChannel chooseChannel = (NewareChannel)obj;
try
{
Goto(chooseChannel);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
static NewareInquireResponse GetStepId(NewareChannel channel)
{
for (int i = 0; i < 4; i++)
{
NewareInquireResponse response = channel.Inquire(30000);
if (response.StepId > 0)
{
//Console.WriteLine("GetStepId end");
return response;
}
}
return new NewareInquireResponse();
//Console.WriteLine("GetStepId start");
}
private void Goto(NewareChannel chooseChannel)
{
NewareInquireResponse response = GetStepId(chooseChannel);
if (response.StepId == 0)
{
return;
}
if (response.WorkStatus != "working")
{
return;
}
for (int i = 0; i < 4; i++)
{
if (chooseChannel.Goto(response.StepId + 1, 30000))
{
break;
}
else
{
NewareInquireResponse response1 = GetStepId(chooseChannel);
if (response1.StepId == response.StepId + 1)
{
break;
}
}
}
}
标签:
我觉得得看那个下位机是否支持了,不知道和你说的下位机是什么。如果这个下位机把所有的命令放到一个队列,挨个执行就可以,如果这个下位机执行不过来把命令给丢掉了,那就再想办法了,需要一个机制判断命令到底执行了没有
最后通过更改接口程序,每次连接都采用建立新连接,待发送成功后,在接口程序上断开连接,下次连接再新建!