您的位置:首页 > 科技 > 能源 > 2.5 C#视觉程序开发实例1----IO_Manager实现切换程序

2.5 C#视觉程序开发实例1----IO_Manager实现切换程序

2024/10/6 6:51:04 来源:https://blog.csdn.net/weixin_42490025/article/details/140216112  浏览:    关键词:2.5 C#视觉程序开发实例1----IO_Manager实现切换程序

2.5 C#视觉程序开发实例1----IO_Manager实现切换程序

1 IO_Manager中输入实现

1.0 IO_Manager中输入部分引脚定义
// 设定index 目的是为了今后可以配置这些参数、
// 输入引脚定义
private int index_trig0 = 0; // trig index
private int index_cst = 7; //cst index
private int[] index_ProNO = new int[8];// 程序号indexfor (int i = 0; i < 8; i++)index_ProNO[i] = 8 + i;
1.1 IO_Manager中获取Trig0 信号
public  bool get_Trig0()
{return Inputs[index_trig0];
}
1.2 IO_Manager中获取Pro_NO
public ushort get_ProgramNO()
{ushort Pro_no = 0;if (Inputs[index_ProNO[0]]) Pro_no += 1;if (Inputs[index_ProNO[1]]) Pro_no += 2;if (Inputs[index_ProNO[2]]) Pro_no += 4;if (Inputs[index_ProNO[3]]) Pro_no += 8;if (Inputs[index_ProNO[4]]) Pro_no += 16;if (Inputs[index_ProNO[5]]) Pro_no += 32;if (Inputs[index_ProNO[5]]) Pro_no += 64;if (Inputs[index_ProNO[6]]) Pro_no += 128;return Pro_no;
}
1.3 IO_Manager中获取Pro_CST程序切换信号
public bool get_CST()
{return Inputs[index_cst];
}

2 IO_Manager中输出实现

2.0 IO_Manager中输出部分引脚定义
// 输出引脚定义private int index_online = 0;// 联机信号private int index_sto = 1;// STO 输出private int index_ok = 2;// OK输出private int index_ng = 3;// NG输出private int index_CST_Acomm = 7;// 程序切换成功
2.1 IO_Manager中输出CST_AComm
public void Out_CST_AComm(bool state)
{lock (_mutex){Outputs[index_CST_Acomm] = state;}
}
2.2 IO_Manager中输出Online信号
public void Out_Onlie(bool state)
{lock(_mutex){Outputs[index_online] = state;}
}

3 Form_vision 主程序中添加代码实现程序号切换和相机触发

3.0 添加program_no 变量
/// <summary>/// 当前程序号/// </summary>public int program_No = 0
3.1 IO_Circle中实现程序号的切换和CST_Acom的返回
 private void IO_Circle()
{bool pro_cst_cur = false;bool pro_cst_last = false;while (true){ // readInputs// writeOutputs System.Threading.Thread.Sleep(20);ContextManager.get_IOCtx().Read();ContextManager.get_IOCtx().Write();//更新程序号// CST  Accom 信号  pro_cst_cur = ContextManager.get_IOCtx().get_CST();if (pro_cst_cur && !pro_cst_last)  //判断上升沿触发{program_No = ContextManager.get_IOCtx().get_ProgramNO();//toDO 代码,程序切换ContextManager.get_IOCtx().Out_CST_AComm(true); } pro_cst_last = pro_cst_cur;// CST_AComm 复位if(!pro_cst_cur)ContextManager.get_IOCtx().Out_CST_AComm(false);if (StopProgramEvent.WaitOne(0, true)) break;}//end while  
}
3.2 Timer_Ticker中实现当前程序号的更新显示
private void timer1_Tick(object sender, EventArgs e)
{/// 更新程序号到控件Util_Helper.Set_NumberControl_Value(num_programNO, program_No);iO_Monitors1.update_status(true,true);
}

4 效果展示

4.1 IO_Client.exe先准备好程序号31到端口上

在这里插入图片描述

4.2 IO_Client.exe 输出CST 信号

Vision 接受到CST上升沿后,立刻执行程序切换,并且输出CST_Acomm信号给IO_Client
在这里插入图片描述

4.2 IO_Client.exe 接收到CST_AComm信号后, 复位 CST信号 ,Vision也会复位CST_Acomm

在这里插入图片描述

5 下一章节 我们会重点讲获取一次相机采集信号和输出一个STO脉冲

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com