当前位置: 首页 > news >正文

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脉冲

http://www.lryc.cn/news/395289.html

相关文章:

  • 【入门篇】STM32寻址范围(更新中)
  • DDD架构
  • Open3D KDtree的建立与使用
  • C语言编程3:运算符,运算符的基本用法
  • 如何通过SPI机制去实现读取配置文件并动态加载对应实现类
  • 双链表(数组模拟)
  • ChatGPT 5.0:一年半后的展望与看法
  • 城市地下综合管廊物联网远程监控
  • VS 附加进程调试
  • 核函数的深入理解
  • 使用Ckman部署ClickHouse集群介绍
  • 「前端工具」postman接口测试工具详解
  • 生成requirements.txt
  • ubuntu ceph部署
  • 2024.7.8
  • Spring 外部jar包Bean自动装配
  • 2通道音频ADC解码芯片ES7243L、ES7243E、ES7243,用于低成本实现模拟麦克风转换为IIS数字话筒
  • uniapp跨域问题解决
  • [C++][ProtoBuf][Proto3语法][一]详细讲解
  • 千古雄文《渔樵问对》原文、译文、解析
  • uniapp 开发备忘录-防坑指南
  • Simple_ReAct_Agent
  • window wsl安装ubuntu
  • postmessage()在同一域名下,传递消息给另一个页面
  • 初始redis:在Ubuntu上安装redis
  • 生物素结合金纳米粒子(Bt@Au-NPs ) biotin-conjugated Au-NPs
  • LeetCode热题100刷题9:25. K 个一组翻转链表、101. 对称二叉树、543. 二叉树的直径、102. 二叉树的层序遍历
  • PyJWT,一个基于JSON的轻量级安全通信方式的python库
  • Golang | Leetcode Golang题解之第223题矩形面积
  • 新手怎么使用GitLab?