写一个 NmodbusHelper
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
using Modbus.Device;
using thinger.cn;
namespace NmodbusHelper
{
public class Modbus4TCP
{
private TcpClient tcpClient = null;
private ModbusIpMaster master;
#region 打开与关闭Socket
public bool Connect(string ip, int port)
{
try
{
tcpClient = new TcpClient();
tcpClient.Connect(IPAddress.Parse(ip), port);
//IPEndPoint ie = new IPEndPoint(IPAddress.Parse(ip), port);
//tcpClient.Connect(ie);
master = ModbusIpMaster.CreateIp(tcpClient);
}
catch (Exception)
{

本文介绍了如何使用NModbusHelper库进行TCP连接,实现Modbus协议的4功能码读取,包括读取保持寄存器并以unsigned和float格式转换输出。展示了在Windows Form应用中连接、读取和断开操作的实例。
最低0.47元/天 解锁文章
1万+





