吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 8323|回复: 18
收起左侧

[其他转载] C#编写上位机界面

[复制链接]
凌凌壹 发表于 2020-5-8 10:29
工具 VS2019  博图 V16 (300PLC) 语言c#
界面功能:通讯 ,读写,简单加了一曲线图。
关于:PID整定(机缘巧合下一个学弟要做个小项目,我就试了试,比较简单后期慢慢更新。)
没有实物(实物太贵现阶段是没办法直棱起来的)只能做测试用。(有大佬有实物的的话可以帮忙做测试,小弟在此先谢过了。)
付百度云连接:链接: https://pan.baidu.com/s/16qA8WFRfLG8n3Vay9S37rQ 提取码: tfpt

百度云链接: 提取码: tfpt

付部分程序:
       #region 初始化
        public Form1()
        {
            InitializeComponent();

            CheckForIllegalCrossThreadCalls = false;

            this.realTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            timerClock.Start();


            this.buttonConnect.Enabled = false;
            this.buttonDisconnect.Enabled = false;
            this.groupBox2.Enabled = false;
            this.groupBox3.Enabled = false;
        }
        //界面初始化
        private void Form1_Load(object sender, EventArgs e)
        {
            this.comboBoxPLCType.SelectedIndex = -1;
        }
        //初始化图表
        private void userCurve1_Load(object sender, EventArgs e)
        {
            userCurve1.SetLeftCurve("A", new float[0], Color.Tomato);
            userCurve1.SetLeftCurve("B", new float[0], Color.Blue);
        }
        //时钟
        private void timerClock_Tick(object sender, EventArgs e)
        {
            this.realTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
        #endregion

        #region 事件
        //连接按钮
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            RequiredFieldValIDAtor();
            try
            {
                if (siemensPLCSelected != SiemensPLCS.S200Smart)
                {
                    siemensTcpNet.Rack = byte.Parse(this.textBoxRack.Text);
                    siemensTcpNet.Slot = byte.Parse(this.textBoxSlot.Text);
                }
                OperateResult connect = siemensTcpNet.ConnectServer();
                if (connect.IsSuccess)
                {
                    this.connectTips.Text = "设备连接成功:已连接至IP:"
                                                        + this.textBoxPLCIP.Text.Trim() + "  的"
                                                        + this.comboBoxPLCType.Text.Trim()
                                                        + "PLC设备";
                    this.connectTips.ForeColor = Color.Green;
                    Connect_Load();
                }
                else
                {
                    this.connectTips.Text = "设备连接失败:未连接至IP:"
                                                            + this.textBoxPLCIP.Text.Trim() + "  的"
                                                            + this.comboBoxPLCType.Text.Trim()
                                                            + "PLC设备";
                    this.connectTips.ForeColor = Color.Red;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        //连接初始化
        private void Connect_Load()
        {
            //界面使能
            this.groupBox2.Enabled = true;
            this.groupBox3.Enabled = true;
            this.buttonDisconnect.Enabled = true;
            this.buttonConnect.Enabled = false;
            //创建线程
            th = new Thread(DataRefresh);
            th.IsBackground = true;
            th.Start();
            //计数时钟
            countTimer.Start();
        }

        //断开连接
        private void buttonDisconnect_Click(object sender, EventArgs e)
        {
            OperateResult ConnectClose = siemensTcpNet.ConnectClose();
            if (ConnectClose.IsSuccess)
            {
                //连接使能,断开关闭
                buttonConnect.Enabled = true;
                buttonDisconnect.Enabled = false;
                this.groupBox2.Enabled = false;
                this.groupBox3.Enabled = false;
                //提示字符串
                this.connectTips.Text = "设备已断开连接";
                this.connectTips.ForeColor = Color.Red;
                //计数时钟
                countTimer.Stop();
                //线程
                th.Abort();
            }
        }
        #endregion

这是界面图片

这是界面图片

免费评分

参与人数 9吾爱币 +12 热心值 +8 收起 理由
ylz_yg + 1 不错哦
cmhchu + 1 赞一个,顶一下
liguang70217 + 1 + 1 谢谢@Thanks!
xzn107 + 1 + 1 我很赞同!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
人云亦云 + 1 谢谢@Thanks!
DeBugWang + 1 + 1 热心回复!
qinling072 + 1 + 1 我很赞同!
涛的世界 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 凌凌壹 发表于 2020-5-10 11:18
xzn107 发表于 2020-5-9 13:31
拿博图的仿真测试就行了哦,模拟测试可以的哈,楼主的HslCommunication.dll是哪搞来的啊

这个主要是测试通讯的,这个.dll也是网上找到的。连接仿真器时中间还有一个软件这样才能建立起来PLC与上位机的通讯。
 楼主| 凌凌壹 发表于 2020-5-12 15:35
sbhd516 发表于 2020-5-10 21:26
HSL 已经拿了专利了。 这样搞不太好。  我用S7NET 做 ,一样可以

但是这个是开源的呀,vs自带的s7.net也是可以的。
 楼主| 凌凌壹 发表于 2020-5-8 11:56
bsjasd 发表于 2020-5-8 12:15
东西不错,学习下
 楼主| 凌凌壹 发表于 2020-5-8 13:06
bsjasd 发表于 2020-5-8 12:15
东西不错,学习下

请指教,我也是新手。
jondn1992 发表于 2020-5-8 16:05
你好请问使用这个plcsim 软件就可以读到plc的值了吗
人云亦云 发表于 2020-5-8 22:06
支持一下,正在学习这方面知识
 楼主| 凌凌壹 发表于 2020-5-9 08:06
人云亦云 发表于 2020-5-8 22:06
支持一下,正在学习这方面知识

一起学习。
304775988 发表于 2020-5-9 08:18
这个代码还要实物测试喔,的确有难度呢
xzn107 发表于 2020-5-9 13:31
拿博图的仿真测试就行了哦,模拟测试可以的哈,楼主的HslCommunication.dll是哪搞来的啊
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-26 17:32

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表