XNET 通讯dll

XNET 通讯dll
  • XNET总线技术是信捷电气自主研发的一套高速总线,支持串行口、USB口、局域网ID指定、局域网IP指定、远程通讯连接。
  • 本库适用于信捷XD/XL/XG系列PLC,TGM系列HMI。远程通讯连接可支持4GBOX、WBOX系列网关。
  • 相比Modbus TCP等现场总线,XNET具有传输速率快、通讯稳定、异步响应等特点,在信捷产品中广泛使用。
XNET 通讯dll
XNET服务模型

XNET串口通讯示例C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XNetClient;

namespace 串口通讯范例
{
    class Program
    {
        /// <summary>
        /// 服务发开的串口在使用服务通信时是支持复用的。
        /// 即可以同时创建多个XNet_Comm,对同一个COM口进行通信,不会被告知串口占用
        /// 要注意端口的打开和释放
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            ///用此方式释放对象并复用原通信句柄
            /// try { XNet_Comm.CloseXNet(); }
            /// catch { }
            /// XNet_Comm = new XNet();
            ///
            XNet XNet_Comm = new XNet(); ;

            //要求服务打开串口
            XNet_Comm.SetComPort("COM3");//“自动查找”不需要手动打开端口,但要手动释放最近使用的端口


            //查找设备、获取通信地址、建立通信路由
            XNet_Comm.FindDevice("COM3", XNetDevice.PLC_XE);
            //XNet_Comm.FindDevice("自动查找", XNetDevice.PLC_XE);
            //XNet_Comm.FindDevice("COM3"\"自动查找", _idStr)支持ID查找

            UInt16[] writeRegs = new UInt16[10] { 0,1,2,3,4,5,6,7,8,9};
            XNet_Comm.WriteRegs(XNetRegs.D, 100, writeRegs);

            UInt16[] readRegs = new UInt16[10];
            XNet_Comm.ReadRegs(XNetRegs.D, 100, readRegs);

            UInt16[] writeCoils = new UInt16[10] { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };
            XNet_Comm.WriteCoils(XNetCoils.M, 100, writeCoils);

            UInt16[] readCoils = new UInt16[10];
            XNet_Comm.ReadCoils(XNetCoils.M, 100, readCoils);

            //让服务关闭最近使用的通信端口
            XNet_Comm.ReleaseComPort();

            //释放服务资源
            XNet_Comm.CloseXNet();
        }
    }
}

XNET串口通讯示例C++


#include <iostream>
#include "XNetClient_cpp.h"
#pragma comment(lib,"XNetClient_cpp")
using namespace XINJE;

int main()
{
	int Ret;

	XNetClient::StartXNetWindows();
	XNetClient::WinSockInit();

	XNetClient xNetClient;
	Ret = xNetClient.XNetCommunication();
	Ret = xNetClient.SetComPort(3);//打开串口

	Ret = xNetClient.FindDevice(3, PLC_XD);//从打开的串口口查找设备(XDPLC)


	short writeRegs[10] = { 1,2,3,4,5,6,7,8,9,-1 };
	short readRegs[10];
	Ret = xNetClient.WriteRegs(XNet_D, 0, 10, writeRegs);
	Ret = xNetClient.ReadRegs(XNet_D, 0, 10, readRegs);

	short writeCoils[10] = { 0,1,1,1,1,1,1,1,0,0 };
	short readCoils[10];
	Ret = xNetClient.WriteCoils(XNet_M, 0, 10, writeCoils);
	Ret = xNetClient.ReadCoils(XNet_M, 0, 10, readCoils);

	Ret = xNetClient.ReleaseComPort(3);//关闭串口
	std::cin >> Ret;
}

完整示例请下载附件:

发布者:刘 炼,转转请注明出处:https://college.xinje.net/uncategorized/xnet-dll/1196/

(25)
上一篇 2021年6月16日 08:23
下一篇 2021年6月21日 10:57

相关推荐

扫码关注

扫码关注微信

关注我们获取最新资讯

公众号

小程序

使用微信扫码体验小程序

P_USER_微信小程序

 

分享本页
返回顶部