TianWeiToolsPro.Communication 3.1.0

dotnet add package TianWeiToolsPro.Communication --version 3.1.0
                    
NuGet\Install-Package TianWeiToolsPro.Communication -Version 3.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TianWeiToolsPro.Communication" Version="3.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TianWeiToolsPro.Communication" Version="3.1.0" />
                    
Directory.Packages.props
<PackageReference Include="TianWeiToolsPro.Communication" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TianWeiToolsPro.Communication --version 3.1.0
                    
#r "nuget: TianWeiToolsPro.Communication, 3.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TianWeiToolsPro.Communication@3.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TianWeiToolsPro.Communication&version=3.1.0
                    
Install as a Cake Addin
#tool nuget:?package=TianWeiToolsPro.Communication&version=3.1.0
                    
Install as a Cake Tool

TianWeiToolsPro

TianWeiToolsPro 是天威开发的设备/通信相关工具集合,主要沉淀 PLC、串口设备等常用工业通讯与设备控制能力,并与 TianWeiToolsPro.Common(通用基础能力)配套使用。

目标框架

该项目为多目标框架构建(以 TianWeiToolsPro.csproj 为准),在当前工作区可见包含:

  • .NET Framework 4.7.2
  • .NET Framework 4.8
  • .NET 6 (Windows)
  • .NET 8 (Windows)
  • .NET 10 (Windows)

模块概览

Device

设备与通信相关能力集中在 Device 命名空间下。

Plc

PLC 相关操作助手(以源码实现为准),当前工程中可见:

  • 欧姆龙(Omron)UDP 协议相关 PLC 操作
  • 欧姆龙(Omron)TCP 协议相关 PLC 操作(新增)
  • 三菱(Melsec)UDP 协议相关 PLC 操作
  • 三菱(Melsec)TCP 协议相关 PLC 操作(新增)
  • Modbus UDP 协议相关 PLC 操作(2026-02-11 16:30 新增)
  • Modbus TCP 协议相关 PLC 操作(2026-02-11 16:30 新增)
  • 三菱 MC 协议 UDP 仿真器 MelsecMcUdpSimulator(新增,用于本地联调/测试)

典型能力(以实际类/方法为准):

  • 连接/断开
  • 读写寄存器/位
  • 常用地址解析与报文封装
SerialPort

串口设备操作类:用于直流电源、电子负载等设备的通讯与控制(以具体设备驱动类为准)。

典型能力(以实际类/方法为准):

  • 串口参数配置(波特率/校验位/停止位等)
  • 发送/接收以及协议封装
  • 设备状态查询与指令执行

与其他项目的关系

  • TianWeiToolsPro.Common:通用扩展方法、CRC/校验、MVVM 基类、命令/事件总线等基础能力

使用方式

方式一:项目引用

TianWeiToolsPro.Device 添加到解决方案并在你的业务项目中引用。

方式二:引用 DLL

编译后引用输出的 DLL。

说明

由于该库涉及与设备通讯,部分能力与现场协议、设备型号、寄存器地址等强相关;建议在业务侧对协议/地址配置做隔离与版本管理,避免硬编码分散。

变更记录 2026-02-11 16:30

  • 新增:MelsecTcp
  • 新增:OmronTcp
  • 新增:ModbusTcp
  • 新增:ModbusUdp
  • 新增:MelsecMcUdpSimulator,用于本地联调/测试,后期将支持更多协议仿真
ModbusTcp / ModbusUdp 使用示例

注意:ModbusTcp / ModbusUdp 当前地址只支持“纯数字的字符串”格式(例如 "0""1""100"),不支持 "D100""X1""M100" 等带前缀的地址写法。

using System;
using TianWeiToolsPro.Device.Plc;

// 仅示例:以源码中的构造参数/方法为准

// TCP
var modbusTcp = new ModbusTcp("192.168.1.10", port: 502);
modbusTcp.Connect();
modbusTcp.WriteWord("100", 123);
var v1 = modbusTcp.ReadWord("100");
modbusTcp.Disconnect();

// UDP
var modbusUdp = new ModbusUdp("192.168.1.10", port: 502);
modbusUdp.Connect();
modbusUdp.WriteBit("1", true);
var b1 = modbusUdp.ReadBit("1");
modbusUdp.Disconnect();

Console.WriteLine($"Word[100]={v1}, Bit[1]={b1}");
MelsecMcUdpSimulator 使用示例

用于在本机启动一个“三菱 MC 协议 UDP”的简易仿真器,便于业务侧在没有真实 PLC 的情况下进行联调/自动化测试。

using System;
using System.Net;
using TianWeiToolsPro.Device.Plc.Simulator;

// 仅示例:以源码中的构造参数/方法为准
// 初始化时可配置端口与绑定 IP(不指定则默认 IPAddress.Any)
var simulator = new MelsecMcUdpSimulator(port: 6000, bindAddress: IPAddress.Any);

// 启动监听
simulator.Start();

// 写入一些测试数据(例如 D 寄存器),然后用你的 Melsec MC/UDP 客户端去读取验证
// 下面 API 名称/地址格式以源码实现为准:
simulator.WriteWord("D100", 123);
simulator.WriteBit("M100", true);

// 读取当前仿真器内存(可用于断言/调试)
var d100 = simulator.ReadWord("D100");
var m100 = simulator.ReadBit("M100");

Console.WriteLine($"D100={d100}, M100={m100}");

// 停止
simulator.Stop();

外部监控地址数据变更(订阅事件):

using System;
using System.Net;
using TianWeiToolsPro.Device.Plc;

// 初始化时可配置端口与绑定 IP(不指定则默认 IPAddress.Any)
var simulator = new MelsecMcUdpSimulator(port: 6000, bindAddress: IPAddress.Any);

// 订阅:当外部客户端(或本地 SetD) 写入 D 寄存器时触发
simulator.DWordChanged += (s, e) =>
{
    // 可按地址过滤要监控的点位
    if (e.Address == 100)
    {
        Console.WriteLine($"D{e.Address} changed: {e.OldValue} -> {e.NewValue}");
    }
};

simulator.Start();

// ...此时用你的 MC/UDP 客户端写入 D100,或调用 simulator.SetD(100, xxx)

simulator.Stop();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Framework net472 is compatible.  net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 97 3/23/2026