• 大小: 471KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-11
  • 语言: C#
  • 标签: 台达PLC  modbus  64位  C#  

资源简介

台达PLC modbus通信上位机64位C#实例程序,vs2010亲测可用。台达PLC modbus通信上位机64位C#实例程序,vs2010亲测可用。

资源截图

代码片段和文件信息

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


using Microsoft.Win32; // for the registry table
using System.Net; // for the ip address
using System.Runtime.InteropServices; // for the P/Invoke

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {

        System.IntPtr hDMTDll; // handle of a loaded DLL
        
        delegate void DelegateClose(int conn_num); // function pointer for disconnection
        
         // About .Net P/Invoke:

         // [DllImport(“XXX.dll“ CharSet = CharSet.Auto)] 
         // static extern int ABC(int a  int b);
          
         // indicates that “ABC“ function is imported from XXX.dll
         // XXX.dll exports a function of the same name with “ABC“
         // the return type and the parameter‘s data type of “ABC“ 
         // must be identical with the function exported from XXX.dll
         // and the CharSet = CharSet.Auto causes the CLR 
         // to use the appropriate character set based on the host OS   
        [DllImport(“kernel32.dll“ CharSet = CharSet.Auto)]
        static extern IntPtr LoadLibrary(string dllPath);
        [DllImport(“kernel32.dll“ CharSet = CharSet.Auto)]
        static extern bool FreeLibrary(IntPtr hDll);

        // Data Access
        [DllImport(“DMT.dll“ CharSet = CharSet.Auto)] 
        static extern int  RequestData(int comm_type int conn_num int slave_addr int func_code byte[] sendbuf int sendlen);
        [DllImport(“DMT.dll“ CharSet = CharSet.Auto)] 
        static extern int  ResponseData(int comm_type int conn_num ref int slave_addr ref int func_code byte[] recvbuf);

        // Serial Communication
        [DllImport(“DMT.dll“ CharSet = CharSet.Auto)] 
        static extern int OpenModbusSerial(int conn_num int baud_rate int data_len char parity int stop_bits int modbus_mode);
        [DllImport(“DMT.dll“ CharSet = CharSet.Auto)] 
        static extern void CloseSerial(int conn_num);
        [DllImport(“DMT.dll“ CharSet = CharSet.Auto)] 
        static extern int GetLastSerialErr();
        [DllImport(“DMT.dll“ CharSet = CharSet.Auto)] 
        static extern void ResetSerialErr();

        // Socket Communication
        [DllImport(“DMT.dll“ CharSet = CharSet.Auto)] 
        static extern int OpenModbusTCPSocket(int conn_num int ipaddr int port);
        [DllImport(“DMT.dll“ CharSet = CharSet.Auto)] 
        static extern void CloseSocket(int conn_num);
        [DllImport(“DMT.dll“ CharSet = CharSet.Auto)] 
        static extern int GetLastSocketErr();
        [DllImport(“DMT.dll“ CharSet = CharSet.Auto)] 
        static extern void ResetSocketErr();
        [DllImport(“DMT.dll“ CharSet = CharSet.Auto)] 
        static extern int ReadSelect(int conn_num int millisecs);

        // MODBUS Address Calculation
        [DllImpo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-12-06 10:07  Example_C# 2005\
     目录           0  2016-12-05 20:14  Example_C# 2005\Backup\
     目录           0  2016-12-05 20:14  Example_C# 2005\Backup\WindowsApplication1\
     文件         946  2011-04-27 15:55  Example_C# 2005\Backup\WindowsApplication1.sln
     文件       39424  2014-06-19 18:26  Example_C# 2005\Backup\WindowsApplication1.suo
     文件       19935  2014-06-19 18:26  Example_C# 2005\Backup\WindowsApplication1\Form1.cs
     文件       23945  2014-06-19 18:26  Example_C# 2005\Backup\WindowsApplication1\Form1.Designer.cs
     文件        5814  2014-06-19 18:26  Example_C# 2005\Backup\WindowsApplication1\Form1.resx
     文件         486  2011-04-27 15:55  Example_C# 2005\Backup\WindowsApplication1\Program.cs
     目录           0  2016-12-05 20:14  Example_C# 2005\Backup\WindowsApplication1\Properties\
     文件        1286  2011-04-27 15:55  Example_C# 2005\Backup\WindowsApplication1\Properties\AssemblyInfo.cs
     文件        2867  2011-04-27 15:55  Example_C# 2005\Backup\WindowsApplication1\Properties\Resources.Designer.cs
     文件        5612  2011-04-27 15:55  Example_C# 2005\Backup\WindowsApplication1\Properties\Resources.resx
     文件        1104  2011-04-27 15:55  Example_C# 2005\Backup\WindowsApplication1\Properties\Settings.Designer.cs
     文件         249  2011-04-27 15:55  Example_C# 2005\Backup\WindowsApplication1\Properties\Settings.settings
     文件        3295  2011-04-28 19:32  Example_C# 2005\Backup\WindowsApplication1\WindowsApplication1.csproj
     文件         168  2012-01-10 16:23  Example_C# 2005\Backup\WindowsApplication1\WindowsApplication1.csproj.user
     文件        5685  2016-12-05 20:14  Example_C# 2005\UpgradeLog.xml
     目录           0  2016-12-05 20:13  Example_C# 2005\WindowsApplication1\
     文件         947  2016-12-05 20:14  Example_C# 2005\WindowsApplication1.sln
     文件       49664  2016-12-05 21:01  Example_C# 2005\WindowsApplication1.suo
     目录           0  2016-12-05 20:13  Example_C# 2005\WindowsApplication1\bin\
     目录           0  2016-12-05 20:14  Example_C# 2005\WindowsApplication1\bin\Debug\
     文件      177152  2014-07-16 11:16  Example_C# 2005\WindowsApplication1\bin\Debug\DMT.dll
     文件       63062  2014-07-16 11:16  Example_C# 2005\WindowsApplication1\bin\Debug\DMT.lib
     文件       23552  2016-12-05 20:33  Example_C# 2005\WindowsApplication1\bin\Debug\WindowsApplication1.exe
     文件       44544  2016-12-05 20:33  Example_C# 2005\WindowsApplication1\bin\Debug\WindowsApplication1.pdb
     文件       11608  2016-12-05 21:00  Example_C# 2005\WindowsApplication1\bin\Debug\WindowsApplication1.vshost.exe
     文件         490  2010-03-17 22:39  Example_C# 2005\WindowsApplication1\bin\Debug\WindowsApplication1.vshost.exe.manifest
     文件      151552  2014-04-28 14:30  Example_C# 2005\WindowsApplication1\DMT.dll
     文件       19935  2016-12-05 20:33  Example_C# 2005\WindowsApplication1\Form1.cs
............此处省略32个文件信息

评论

共有 条评论