当前位置:网站首页>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
边栏推荐
- Glide conclusion
- 请问postgresql cdc 怎么设置单独的增量模式呀,debezium.snapshot.mo
- Shortcut keys for vscode
- Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
- Who is the "conscience" domestic brand?
- LSTM应用于MNIST数据集分类(与CNN做对比)
- AtCoder Beginner Contest 258「ABCDEFG」
- Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
- Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
- Comparative learning in the period of "arms race"
猜你喜欢
WorkManager学习一
"Everyday Mathematics" serial 58: February 27
风控模型启用前的最后一道工序,80%的童鞋在这都踩坑
在C# 中实现上升沿,并模仿PLC环境验证 If 语句使用上升沿和不使用上升沿的不同
[dark horse morning post] Luo Yonghao responded to ridicule Oriental selection; Dong Qing's husband Mi Chunlei was executed for more than 700million; Geely officially acquired Meizu; Huawei releases M
微信核酸检测预约小程序系统毕业设计毕设(8)毕业设计论文模板
The most complete is an I2C summary
非技术部门,如何参与 DevOps?
How do programmers live as they like?
【DNS】“Can‘t resolve host“ as non-root user, but works fine as root
随机推荐
Learning notes 5 - high precision map solution
Learning note 4 -- Key Technologies of high-precision map (Part 2)
QT implements JSON parsing
The most complete is an I2C summary
双向RNN与堆叠的双向RNN
Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
Sqlserver regularly backup database and regularly kill database deadlock solution
基于昇腾AI丨以萨技术推出视频图像全目标结构化解决方案,达到业界领先水平
Solution to the length of flex4 and Flex3 combox drop-down box
vite//
重磅:国产IDE发布,由阿里研发,完全开源!
Go-3-第一个Go程序
DDOS攻击原理,被ddos攻击的现象
跨页面通讯
web安全
WorkManager学习一
Go-2-Vim IDE常用功能
2021年山东省赛题库题目抓包
SLAM 01.人类识别环境&路径的模型建立
Go project practice - Gorm format time field