• 大小: 355KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-06-18
  • 语言: C#
  • 标签: C#    pl  

资源简介

关于用c#串口读取三菱plc的x y点数据,商机无限..................

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        string aa;
        string data;
        string y0 =“0“;
        string y1 = “0“;
        string y2 = “0“;
        string y3 = “0“;
        string y4 = “0“;
        string y5 = “0“;
        string y6 = “0“;
        string y7 = “0“;
        bool on;
        
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            axMSComm1.PortOpen = false;
           
            Close();

        }
       
        private void Form1_Load(object sender EventArgs e)
        {
            axMSComm1.CommPort = 7; //‘设置通信端口号为COM1
            axMSComm1.Settings = “9600e71“; //‘设置串口参数
            axMSComm1.InputMode = 0;//‘接收文本型数据
            axMSComm1.PortOpen = true;//‘打开通信端口1
            axMSComm1.RThreshold = 1;
            
            }

            
        private void Form1_FormClosing(object sender FormClosingEventArgs e)
        {
            axMSComm1.PortOpen = false;
        }
        protected void send()
        {
            on = true;   
        }
       
     
       private void button9_Click(object sender EventArgs e)
        {
            y7 = “1“;
            on = true;
            send();
        }

       private void button17_Click(object sender EventArgs e)
        {
            y7 = “0“;
            on = true;
            send();
        }

        private void timer1_Tick(object sender EventArgs e)
        {
            string s1 = y7 + y6 + y5 + y4;
            string s2 = y3 + y2 + y1 + y0;
            int b1 = Convert.ToInt32(s1 2);//二进制转十进制
            int b2 = Convert.ToInt32(s2 2);//二进制转十进制

            if (b1 > 9)//十进制转asc码
                b1 = b1 + 55;//b1(A-F)
            else
                b1 = b1 + 48;//b1(0-9)
            if (b2 > 9)
                b2 = b2 + 55;
            else
                b2 = b2 + 48;
            int check = b1 + b2 + 456;
            byte b11 = (byte)b1;
            byte b22 = (byte)b2;
            string checks = Convert.ToString(check 16);//十进制转十六进制
            checks = checks.ToUpper();
            byte[] outdata = { 2 49 48 48 65 49 48 50 b11 b22 48 48 3 };
            string outdata1 = System.Text.Encoding.ASCII.GetString(outdata);
            string outdata2 = outdata1 + checks.Substring(checks.Length - 2 1) + checks.Substring(checks.Length - 1 1);
            byte[] str = { 2 4849 48 49 52 48 50 3 53 66 };
            string str1 = System.Text.Encoding.ASCII.GetString(str);
            
            if (on == true)
                axMSComm1.Output = (outdata2);
           
            el

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-05-23 14:14  视频处理与三菱PLC通讯最终程序\
     目录           0  2018-05-23 14:14  视频处理与三菱PLC通讯最终程序\.vs\
     目录           0  2018-05-23 14:14  视频处理与三菱PLC通讯最终程序\.vs\WindowsFormsApplication1\
     目录           0  2018-05-23 14:14  视频处理与三菱PLC通讯最终程序\.vs\WindowsFormsApplication1\v15\
     文件       59904  2018-05-25 14:53  视频处理与三菱PLC通讯最终程序\.vs\WindowsFormsApplication1\v15\.suo
     目录           0  2018-05-23 14:14  视频处理与三菱PLC通讯最终程序\.vs\WindowsFormsApplication1\v15\Server\
     目录           0  2018-05-25 14:53  视频处理与三菱PLC通讯最终程序\.vs\WindowsFormsApplication1\v15\Server\sqlite3\
     文件           0  2018-05-23 14:14  视频处理与三菱PLC通讯最终程序\.vs\WindowsFormsApplication1\v15\Server\sqlite3\db.lock
     文件      512000  2018-05-25 14:53  视频处理与三菱PLC通讯最终程序\.vs\WindowsFormsApplication1\v15\Server\sqlite3\storage.ide
     目录           0  2016-06-07 11:14  视频处理与三菱PLC通讯最终程序\Backup\
     目录           0  2016-06-07 11:14  视频处理与三菱PLC通讯最终程序\Backup1\
     目录           0  2016-06-07 11:14  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\
     文件         962  2011-06-08 21:23  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1.sln
     文件       25600  2016-03-22 16:22  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1.suo
     文件        5172  2016-03-22 16:22  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\Form1.cs
     文件        6509  2016-03-22 16:21  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\Form1.Designer.cs
     文件        6576  2016-03-22 16:21  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\Form1.resx
     文件         505  2011-06-08 21:23  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\Program.cs
     目录           0  2016-06-07 11:14  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\Properties\
     文件        1386  2011-06-08 21:23  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\Properties\AssemblyInfo.cs
     文件        2898  2011-06-08 21:23  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\Properties\Resources.Designer.cs
     文件        5612  2011-06-08 21:23  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\Properties\Resources.resx
     文件        1109  2011-06-08 21:23  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\Properties\Settings.Designer.cs
     文件         249  2011-06-08 21:23  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\Properties\Settings.settings
     文件        4412  2012-01-01 14:32  视频处理与三菱PLC通讯最终程序\Backup1\WindowsFormsApplication1\WindowsFormsApplication1.csproj
     目录           0  2016-06-07 11:14  视频处理与三菱PLC通讯最终程序\Backup\WindowsFormsApplication1\
     文件         962  2011-06-08 21:23  视频处理与三菱PLC通讯最终程序\Backup\WindowsFormsApplication1.sln
     文件       25600  2016-03-21 18:01  视频处理与三菱PLC通讯最终程序\Backup\WindowsFormsApplication1.suo
     文件        4143  2016-03-21 17:53  视频处理与三菱PLC通讯最终程序\Backup\WindowsFormsApplication1\Form1.cs
     文件        7561  2016-03-21 17:53  视频处理与三菱PLC通讯最终程序\Backup\WindowsFormsApplication1\Form1.Designer.cs
     文件        6737  2016-03-21 17:53  视频处理与三菱PLC通讯最终程序\Backup\WindowsFormsApplication1\Form1.resx
............此处省略58个文件信息

评论

共有 条评论