• 大小: 0.47M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-04-30
  • 语言: C#
  • 标签: Modbus  通信  C#  

资源简介

简易的modbus通信

资源截图

代码片段和文件信息

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.Windows;
using System.Runtime.InteropServices;



namespace ModbusApiTestForCsharp_1
{
    public enum SoftElemType
    {
        //AM600
        ELEM_QX = 0     //QX元件
        ELEM_MW = 1     //MW元件
        ELEM_X = 2  //X元件(对应QX200~QX300)
        ELEM_Y = 3  //Y元件(对应QX300~QX400)

        //H3U
        REGI_H3U_Y = 0x20       //Y元件的定义
        REGI_H3U_X = 0x21 //X元件的定义
        REGI_H3U_S = 0x22 //S元件的定义
        REGI_H3U_M = 0x23 //M元件的定义
        REGI_H3U_TB = 0x24 //T位元件的定义
        REGI_H3U_TW = 0x25 //T字元件的定义
        REGI_H3U_CB = 0x26 //C位元件的定义
        REGI_H3U_CW = 0x27 //C字元件的定义
        REGI_H3U_DW = 0x28 //D字元件的定义
        REGI_H3U_CW2 = 0x29     //C双字元件的定义
        REGI_H3U_SM = 0x2a //SM
        REGI_H3U_SD = 0x2b //
        REGI_H3U_R = 0x2c //

    }
    public partial class Form1 : Form
    {
        #region //标准库
        [DllImport(“StandardModbusApi.dll“ EntryPoint = “Init_ETH_String“ CallingConvention = CallingConvention.Cdecl)]
        public static extern bool Init_ETH_String(string sIpAddr int nNetId = 0 int IpPort = 502);

        [DllImport(“StandardModbusApi.dll“ EntryPoint = “Exit_ETH“ CallingConvention = CallingConvention.Cdecl)]
        public static extern bool Exit_ETH(int nNetId = 0);

        [DllImport(“StandardModbusApi.dll“ EntryPoint = “H3u_Write_Soft_Elem“ CallingConvention = CallingConvention.Cdecl)]
        public static extern int H3u_Write_Soft_Elem(SoftElemType eType int nStartAddr int nCount byte[] pValue int nNetId = 0);

        [DllImport(“StandardModbusApi.dll“ EntryPoint = “H3u_Read_Soft_Elem“ CallingConvention = CallingConvention.Cdecl)]
        public static extern int H3u_Read_Soft_Elem(SoftElemType eType int nStartAddr int nCount byte[] pValue int nNetId = 0);

        [DllImport(“StandardModbusApi.dll“ EntryPoint = “H3u_Read_Soft_Elem_Float“ CallingConvention = CallingConvention.Cdecl)]
        public static extern int H3u_Read_Soft_Elem_Float(SoftElemType eType int nStartAddr int nCount float[] pValue int nNetId = 0);


        [DllImport(“StandardModbusApi.dll“ EntryPoint = “Am600_Write_Soft_Elem“ CallingConvention = CallingConvention.Cdecl)]
        public static extern int Am600_Write_Soft_Elem(SoftElemType eType int nStartAddr int nCount byte[] pValue int nNetId = 0);

        [DllImport(“StandardModbusApi.dll“ EntryPoint = “Am600_Read_Soft_Elem“ CallingConvention = CallingConvention.Cdecl)]
        public static extern int Am600_Read_Soft_Elem(SoftElemType eType int nStartAddr int nCount byte[] pValue int nNetId = 0);

        #endregion

        public Form1()
        {
            InitializeComponent();
        }

        pr

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     43008  2020-06-03 14:10  ModbusApiTestForCsharp_1\.vs\ModbusApiTestForCsharp_1\v14\.suo

     文件        672  2020-03-04 16:07  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Debug\Api.log

     文件      11776  2020-03-04 16:05  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Debug\ModbusApiTestForCsharp_1.exe

     文件      26112  2020-03-04 16:05  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Debug\ModbusApiTestForCsharp_1.pdb

     文件      22696  2020-06-03 14:05  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Debug\ModbusApiTestForCsharp_1.vshost.exe

     文件        490  2018-09-15 15:29  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Debug\ModbusApiTestForCsharp_1.vshost.exe.manifest

     文件     266752  2016-12-29 18:38  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Debug\ModbusTcpAPI.dll

     文件     239616  2016-12-29 18:38  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Debug\StandardModbusApi.dll

     文件      10240  2016-12-30 09:51  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Release\ModbusApiTestForCsharp_1.exe

     文件      22016  2016-12-30 09:51  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Release\ModbusApiTestForCsharp_1.pdb

     文件      11600  2016-12-30 09:45  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Release\ModbusApiTestForCsharp_1.vshost.exe

     文件        490  2009-08-31 00:40  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Release\ModbusApiTestForCsharp_1.vshost.exe.manifest

     文件     266752  2016-12-29 18:38  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Release\ModbusTcpAPI.dll

     文件     239616  2016-12-29 18:38  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\bin\Release\StandardModbusApi.dll

     文件       7710  2020-03-04 16:05  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\Form1.cs

     文件       5017  2020-03-04 15:59  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\Form1.Designer.cs

     文件       5817  2020-03-04 15:59  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\Form1.resx

     文件       3707  2016-12-30 09:44  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1.csproj

     文件       2870  2020-03-04 15:56  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7398  2020-06-03 14:04  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       2944  2020-06-03 14:05  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Debug\ModbusApiTestForCsharp_1.csproj.FileListAbsolute.txt

     文件        976  2020-03-04 15:59  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Debug\ModbusApiTestForCsharp_1.csproj.GenerateResource.Cache

     文件       9177  2020-03-04 15:59  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Debug\ModbusApiTestForCsharp_1.csprojResolveAssemblyReference.cache

     文件      11776  2020-03-04 16:05  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Debug\ModbusApiTestForCsharp_1.exe

     文件        180  2020-03-04 15:59  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Debug\ModbusApiTestForCsharp_1.Form1.resources

     文件      26112  2020-03-04 16:05  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Debug\ModbusApiTestForCsharp_1.pdb

     文件        180  2016-12-30 09:44  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Debug\ModbusApiTestForCsharp_1.Properties.Resources.resources

     文件       6272  2016-12-30 09:51  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Release\DesignTimeResolveAssemblyReferencesInput.cache

     文件        750  2016-12-30 09:50  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Release\ModbusApiTestForCsharp_1.csproj.FileListAbsolute.txt

     文件        975  2016-12-30 09:50  ModbusApiTestForCsharp_1\ModbusApiTestForCsharp_1\obj\x86\Release\ModbusApiTestForCsharp_1.csproj.GenerateResource.Cache

............此处省略30个文件信息

评论

共有 条评论