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

资源简介

C#三菱FX系列PLC纯串口命令各区域读写,对于D区,各类型数据均有涉及:short,int,float,简单的demo,并非项目,一目了然

资源截图

代码片段和文件信息

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;
using System.IO.Ports;
using System.Threading;
using System.IO;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            try
            {
                SerialPort sp = new SerialPort(“COM3“ 9600 Parity.Even 7 StopBits.One);
                sp.Open();

                sp.Write(MethodHx.GenerateMitsubishiPlcReadCommand(“D“ 110 1));
                byte[] br = new byte[144];
                int b = 0 i = 0;
                while (true)
                {
                    b = sp.ReadByte();
                    if (b == 3)
                    {
                        sp.ReadByte();
                        sp.ReadByte();
                        break;
                    }
                    br[i] = (byte)b;
                    i++;
                }
                short D110 = 0;
                if (br[0] == 2)
                    D110 = MethodHx.DecodeMitsubishiPlcData_D_Short(br);
                Console.WriteLine(D110);

                sp.Close();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        private void button2_Click(object sender EventArgs e)
        {
            try
            {
                SerialPort sp = new SerialPort(“COM3“ 9600 Parity.Even 7 StopBits.One);
                sp.Open();

                sp.Write(MethodHx.GenerateMitsubishiPlcReadCommand(“D“ 510 10));
                byte[] br = new byte[144];
                int b = 0 i = 0;
                while (true)
                {
                    b = sp.ReadByte();
                    if (b == 3)
                    {
                        sp.ReadByte();
                        sp.ReadByte();
                        break;
                    }
                    br[i] = (byte)b;
                    i++;
                }
                string D800 = ““;
                if (br[0] == 2)
                    D800 = MethodHx.DecodeMitsubishiPlcData_D_String(br 10);
                Console.WriteLine(D800);

                Console.WriteLine(“**********************“);

                sp.Write(MethodHx.GenerateMitsubishiPlcReadCommand(“D“ 510 10));
                b = 0;
                i = 0;
                while (true)
                {
                    b = sp.ReadByte();
                    if (b == 3)
                    {
                        sp.ReadByte();
                        sp.ReadByte();
                        break;
                    }
                    br[i] = (byte)b;
                    i++;
                }
 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-12-21 15:45  WindowsFormsApplication2\
     目录           0  2017-12-23 15:09  WindowsFormsApplication2\WindowsFormsApplication2\
     文件        7614  2017-12-23 14:07  WindowsFormsApplication2\WindowsFormsApplication2\Form1.Designer.cs
     文件        8069  2017-12-23 15:09  WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs
     文件        5817  2017-12-23 14:07  WindowsFormsApplication2\WindowsFormsApplication2\Form1.resx
     文件       16418  2017-12-23 15:05  WindowsFormsApplication2\WindowsFormsApplication2\MethodHx.cs
     文件         505  2017-12-21 15:45  WindowsFormsApplication2\WindowsFormsApplication2\Program.cs
     目录           0  2017-12-21 15:45  WindowsFormsApplication2\WindowsFormsApplication2\Properties\
     文件        1372  2017-12-21 15:45  WindowsFormsApplication2\WindowsFormsApplication2\Properties\AssemblyInfo.cs
     文件        2900  2017-12-21 15:45  WindowsFormsApplication2\WindowsFormsApplication2\Properties\Resources.Designer.cs
     文件        5612  2017-12-21 15:45  WindowsFormsApplication2\WindowsFormsApplication2\Properties\Resources.resx
     文件        1111  2017-12-21 15:45  WindowsFormsApplication2\WindowsFormsApplication2\Properties\Settings.Designer.cs
     文件         249  2017-12-21 15:45  WindowsFormsApplication2\WindowsFormsApplication2\Properties\Settings.settings
     文件        3801  2017-12-21 15:52  WindowsFormsApplication2\WindowsFormsApplication2\WindowsFormsApplication2.csproj
     目录           0  2017-12-21 15:45  WindowsFormsApplication2\WindowsFormsApplication2\bin\
     目录           0  2017-12-23 15:05  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\
     文件       17920  2017-12-23 15:09  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe
     文件       44544  2017-12-23 15:09  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.pdb
     文件       24216  2017-12-23 15:09  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe
     文件         490  2017-09-29 21:43  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe.manifest
     目录           0  2017-12-21 15:45  WindowsFormsApplication2\WindowsFormsApplication2\obj\
     目录           0  2017-12-23 15:09  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\
     文件        1453  2017-12-21 16:51  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6884  2017-12-21 15:46  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2017-12-23 15:22  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\TempPE\
     文件         180  2017-12-23 15:05  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Form1.resources
     文件         180  2017-12-23 15:05  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Properties.Resources.resources
     文件         946  2017-12-23 15:09  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csproj.FileListAbsolute.txt
     文件         977  2017-12-23 15:05  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csproj.GenerateResource.Cache
     文件        2211  2017-12-23 15:06  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csprojResolveAssemblyReference.cache
     文件       17920  2017-12-23 15:09  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.exe
............此处省略3个文件信息

评论

共有 条评论