当前位置:网站首页>A simple PLC motion control project
A simple PLC motion control project
2022-04-22 10:32:00 【Brother Chang said programming】
Automation industry , It's getting closer to the software industry .
quite a lot PLC Engineers are beginning to realize , Master a programming language , Becoming more and more important .
that PLC After engineers learn to program , What kind of experience will it be ?
I think the most direct experience is : Know more about principled things , The technology stack is more comprehensive , Can complete the project evaluation independently 、 drawing 、 The selection 、PLC Program development and debugging , To the upper computer development , Even higher WEB End 、 Mobile .
Get down to business , This paper mainly shares a motion control case commonly used in industrial field , From hardware selection to program design , Then from local debugging to host computer development and debugging .
This case is a relatively simple case , But it can effectively PLC Combined with the upper computer , For beginners , It is a more suitable hand training project .
1、 Hardware selection
controller : Siemens 200Smart PLC, Models for ST20(DC-DC-DC)
Driver : Stepping driver
The motor :42mm Stepper motor
Limit :3 A limit switch , Corresponding to the origin respectively 、 Left limit 、 Right limit
platform : Uniaxial module
Button indicator : start-up 、 stop it 、 Running state 、3 A travel switch ( Analog completion signal )
2、 Hardware wiring diagram

3、PLC Application development
S7-200 Smart PLC Motion control requires the use of a motion control wizard , The core procedure is as follows :


4、 PC program development
(1)I/O surface :PLC Program programming , The host computer interface will be reserved , Upper computer I/O The table is shown below :

(2) Interface design : Upper computer UI Interface design

(3) Function realization : The upper computer mainly includes real-time status and data monitoring 、 Speed and position parameter setting 、 The system log shows 、 Communication parameter settings .
-
Real time status and data monitoring
This case is similar to Siemens PLC The communication mode between is S7 signal communication , Use open source communication library s7.net To achieve , Real time data acquisition based on multithreading , Combined with practice I/O Data analysis .
private void PLCCommunication()
{
while (!cts.IsCancellationRequested)
{
byte[] result = plc.ReadBytes(StoreType.DataBlock, 1, 0, 23);
if (result != null && result.Length == 23)
{
this.Invoke(new Action(() =>
{
// Real time status update here
}));
Thread.Sleep(10);
}
}
}
-
Speed and position parameter setting
Independent setting interface is adopted for parameter setting , Pass values through the form to realize .

The code is as follows :
/// <summary>
/// The set value
/// </summary>
public string setValue = string.Empty;
private void btn_Set_Click(object sender, EventArgs e)
{
this.setValue = this.txt_SetValue.Text;
this.DialogResult = DialogResult.OK;
this.Close();
}
-
The system log shows
The system log is based on ListView Control development , Implementation log 、 Call the police 、 The warning is displayed differently in three different states , It can be stored in the database at the same time , Facilitate subsequent traceability .
private string CurrentTime
{
get { return DateTime.Now.ToString("HH:mm:ss"); }
}
// Write to the log
private void AddLog(int index, string log)
{
if (this.lstInfo.InvokeRequired)
{
this.lstInfo.Invoke(new Action(() =>
{
ListViewItem lst = new ListViewItem(CurrentTime, index);
lst.SubItems.Add(log);
this.lstInfo.Items.Insert(0, lst);
}));
}
else
{
ListViewItem lst = new ListViewItem(CurrentTime, index);
lst.SubItems.Add(log);
this.lstInfo.Items.Insert(0, lst);
}
}
-
Communication parameter settings
Communication parameters are system parameters , use Winform Of Settings To configure storage , Simple and quick .
The interface design is as follows :

The code is as follows :
public SaveDefaultSettingDelegate SaveDefaultSetting;
private void btn_Set_Click(object sender, EventArgs e)
{
CommSet set = new CommSet();
try
{
set.IPAddress = this.txt_IPAddress.Text;
set.CPUType = this.cmb_CPUType.Text;
set.StoreTime = Convert.ToInt32(this.txt_StoreTime.Text);
set.AutoStore = this.chk_AutoStore.Checked;
}
catch (Exception)
{
MessageBox.Show(" Please check whether the data format is correct "," Format error ");
return;
}
SaveDefaultSetting(set);
MessageBox.Show(" Configuration is successful , Immediate effect ", " Configuration is successful ");
this.Close();
}
5、 Written in the back
In recent years , As more and more devices begin to join IIoT The Internet (Industrial Internet of Things, Industrial Internet of things is short for IIoT),IT And OT The boundaries between them will gradually disappear , Until it becomes one or the same system .
therefore , More and more electrical engineers begin to transform to PC development . Because on the basis of existing electrical skills , If you master the upper computer development skills , The salary reaches 20K, even to the extent that 30K, It's going to be easier .
If you want to learn the content related to PC development, you can confide in me
版权声明
本文为[Brother Chang said programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221023558112.html
边栏推荐
- The computer cleans the C disk (system disk) and the disk compression (disk partition) and expansion (disk expansion).
- Slime 2022 展望:把 Istio 的复杂性塞入智能的黑盒
- Query process of 004-mysql
- 【leetcode】二叉树遍历迭代法的统一模板
- [SV] assign force difference
- Spark 3.x 的 WSCG 机制源码解析
- Cobbler cobbler cobbler
- LLVM之父Chris Lattner:编译器的黄金时代
- Use of navigationview
- How to implement acid at the bottom of MySQL?
猜你喜欢

Error message during unity3d build: missing project ID in unity solution

【SQL server速成之路】数据库的查询

三分钟快速了解互动涂鸦

数字化时代,企业运维面临现状及挑战分析解读

Pytorch semantic segmentation total convolution network

The debug breakpoint of idea thread pool cannot jump in

Use of navigationview

numpy库的基础知识介绍与基本使用

LLVM之父Chris Lattner:编译器的黄金时代

斜率优化DP
随机推荐
PCIE XDMA IP核介绍(附列表)-明德扬科教(mdy-edu.com)
半个月东山再起,如果你哪天失业了,请务必收藏好5大自媒体工具
Google Adsense suggests that the advertising capture tool is wrong, which may lead to reduced revenue. What should we do
Two ways to write Coriolis (understand 'fn.length' and 'FN. Tostring()')
2022-04-17_ Function (I)
Slime 2022 展望:把 Istio 的复杂性塞入智能的黑盒
Directory of message queuing Master Course
《MySQL 是怎样运行的:从根儿上理解 MySQL 》优质笔记
001-MYSQL命令
基于PyQt5实现数据动态可视化
php 獲取IP以分鐘限制提交次數,適用於驗證碼獲取過於頻繁
企业级 Web 开发的挑战
基于容器的PaaS混合云的几种形式
TC397 MCMCAN
安全远程访问+安全文件传输+终端仿真+远程管理丨上海道宁联合VanDyke为IT行业人员带来可靠的、易于配置的软件
MySql5.7.26安装
Pytorch semantic segmentation total convolution network
一个简单的PLC运动控制项目
About the problem that the picture library of tpshop open source mall version 6.0 does not display pictures
Here comes the article ~ share compressed and decompressed files [online website]