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

C#使用TCP-S7协议读写西门子PLC(五)-测试程序

上面四篇我们进行封装连接PLC以及读写PLC内存地址表 

C#使用TCP-S7协议读写西门子PLC(一)-CSDN博客

 C#使用TCP-S7协议读写西门子PLC(二)-CSDN博客

 C#使用TCP-S7协议读写西门子PLC(三)-CSDN博客

 C#使用TCP-S7协议读写西门子PLC(四)-CSDN博客

这里我们进行测试操作

西门子PLC-S7协议测试读写基础数据类型、字符串、Unicode字符串、连续数组等

窗体应用程序PlcSiemesS7Demo应用程序文件清单如下图所示

窗体FormS7Protocol设计器如下:

窗体设计器代码如下:

文件FormS7Protocol.Designer.cs


namespace PlcSiemesS7Demo
{partial class FormS7Protocol{/// <summary>/// 必需的设计器变量。/// </summary>private System.ComponentModel.IContainer components = null;/// <summary>/// 清理所有正在使用的资源。/// </summary>/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows 窗体设计器生成的代码/// <summary>/// 设计器支持所需的方法 - 不要修改/// 使用代码编辑器修改此方法的内容。/// </summary>private void InitializeComponent(){this.panel1 = new System.Windows.Forms.Panel();this.cboSiemensPLCCategory = new System.Windows.Forms.ComboBox();this.label2 = new System.Windows.Forms.Label();this.btnDisconnect = new System.Windows.Forms.Button();this.btnConnect = new System.Windows.Forms.Button();this.txbPort = new System.Windows.Forms.TextBox();this.label3 = new System.Windows.Forms.Label();this.txbIP = new System.Windows.Forms.TextBox();this.label1 = new System.Windows.Forms.Label();this.rtxbDisplay = new System.Windows.Forms.RichTextBox();this.groupBox1 = new System.Windows.Forms.GroupBox();this.btnReadWString = new System.Windows.Forms.Button();this.label12 = new System.Windows.Forms.Label();this.txtReadValWString = new System.Windows.Forms.TextBox();this.label13 = new System.Windows.Forms.Label();this.txtReadWStringLength = new System.Windows.Forms.TextBox();this.rtxtReadValArray = new System.Windows.Forms.RichTextBox();this.btnReadArray = new System.Windows.Forms.Button();this.label9 = new System.Windows.Forms.Label();this.label8 = new System.Windows.Forms.Label();this.txtReadArrayLength = new System.Windows.Forms.TextBox();this.btnReadString = new System.Windows.Forms.Button();this.label7 = new System.Windows.Forms.Label();this.txtReadValString = new System.Windows.Forms.TextBox();this.label4 = new System.Windows.Forms.Label();this.txtReadStringLength = new System.Windows.Forms.TextBox();this.btnReadBasic = new System.Windows.Forms.Button();this.label5 = new System.Windows.Forms.Label();this.txtReadValBasic = new System.Windows.Forms.TextBox();this.cboReadDataType = new System.Windows.Forms.ComboBox();this.label6 = new System.Windows.Forms.Label();this.label10 = new System.Windows.Forms.Label();this.label11 = new System.Windows.Forms.Label();this.txtOffsetAddress = new System.Windows.Forms.TextBox();this.cboRegisterCategory = new System.Windows.Forms.ComboBox();this.groupBox2 = new System.Windows.Forms.GroupBox();this.btnWriteWString = new System.Windows.Forms.Button();this.label14 = new System.Windows.Forms.Label();this.txtWriteValWString = new System.Windows.Forms.TextBox();this.label15 = new System.Windows.Forms.Label();this.txtWriteWStringLength = new System.Windows.Forms.TextBox();this.rtxtWriteValArray = new System.Windows.Forms.RichTextBox();this.btnWriteArray = new System.Windows.Forms.Button();this.label16 = new System.Windows.Forms.Label();this.btnWriteString = new System.Windows.Forms.Button();this.label18 = new System.Windows.Forms.Label();this.txtWriteValString = new System.Windows.Forms.TextBox();this.label19 = new System.Windows.Forms.Label();this.txtWriteStringLength = new System.Windows.Forms.TextBox();this.btnWriteBasic = new System.Windows.Forms.Button();this.label20 = new System.Windows.Forms.Label();this.txtWriteValBasic = new System.Windows.Forms.TextBox();this.cboWriteDataType = new System.Windows.Forms.ComboBox();this.label21 = new System.Windows.Forms.Label();this.label22 = new System.Windows.Forms.Label();this.txtDbNumber = new System.Windows.Forms.TextBox();this.panel1.SuspendLayout();this.groupBox1.SuspendLayout();this.groupBox2.SuspendLayout();this.SuspendLayout();// // panel1// this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;this.panel1.Controls.Add(this.cboSiemensPLCCategory);this.panel1.Controls.Add(this.label2);this.panel1.Controls.Add(this.btnDisconnect);this.panel1.Controls.Add(this.btnConnect);this.panel1.Controls.Add(this.txbPort);this.panel1.Controls.Add(this.label3);this.panel1.Controls.Add(this.txbIP);this.panel1.Controls.Add(this.label1);this.panel1.Location = new System.Drawing.Point(4, 4);this.panel1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);this.panel1.Name = "panel1";this.panel1.Size = new System.Drawing.Size(611, 87);this.panel1.TabIndex = 2;// // cboSiemensPLCCategory// this.cboSiemensPLCCategory.FormattingEnabled = true;this.cboSiemensPLCCategory.Location = new System.Drawing.Point(122, 52);this.cboSiemensPLCCategory.Name = "cboSiemensPLCCategory";this.cboSiemensPLCCategory.Size = new System.Drawing.Size(206, 20);this.cboSiemensPLCCategory.TabIndex = 14;// // label2// this.label2.AutoSize = true;this.label2.Location = new System.Drawing.Point(8, 52);this.label2.Name = "label2";this.label2.Size = new System.Drawing.Size(95, 12);this.label2.TabIndex = 13;this.label2.Text = "西门子PLC型号:";// // btnDisconnect// this.btnDisconnect.Enabled = false;this.btnDisconnect.Location = new System.Drawing.Point(494, 14);this.btnDisconnect.Name = "btnDisconnect";this.btnDisconnect.Size = new System.Drawing.Size(91, 28);this.btnDisconnect.TabIndex = 5;this.btnDisconnect.Text = "断开连接";this.btnDisconnect.UseVisualStyleBackColor = true;this.btnDisconnect.Click += new System.EventHandler(this.btnDisconnect_Click);// // btnConnect// this.btnConnect.Location = new System.Drawing.Point(371, 14);this.btnConnect.Name = "btnConnect";this.btnConnect.Size = new System.Drawing.Size(91, 28);this.btnConnect.TabIndex = 4;this.btnConnect.Text = "连接";this.btnConnect.UseVisualStyleBackColor = true;this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click);// // txbPort// this.txbPort.Location = new System.Drawing.Point(238, 14);this.txbPort.Name = "txbPort";this.txbPort.Size = new System.Drawing.Size(90, 21);this.txbPort.TabIndex = 3;this.txbPort.Text = "102";// // label3// this.label3.AutoSize = true;this.label3.Location = new System.Drawing.Point(184, 17);this.label3.Name = "label3";this.label3.Size = new System.Drawing.Size(53, 12);this.label3.TabIndex = 2;this.label3.Text = "端口号:";// // txbIP// this.txbIP.Location = new System.Drawing.Point(62, 14);this.txbIP.Name = "txbIP";this.txbIP.Size = new System.Drawing.Size(106, 21);this.txbIP.TabIndex = 1;this.txbIP.Text = "192.168.1.10";// // label1// this.label1.AutoSize = true;this.label1.Location = new System.Drawing.Point(8, 17);this.label1.Name = "label1";this.label1.Size = new System.Drawing.Size(53, 12);this.label1.TabIndex = 0;this.label1.Text = "IP地址:";// // rtxbDisplay// this.rtxbDisplay.Location = new System.Drawing.Point(4, 622);this.rtxbDisplay.Name = "rtxbDisplay";this.rtxbDisplay.ReadOnly = true;this.rtxbDisplay.Size = new System.Drawing.Size(943, 232);this.rtxbDisplay.TabIndex = 3;this.rtxbDisplay.Text = "";// // groupBox1// this.groupBox1.Controls.Add(this.btnReadWString);this.groupBox1.Controls.Add(this.label12);this.groupBox1.Controls.Add(this.txtReadValWString);this.groupBox1.Controls.Add(this.label13);this.groupBox1.Controls.Add(this.txtReadWStringLength);this.groupBox1.Controls.Add(this.rtxtReadValArray);this.groupBox1.Controls.Add(this.btnReadArray);this.groupBox1.Controls.Add(this.label9);this.groupBox1.Controls.Add(this.label8);this.groupBox1.Controls.Add(this.txtReadArrayLength);this.groupBox1

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【C语言学习路线】
  • 【JavaScript】LeetCode:36-40
  • 系统架构设计师 需求分析篇一
  • vue中动态引入加载图片不显示
  • AI大模型与产品经理:替代与合作的深度剖析
  • 说⼀说hashCode()和equals()的关系
  • Corrupt block relative dba: 0x02c0b382 (file 11, block 45954)
  • 动态内存
  • 【Obsidian】当笔记接入AI,Copilot插件推荐
  • 函数模板(初阶)
  • C:字符串函数(续)-学习笔记
  • C语言中实现在动态库中访问另一个动态库变量
  • 白月光git
  • 为什么H.266未能普及?EasyCVR视频编码技术如何填补市场空白
  • 如何建立一个Webservice WSDL的简单例子(完整例子)
  • hexo+github搭建个人博客
  • CentOS 7 修改主机名
  • CNN 在图像分割中的简史:从 R-CNN 到 Mask R-CNN
  • Java知识点总结(JavaIO-打印流)
  • JSONP原理
  • leetcode378. Kth Smallest Element in a Sorted Matrix
  • macOS 中 shell 创建文件夹及文件并 VS Code 打开
  • MD5加密原理解析及OC版原理实现
  • php的插入排序,通过双层for循环
  • Promise面试题,控制异步流程
  • Redux系列x:源码分析
  • SpiderData 2019年2月25日 DApp数据排行榜
  • 产品三维模型在线预览
  • 关于springcloud Gateway中的限流
  • 前端之React实战:创建跨平台的项目架构
  • 算法-插入排序
  • 新书推荐|Windows黑客编程技术详解
  • 再谈express与koa的对比
  • 正则学习笔记
  • 字符串匹配基础上
  • 【云吞铺子】性能抖动剖析(二)
  • 3月7日云栖精选夜读 | RSA 2019安全大会:企业资产管理成行业新风向标,云上安全占绝对优势 ...
  • mysql 慢查询分析工具:pt-query-digest 在mac 上的安装使用 ...
  • # Kafka_深入探秘者(2):kafka 生产者
  • ###51单片机学习(2)-----如何通过C语言运用延时函数设计LED流水灯
  • #QT(智能家居界面-界面切换)
  • $LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
  • ()、[]、{}、(())、[[]]命令替换
  • (6)添加vue-cookie
  • (力扣)1314.矩阵区域和
  • (十二)springboot实战——SSE服务推送事件案例实现
  • (十三)Java springcloud B2B2C o2o多用户商城 springcloud架构 - SSO单点登录之OAuth2.0 根据token获取用户信息(4)...
  • (万字长文)Spring的核心知识尽揽其中
  • (一) springboot详细介绍
  • (一)Linux+Windows下安装ffmpeg
  • (转)菜鸟学数据库(三)——存储过程
  • (转)关于如何学好游戏3D引擎编程的一些经验
  • (总结)Linux下的暴力密码在线破解工具Hydra详解
  • .NET Core中如何集成RabbitMQ
  • .Net Redis的秒杀Dome和异步执行