当前位置:网站首页>Implement the rising edge in C #, and simulate the PLC environment to verify the difference between if statement using the rising edge and not using the rising edge
Implement the rising edge in C #, and simulate the PLC environment to verify the difference between if statement using the rising edge and not using the rising edge
2022-07-05 10:43:00 【Lava of Rodinia】
PLC It can be thought that running in while The program in the loop (Ob100 With the exception of ), every last OB Each block is a separate thread . Understand this , It can be better C# Upper computer programming and PLC Of SCL(ST) Programming .
stay SCL in , If If The condition of the statement uses a long signal ,If The statement will be executed repeatedly , Some exchange values , Transfer value , The operation of updating the value cannot be completed , Now If The condition of the statement must use transient signals ,If The condition of using rising edge is a good choice .
Rising edge :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FPTest
{
public class R_TRIG
{
///
/// This attribute stores the last bool state ,get;private set; This is equivalent to PLC Of Output Interface
///
public bool Last {
get; private set; }
///
/// This attribute is filled with the detected bool The amount ,set; amount to PLC Of Input Interface
///
public bool CLK
{
set
{
Q = value && !Last;// We know that the rising edge is from 0 change 1 For a moment , Therefore, when this scan is true and the last one is false, a rising edge is generated
Last = value;// Refresh the reference bit every scanning cycle
}
}
///
/// This is the state of detection , External access to this variable will know whether the rising edge has been generated
/// amount to PLC Of Output Interface
public bool Q {
get; private set; }
}
}
Falling edge
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FPTest
{
public class F_TRIG
{
public bool Last {
get; private set; }
public bool CLK
{
set
{
Q = !value && Last;//1 change 0 Last time is true, this time is false
Last = value;
}
}
public bool Q {
get; private set; }
}
}
The main program
namespace FPTest
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
rTrig = new R_TRIG();
fTrig = new F_TRIG();
this.label1.Text = a.ToString();
this.label2.Text = b.ToString();
}
private R_TRIG rTrig;
private F_TRIG fTrig;
private int a = 0;
private int b = 0;
CancellationTokenSource cts = new CancellationTokenSource();
private void btnUp_Click(object sender, EventArgs e)
{
Task.Run(async () =>
{
while (!cts.IsCancellationRequested)
{
await Task.Delay(200);
rTrig.CLK = true;
if (rTrig.Q)
{
a = b;
b = int.Parse(this.textBox1.Text.Trim()) ;
}
this.label1.Invoke(new Action(() => {
this.label1.Text = a.ToString(); }));
this.label2.Invoke(new Action(() => {
this.label2.Text = b.ToString(); }));
}
}, cts.Token);
}
private void NoRTrig_Click(object sender, EventArgs e)
{
Task.Run(async () =>
{
while (!cts.IsCancellationRequested)
{
await Task.Delay(200);
if (true)
{
a = b;
b = int.Parse(this.textBox1.Text.Trim());
}
this.label1.Invoke(new Action(() => {
this.label1.Text = a.ToString(); }));
this.label2.Invoke(new Action(() => {
this.label2.Text = b.ToString(); }));
}
}, cts.Token);
}
}
}

The initial state

Use rising edge ,If It was executed once in

Do not use rising edge ,a,b Unable to pass value
边栏推荐
- Share Net lightweight ORM
- 埋点111
- csdn软件测试入门的测试基本流程
- A usage example that can be compatible with various database transactions
- 2021年山东省赛题库题目抓包
- 【SWT组件】内容滚动组件 ScrolledComposite
- 爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
- 九度 1480:最大上升子序列和(动态规划思想求最值)
- 手机厂商“互卷”之年:“机海战术”失灵,“慢节奏”打法崛起
- Nine degrees 1480: maximum ascending subsequence sum (dynamic programming idea for the maximum value)
猜你喜欢

Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework

“军备竞赛”时期的对比学习

Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born

5g NR system architecture

基于昇腾AI丨爱笔智能推出银行网点数字化解决方案,实现从总部到网点的信息数字化全覆盖

重磅:国产IDE发布,由阿里研发,完全开源!
![C language QQ chat room small project [complete source code]](/img/4e/b3703ac864830d55c824e1b56c8f85.png)
C language QQ chat room small project [complete source code]

5G NR系统架构

非技術部門,如何參與 DevOps?

DGL中的消息传递相关内容的讲解
随机推荐
Learning note 4 -- Key Technologies of high-precision map (Part 2)
使用GBase 8c数据库过程中报错:80000502,Cluster:%s is busy,是怎么回事?
vite//
微信核酸检测预约小程序系统毕业设计毕设(8)毕业设计论文模板
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
Node の MongoDB Driver
SqlServer定时备份数据库和定时杀死数据库死锁解决
基于昇腾AI丨以萨技术推出视频图像全目标结构化解决方案,达到业界领先水平
Web3基金会「Grant计划」赋能开发者,盘点四大成功项目
5G NR系统架构
Taro进阶
What are the top ten securities companies? Is it safe to open an account online?
正则表达式
2022年流动式起重机司机考试题库及模拟考试
Go项目实战—参数绑定,类型转换
小程序框架Taro
想请教一下,十大券商有哪些?在线开户是安全么?
2022年T电梯修理操作证考试题及答案
SAP ui5 objectpagelayout control usage sharing
使用bat命令一键启动常用浏览器