• 大小: 0.77M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-06-16
  • 语言: C#
  • 标签: 台达PLC  485  PLC  通信  C#  

资源简介


资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HslCommunication.ModBus;

namespace DVPModbus
{
    public partial class Form1 : Form
    {
        //PLC为台达DVP系列,AS系列的通信地址不一样
        //台达PLC的RS485默认参数:9600,7,1stop,Even;
        private ModbusAscii modbus;
        string portName;
        int baudRate;
        int dataBits;
        string PLCstation;
        public Form1()
        {
            InitializeComponent();
            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 0;
            comboBox3.SelectedIndex = 0;
            comboBox4.SelectedIndex = 0;
            comboBox5.SelectedIndex = 0;
            comboBox6.SelectedIndex = 0;
        }

        private void btnOpen_Click(object sender EventArgs e)
        {
            var stopbits = System.IO.Ports.StopBits.One;
            var Parity = System.IO.Ports.Parity.None;
            if (comboBox1.SelectedIndex == 0)
            {
                portName = “COM1“;
            }
            else if (comboBox1.SelectedIndex == 1)
            {
                portName = “COM2“;
            }
            else if (comboBox1.SelectedIndex == 2)
            {
                portName = “COM3“;
            }
            else if (comboBox1.SelectedIndex == 3)
            {
                portName = “COM4“;
            }
            else if (comboBox1.SelectedIndex == 4)
            {
                portName = “COM5“;
            }

            if (comboBox2.SelectedIndex == 0)
            {
                baudRate = 9600;
            }
            else if (comboBox2.SelectedIndex == 1)
            {
                baudRate = 4800;
            }
            else if (comboBox2.SelectedIndex == 2)
            {
                baudRate = 19200;
            }
            else if (comboBox3.SelectedIndex == 3)
            {
                baudRate = 115200;
            }

            if (comboBox3.SelectedIndex == 0)
            {
                dataBits = 7;
            }
            else if (comboBox3.SelectedIndex == 1)
            {
                dataBits = 8;
            }

            if (comboBox4.SelectedIndex == 0)
            {
                stopbits = System.IO.Ports.StopBits.One;
            }
            else if (comboBox4.SelectedIndex == 1)
            {
                stopbits = System.IO.Ports.StopBits.Two;
            }

            if (comboBox5.SelectedIndex == 0)
            {
                Parity = System.IO.Ports.Parity.None;
            }
            else if (comboBox5.SelectedIndex == 1)
            {
                Parity = System.IO.Ports.Parity.Odd;
            }
            else if (comboBox5.SelectedIndex == 2)
            {
                Parity = System.IO.Ports.Par

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2021-03-15 00:24  DVPModbus485\
     目录           0  2021-01-08 19:02  DVPModbus485\.vs\
     目录           0  2021-01-08 19:02  DVPModbus485\.vs\DVPModbus\
     目录           0  2021-01-08 19:02  DVPModbus485\.vs\DVPModbus\v16\
     文件       46080  2021-03-15 00:25  DVPModbus485\.vs\DVPModbus\v16\.suo
     文件         189  2020-12-30 00:13  DVPModbus485\App.config
     文件        3830  2020-12-30 00:19  DVPModbus485\DVPModbus.csproj
     文件        1122  2020-12-30 00:13  DVPModbus485\DVPModbus.sln
     文件       30291  2021-03-15 00:24  DVPModbus485\Form1.Designer.cs
     文件        8159  2021-03-15 00:24  DVPModbus485\Form1.cs
     文件        6011  2021-03-15 00:24  DVPModbus485\Form1.resx
     文件         521  2020-12-30 00:13  DVPModbus485\Program.cs
     目录           0  2021-01-08 19:02  DVPModbus485\Properties\
     文件        1310  2020-12-30 00:13  DVPModbus485\Properties\AssemblyInfo.cs
     文件        2850  2020-12-30 00:13  DVPModbus485\Properties\Resources.Designer.cs
     文件        5612  2020-12-30 00:13  DVPModbus485\Properties\Resources.resx
     文件        1094  2020-12-30 00:13  DVPModbus485\Properties\Settings.Designer.cs
     文件         249  2020-12-30 00:13  DVPModbus485\Properties\Settings.settings
     目录           0  2021-01-08 19:02  DVPModbus485\bin\
     目录           0  2021-03-15 00:25  DVPModbus485\bin\Debug\
     文件       19968  2021-03-15 00:25  DVPModbus485\bin\Debug\DVPModbus.exe
     文件         189  2020-12-30 00:13  DVPModbus485\bin\Debug\DVPModbus.exe.config
     文件       38400  2021-03-15 00:25  DVPModbus485\bin\Debug\DVPModbus.pdb
     文件     2482176  2020-12-22 02:53  DVPModbus485\bin\Debug\HslCommunication.dll
     目录           0  2021-01-08 19:02  DVPModbus485\obj\
     目录           0  2021-03-15 00:25  DVPModbus485\obj\Debug\
     文件         214  2021-03-15 00:24  DVPModbus485\obj\Debug\.NETframeworkVersion=v4.5.2.AssemblyAttributes.cs
     文件         180  2021-03-15 00:25  DVPModbus485\obj\Debug\DVPModbus.Form1.resources
     文件         180  2021-03-15 00:25  DVPModbus485\obj\Debug\DVPModbus.Properties.Resources.resources
     文件           0  2021-03-15 00:25  DVPModbus485\obj\Debug\DVPModbus.csproj.CopyComplete
     文件          42  2021-03-15 00:25  DVPModbus485\obj\Debug\DVPModbus.csproj.CoreCompileInputs.cache
............此处省略7个文件信息

评论

共有 条评论