Some Fix
This commit is contained in:
31
Modbus.Net/Modbus.Net.Modbus.NA200H/AddressFormaterNA200H.cs
Normal file
31
Modbus.Net/Modbus.Net.Modbus.NA200H/AddressFormaterNA200H.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace Modbus.Net.Modbus.NA200H
|
||||
{
|
||||
/// <summary>
|
||||
/// 南大奥拓NA200H专用AddressFormater
|
||||
/// </summary>
|
||||
public class AddressFormaterNA200H : AddressFormater
|
||||
{
|
||||
/// <summary>
|
||||
/// 格式化地址
|
||||
/// </summary>
|
||||
/// <param name="area">地址区域</param>
|
||||
/// <param name="address">地址</param>
|
||||
/// <returns>格式化的地址字符串</returns>
|
||||
public override string FormatAddress(string area, int address)
|
||||
{
|
||||
return area + " " + address;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 格式化地址
|
||||
/// </summary>
|
||||
/// <param name="area">地址区域</param>
|
||||
/// <param name="address">地址</param>
|
||||
/// <param name="subAddress">比特位地址</param>
|
||||
/// <returns>格式化的地址字符串</returns>
|
||||
public override string FormatAddress(string area, int address, int subAddress)
|
||||
{
|
||||
return area + " " + address + "." + subAddress;
|
||||
}
|
||||
}
|
||||
}
|
||||
262
Modbus.Net/Modbus.Net.Modbus.NA200H/AddressTranslatorNA200H.cs
Normal file
262
Modbus.Net/Modbus.Net.Modbus.NA200H/AddressTranslatorNA200H.cs
Normal file
@@ -0,0 +1,262 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net.Modbus.NA200H
|
||||
{
|
||||
/// <summary>
|
||||
/// 南大奥拓NA200H数据单元翻译器
|
||||
/// </summary>
|
||||
public class AddressTranslatorNA200H : ModbusTranslatorBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 读功能码
|
||||
/// </summary>
|
||||
protected Dictionary<string, AreaOutputDef> ReadFunctionCodeDictionary;
|
||||
|
||||
/// <summary>
|
||||
/// 功能码翻译至标准Modbus地址位置
|
||||
/// </summary>
|
||||
protected Dictionary<string, int> TransDictionary;
|
||||
|
||||
/// <summary>
|
||||
/// 写功能码
|
||||
/// </summary>
|
||||
protected Dictionary<(string, bool), AreaOutputDef> WriteFunctionCodeDictionary;
|
||||
|
||||
/// <summary>
|
||||
/// 构造器
|
||||
/// </summary>
|
||||
public AddressTranslatorNA200H()
|
||||
{
|
||||
TransDictionary = new Dictionary<string, int>
|
||||
{
|
||||
{"Q", 0},
|
||||
{"M", 10000},
|
||||
{"N", 30000},
|
||||
{"I", 0},
|
||||
{"S", 10000},
|
||||
{"IW", 0},
|
||||
{"SW", 5000},
|
||||
{"MW", 0},
|
||||
{"QW", 20000},
|
||||
{"NW", 21000}
|
||||
};
|
||||
ReadFunctionCodeDictionary = new Dictionary<string, AreaOutputDef>
|
||||
{
|
||||
{
|
||||
"Q",
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolReadDataFunctionCode.ReadCoilStatus,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
"M",
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolReadDataFunctionCode.ReadCoilStatus,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
"N",
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolReadDataFunctionCode.ReadCoilStatus,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
"I",
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolReadDataFunctionCode.ReadInputStatus,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
"S",
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolReadDataFunctionCode.ReadInputStatus,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
"IW",
|
||||
new AreaOutputDef {Code = (int) ModbusProtocolReadDataFunctionCode.ReadInputRegister, AreaWidth = 2}
|
||||
},
|
||||
{
|
||||
"SW",
|
||||
new AreaOutputDef {Code = (int) ModbusProtocolReadDataFunctionCode.ReadInputRegister, AreaWidth = 2}
|
||||
},
|
||||
{
|
||||
"MW",
|
||||
new AreaOutputDef {Code = (int) ModbusProtocolReadDataFunctionCode.ReadHoldRegister, AreaWidth = 2}
|
||||
},
|
||||
{
|
||||
"NW",
|
||||
new AreaOutputDef {Code = (int) ModbusProtocolReadDataFunctionCode.ReadHoldRegister, AreaWidth = 2}
|
||||
},
|
||||
{
|
||||
"QW",
|
||||
new AreaOutputDef {Code = (int) ModbusProtocolReadDataFunctionCode.ReadHoldRegister, AreaWidth = 2}
|
||||
}
|
||||
};
|
||||
WriteFunctionCodeDictionary = new Dictionary<(string, bool), AreaOutputDef>
|
||||
{
|
||||
{
|
||||
("Q", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("M", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("N", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("MW", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
},
|
||||
{
|
||||
("NW", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
},
|
||||
{
|
||||
("QW", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
},
|
||||
{
|
||||
("Q", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("M", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("N", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("MW", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
},
|
||||
{
|
||||
("NW", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
},
|
||||
{
|
||||
("QW", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 地址转换
|
||||
/// </summary>
|
||||
/// <param name="address">格式化的地址</param>
|
||||
/// <param name="isRead">是否为读取,是为读取,否为写入</param>
|
||||
/// <param name="isSingle">是否只写入一个数据</param>
|
||||
/// <returns>翻译后的地址</returns>
|
||||
public override AddressDef AddressTranslate(string address, bool isRead, bool isSingle)
|
||||
{
|
||||
address = address.ToUpper();
|
||||
var splitString = address.Split(' ');
|
||||
var head = splitString[0];
|
||||
var tail = splitString[1];
|
||||
string sub;
|
||||
if (tail.Contains('.'))
|
||||
{
|
||||
var splitString2 = tail.Split('.');
|
||||
sub = splitString2[1];
|
||||
tail = splitString2[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
sub = "0";
|
||||
}
|
||||
return isRead
|
||||
? new AddressDef
|
||||
{
|
||||
AreaString = head,
|
||||
Area = ReadFunctionCodeDictionary[head].Code,
|
||||
Address = TransDictionary[head] + int.Parse(tail) - 1,
|
||||
SubAddress = int.Parse(sub)
|
||||
}
|
||||
: new AddressDef
|
||||
{
|
||||
AreaString = head,
|
||||
Area = WriteFunctionCodeDictionary[(head, isSingle)].Code,
|
||||
Address = TransDictionary[head] + int.Parse(tail) - 1,
|
||||
SubAddress = int.Parse(sub)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取区域中的单个地址占用的字节长度
|
||||
/// </summary>
|
||||
/// <param name="area">区域名称</param>
|
||||
/// <returns>字节长度</returns>
|
||||
public override double GetAreaByteLength(string area)
|
||||
{
|
||||
return ReadFunctionCodeDictionary[area].AreaWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Modbus.Net.Modbus\Modbus.Net.Modbus.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,34 +1,5 @@
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// 南大奥拓NA200H专用AddressFormater
|
||||
/// </summary>
|
||||
public class AddressFormaterNA200H : AddressFormater
|
||||
{
|
||||
/// <summary>
|
||||
/// 格式化地址
|
||||
/// </summary>
|
||||
/// <param name="area">地址区域</param>
|
||||
/// <param name="address">地址</param>
|
||||
/// <returns>格式化的地址字符串</returns>
|
||||
public override string FormatAddress(string area, int address)
|
||||
{
|
||||
return area + " " + address;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 格式化地址
|
||||
/// </summary>
|
||||
/// <param name="area">地址区域</param>
|
||||
/// <param name="address">地址</param>
|
||||
/// <param name="subAddress">比特位地址</param>
|
||||
/// <returns>格式化的地址字符串</returns>
|
||||
public override string FormatAddress(string area, int address, int subAddress)
|
||||
{
|
||||
return area + " " + address + "." + subAddress;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modbus标准AddressFormater
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -29,260 +28,6 @@ namespace Modbus.Net.Modbus
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 南大奥拓NA200H数据单元翻译器
|
||||
/// </summary>
|
||||
public class AddressTranslatorNA200H : ModbusTranslatorBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 读功能码
|
||||
/// </summary>
|
||||
protected Dictionary<string, AreaOutputDef> ReadFunctionCodeDictionary;
|
||||
|
||||
/// <summary>
|
||||
/// 功能码翻译至标准Modbus地址位置
|
||||
/// </summary>
|
||||
protected Dictionary<string, int> TransDictionary;
|
||||
|
||||
/// <summary>
|
||||
/// 写功能码
|
||||
/// </summary>
|
||||
protected Dictionary<(string, bool), AreaOutputDef> WriteFunctionCodeDictionary;
|
||||
|
||||
/// <summary>
|
||||
/// 构造器
|
||||
/// </summary>
|
||||
public AddressTranslatorNA200H()
|
||||
{
|
||||
TransDictionary = new Dictionary<string, int>
|
||||
{
|
||||
{"Q", 0},
|
||||
{"M", 10000},
|
||||
{"N", 30000},
|
||||
{"I", 0},
|
||||
{"S", 10000},
|
||||
{"IW", 0},
|
||||
{"SW", 5000},
|
||||
{"MW", 0},
|
||||
{"QW", 20000},
|
||||
{"NW", 21000}
|
||||
};
|
||||
ReadFunctionCodeDictionary = new Dictionary<string, AreaOutputDef>
|
||||
{
|
||||
{
|
||||
"Q",
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolReadDataFunctionCode.ReadCoilStatus,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
"M",
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolReadDataFunctionCode.ReadCoilStatus,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
"N",
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolReadDataFunctionCode.ReadCoilStatus,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
"I",
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolReadDataFunctionCode.ReadInputStatus,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
"S",
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolReadDataFunctionCode.ReadInputStatus,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
"IW",
|
||||
new AreaOutputDef {Code = (int) ModbusProtocolReadDataFunctionCode.ReadInputRegister, AreaWidth = 2}
|
||||
},
|
||||
{
|
||||
"SW",
|
||||
new AreaOutputDef {Code = (int) ModbusProtocolReadDataFunctionCode.ReadInputRegister, AreaWidth = 2}
|
||||
},
|
||||
{
|
||||
"MW",
|
||||
new AreaOutputDef {Code = (int) ModbusProtocolReadDataFunctionCode.ReadHoldRegister, AreaWidth = 2}
|
||||
},
|
||||
{
|
||||
"NW",
|
||||
new AreaOutputDef {Code = (int) ModbusProtocolReadDataFunctionCode.ReadHoldRegister, AreaWidth = 2}
|
||||
},
|
||||
{
|
||||
"QW",
|
||||
new AreaOutputDef {Code = (int) ModbusProtocolReadDataFunctionCode.ReadHoldRegister, AreaWidth = 2}
|
||||
}
|
||||
};
|
||||
WriteFunctionCodeDictionary = new Dictionary<(string, bool), AreaOutputDef>
|
||||
{
|
||||
{
|
||||
("Q", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("M", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("N", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("MW", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
},
|
||||
{
|
||||
("NW", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
},
|
||||
{
|
||||
("QW", false),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteMultiRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
},
|
||||
{
|
||||
("Q", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("M", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("N", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleCoil,
|
||||
AreaWidth = 0.125
|
||||
}
|
||||
},
|
||||
{
|
||||
("MW", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
},
|
||||
{
|
||||
("NW", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
},
|
||||
{
|
||||
("QW", true),
|
||||
new AreaOutputDef
|
||||
{
|
||||
Code = (int) ModbusProtocolWriteDataFunctionCode.WriteSingleRegister,
|
||||
AreaWidth = 2
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 地址转换
|
||||
/// </summary>
|
||||
/// <param name="address">格式化的地址</param>
|
||||
/// <param name="isRead">是否为读取,是为读取,否为写入</param>
|
||||
/// <param name="isSingle">是否只写入一个数据</param>
|
||||
/// <returns>翻译后的地址</returns>
|
||||
public override AddressDef AddressTranslate(string address, bool isRead, bool isSingle)
|
||||
{
|
||||
address = address.ToUpper();
|
||||
var splitString = address.Split(' ');
|
||||
var head = splitString[0];
|
||||
var tail = splitString[1];
|
||||
string sub;
|
||||
if (tail.Contains('.'))
|
||||
{
|
||||
var splitString2 = tail.Split('.');
|
||||
sub = splitString2[1];
|
||||
tail = splitString2[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
sub = "0";
|
||||
}
|
||||
return isRead
|
||||
? new AddressDef
|
||||
{
|
||||
AreaString = head,
|
||||
Area = ReadFunctionCodeDictionary[head].Code,
|
||||
Address = TransDictionary[head] + int.Parse(tail) - 1,
|
||||
SubAddress = int.Parse(sub)
|
||||
}
|
||||
: new AddressDef
|
||||
{
|
||||
AreaString = head,
|
||||
Area = WriteFunctionCodeDictionary[(head, isSingle)].Code,
|
||||
Address = TransDictionary[head] + int.Parse(tail) - 1,
|
||||
SubAddress = int.Parse(sub)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取区域中的单个地址占用的字节长度
|
||||
/// </summary>
|
||||
/// <param name="area">区域名称</param>
|
||||
/// <returns>字节长度</returns>
|
||||
public override double GetAreaByteLength(string area)
|
||||
{
|
||||
return ReadFunctionCodeDictionary[area].AreaWidth;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modbus数据单元翻译器
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public ModbusAsciiInTcpProtocol(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
@@ -13,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="ip">IP地址</param>
|
||||
public ModbusAsciiInTcpProtocolLinker(string ip)
|
||||
: base(ip, int.Parse(ConfigurationManager.AppSettings["ModbusPort"] ?? "502"), false)
|
||||
: base(ip, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"), false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Modbus.Net.Modbus
|
||||
public ModbusAsciiInTcpProtocolLinker(string ip, int port)
|
||||
: base(ip, port)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "100")));
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "100")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -18,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public ModbusAsciiInUdpProtocol(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -17,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="ip">IP地址</param>
|
||||
public ModbusAsciiInUdpProtocolLinker(string ip)
|
||||
: base(ip, int.Parse(ConfigurationManager.AppSettings["ModbusPort"] ?? "502"), false)
|
||||
: base(ip, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"), false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -29,7 +25,7 @@ namespace Modbus.Net.Modbus
|
||||
public ModbusAsciiInUdpProtocolLinker(string ip, int port)
|
||||
: base(ip, port)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public ModbusAsciiProtocol(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["COM"], slaveAddress, masterAddress)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["COM"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
using System.Text;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Modbus.Net.Modbus
|
||||
public ModbusAsciiProtocolLinker(string com, int slaveAddress)
|
||||
: base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[] { new List<(int,int)> { (1,1), (2,2) }, new List<(int, int)> { (3, 3), (4, 4) }}, int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[] { new List<(int,int)> { (1,1), (2,2) }, new List<(int, int)> { (3, 3), (4, 4) }}, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <summary>
|
||||
/// 跟写数据有关的功能码
|
||||
/// </summary>
|
||||
internal enum ModbusProtocolWriteDataFunctionCode : byte
|
||||
public enum ModbusProtocolWriteDataFunctionCode : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// 写单个线圈
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Configuration;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -14,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public ModbusRtuInTcpProtocol(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -12,7 +12,7 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="ip">IP地址</param>
|
||||
public ModbusRtuInTcpProtocolLinker(string ip)
|
||||
: base(ip, int.Parse(ConfigurationManager.AppSettings["ModbusPort"] ?? "502"), false)
|
||||
: base(ip, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"), false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Modbus.Net.Modbus
|
||||
public ModbusRtuInTcpProtocolLinker(string ip, int port)
|
||||
: base(ip, port)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -18,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public ModbusRtuInUdpProtocol(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -17,7 +12,7 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="ip">IP地址</param>
|
||||
public ModbusRtuInUdpProtocolLinker(string ip)
|
||||
: base(ip, int.Parse(ConfigurationManager.AppSettings["ModbusPort"] ?? "502"), false)
|
||||
: base(ip, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"), false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -29,7 +24,7 @@ namespace Modbus.Net.Modbus
|
||||
public ModbusRtuInUdpProtocolLinker(string ip, int port)
|
||||
: base(ip, port)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public ModbusRtuProtocol(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["COM"], slaveAddress, masterAddress)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["COM"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
@@ -17,7 +17,7 @@ namespace Modbus.Net.Modbus
|
||||
public ModbusRtuProtocolLinker(string com, int slaveAddress)
|
||||
: base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[]{new List<(int,int)>{(0,0)}, new List<(int, int)>{(1,1)}}, int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[]{new List<(int,int)>{(0,0)}, new List<(int, int)>{(1,1)}}, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public ModbusTcpProtocol(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="ip">IP地址</param>
|
||||
public ModbusTcpProtocolLinker(string ip)
|
||||
: this(ip, int.Parse(ConfigurationManager.AppSettings["ModbusPort"] ?? "502"))
|
||||
: this(ip, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="port">端口</param>
|
||||
public ModbusTcpProtocolLinker(string ip, int port) : base(ip, port)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int>{4,5}, 6)));
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int>{4,5}, 6)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public ModbusUdpProtocol(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="ip">IP地址</param>
|
||||
public ModbusUdpProtocolLinker(string ip)
|
||||
: this(ip, int.Parse(ConfigurationManager.AppSettings["ModbusPort"] ?? "502"))
|
||||
: this(ip, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="port">端口</param>
|
||||
public ModbusUdpProtocolLinker(string ip, int port) : base(ip, port)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int> { 4, 5 }, 6)));
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int> { 4, 5 }, 6)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Nito.AsyncEx;
|
||||
|
||||
namespace Modbus.Net.Siemens
|
||||
@@ -18,7 +18,7 @@ namespace Modbus.Net.Siemens
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public SiemensPpiProtocol(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["COM"], slaveAddress, masterAddress)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["COM"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.IO.Ports;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -19,7 +19,7 @@ namespace Modbus.Net.Siemens
|
||||
public SiemensPpiProtocolLinker(string com, int slaveAddress)
|
||||
: base(com, 9600, Parity.Even, StopBits.One, 8, slaveAddress)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Nito.AsyncEx;
|
||||
|
||||
namespace Modbus.Net.Siemens
|
||||
@@ -31,7 +31,7 @@ namespace Modbus.Net.Siemens
|
||||
/// <param name="maxPdu"></param>
|
||||
public SiemensTcpProtocol(byte tdpuSize, ushort tsapSrc, ushort tsapDst, ushort maxCalling, ushort maxCalled,
|
||||
ushort maxPdu)
|
||||
: this(tdpuSize, tsapSrc, tsapDst, maxCalling, maxCalled, maxPdu, ConfigurationManager.AppSettings["IP"])
|
||||
: this(tdpuSize, tsapSrc, tsapDst, maxCalling, maxCalled, maxPdu, new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"])
|
||||
{
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Modbus.Net.Siemens
|
||||
ushort maxPdu, string ip)
|
||||
: this(
|
||||
tdpuSize, tsapSrc, tsapDst, maxCalling, maxCalled, maxPdu, ip,
|
||||
int.Parse(ConfigurationManager.AppSettings["SiemensPort"] ?? "102"))
|
||||
int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["SiemensPort"] ?? "102"))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
|
||||
namespace Modbus.Net.Siemens
|
||||
{
|
||||
@@ -15,7 +14,7 @@ namespace Modbus.Net.Siemens
|
||||
/// </summary>
|
||||
/// <param name="ip">IP地址</param>
|
||||
public SiemensTcpProtocolLinker(string ip)
|
||||
: this(ip, int.Parse(ConfigurationManager.AppSettings["SiemensPort"] ?? "102"))
|
||||
: this(ip, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["SiemensPort"] ?? "102"))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -27,7 +26,7 @@ namespace Modbus.Net.Siemens
|
||||
public SiemensTcpProtocolLinker(string ip, int port)
|
||||
: base(ip, port)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new MatchDirectlySendController(new ICollection<(int,int)>[] { new List<(int,int)> { (11,11), (12,12) } }, int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0"), DuplicateWithCount.GetDuplcateFunc(new List<int>{2, 3}, 0)));
|
||||
((BaseConnector)BaseConnector).AddController(new MatchDirectlySendController(new ICollection<(int,int)>[] { new List<(int,int)> { (11,11), (12,12) } }, DuplicateWithCount.GetDuplcateFunc(new List<int>{2, 3}, 0)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{3597
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.Modbus.Test", "..\Samples\Modbus.Net.Modbus.Test\Modbus.Net.Modbus.Test.csproj", "{22A35CA8-CDCF-416D-BA84-08C933B4A3DE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modbus.Net.Modbus.NA200H", "Modbus.Net.Modbus.NA200H\Modbus.Net.Modbus.NA200H.csproj", "{D4AF0E1E-676E-43B6-BAA3-BFC329D68C80}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -48,6 +50,10 @@ Global
|
||||
{22A35CA8-CDCF-416D-BA84-08C933B4A3DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{22A35CA8-CDCF-416D-BA84-08C933B4A3DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{22A35CA8-CDCF-416D-BA84-08C933B4A3DE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D4AF0E1E-676E-43B6-BAA3-BFC329D68C80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D4AF0E1E-676E-43B6-BAA3-BFC329D68C80}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D4AF0E1E-676E-43B6-BAA3-BFC329D68C80}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D4AF0E1E-676E-43B6-BAA3-BFC329D68C80}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="COM" value="COM1" />
|
||||
<add key="FBoxOpcDaHost" value="opcda://localhost/FBoxOpcServer" />
|
||||
<add key="IP" value="192.168.1.1" />
|
||||
<add key="ComConnectionTimeout" value="3000" />
|
||||
<add key="IPConnectionTimeout" value="5000" />
|
||||
<add key="ModbusPort" value="502" />
|
||||
<add key="OpcDaHost" value="opcda://localhost/..." />
|
||||
<add key="OpcUaHost" value="opc.tcp://localhost/..." />
|
||||
<add key="SiemensPort" value="102" />
|
||||
<add key="FetchSleepTime" value="100" />
|
||||
</appSettings>
|
||||
</configuration>
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Nito.AsyncEx;
|
||||
using Serilog;
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net
|
||||
namespace Modbus.Net
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据返回代理参数
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net
|
||||
{
|
||||
@@ -16,6 +13,8 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
/// <param name="receiveMessage">收到的报文信息</param>
|
||||
/// <param name="packageCountPositions">收到的断包长度查询位置</param>
|
||||
/// <param name="otherCount">除掉长度查询信息外其它报文的长度
|
||||
/// 注意:该长度不包含CRC校验</param>
|
||||
/// <returns>切分后的报文信息</returns>
|
||||
private static ICollection<byte[]> DuplicateMessages(byte[] receiveMessage, ICollection<int> packageCountPositions, int otherCount)
|
||||
{
|
||||
@@ -52,6 +51,8 @@ namespace Modbus.Net
|
||||
/// 获取按照长度断包的函数
|
||||
/// </summary>
|
||||
/// <param name="packageCountPositions">断包长度的位置信息</param>
|
||||
/// <param name="otherCount">除掉长度查询信息外其它报文的长度
|
||||
/// 注意:该长度不包含CRC校验</param>
|
||||
/// <returns>断包函数</returns>
|
||||
public static Func<byte[], ICollection<byte[]>> GetDuplcateFunc(ICollection<int> packageCountPositions, int otherCount)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net
|
||||
{
|
||||
@@ -12,9 +9,9 @@ namespace Modbus.Net
|
||||
public class MatchDirectlySendController : MatchController
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public MatchDirectlySendController(ICollection<(int, int)>[] keyMatches, int acquireTime,
|
||||
public MatchDirectlySendController(ICollection<(int, int)>[] keyMatches,
|
||||
Func<byte[], ICollection<byte[]>> duplicateFunc = null) : base(keyMatches,
|
||||
acquireTime, false, duplicateFunc)
|
||||
0, false, duplicateFunc)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net.Interface
|
||||
namespace Modbus.Net
|
||||
{
|
||||
public interface IMachine : IMachine<string>
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net.Interface
|
||||
namespace Modbus.Net
|
||||
{
|
||||
/// <summary>
|
||||
/// 没有Id的设备属性
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net.Interface
|
||||
namespace Modbus.Net
|
||||
{
|
||||
public interface IUtility : IUtilityProperty, IUtilityMethodData
|
||||
{
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net.Interface
|
||||
namespace Modbus.Net
|
||||
{
|
||||
/// <summary>
|
||||
/// Api入口的抽象
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
using Quartz.Listener;
|
||||
using Quartz;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net.Job
|
||||
namespace Modbus.Net
|
||||
{
|
||||
public class JobChainingJobListenerWithDataMap : JobListenerSupport
|
||||
{
|
||||
@@ -31,7 +28,7 @@ namespace Modbus.Net.Job
|
||||
/// </summary>
|
||||
/// <param name="firstJob">a JobKey with the name and group of the first job</param>
|
||||
/// <param name="secondJob">a JobKey with the name and group of the follow-up job</param>
|
||||
public new void AddJobChainLink(JobKey firstJob, JobKey secondJob)
|
||||
public void AddJobChainLink(JobKey firstJob, JobKey secondJob)
|
||||
{
|
||||
chainLinks.Add(firstJob, secondJob);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
using Modbus.Net.Interface;
|
||||
using Quartz;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using Quartz.Impl.Matchers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net.Job
|
||||
namespace Modbus.Net
|
||||
{
|
||||
public sealed class MachineJobSchedulerCreator
|
||||
{
|
||||
public static async Task<MachineGetJobScheduler> CreateScheduler(int count, int interval)
|
||||
public static async Task<MachineGetJobScheduler> CreateScheduler(string triggerKey, int count, int interval)
|
||||
{
|
||||
IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler();
|
||||
|
||||
ITrigger trigger;
|
||||
if (count >= 0)
|
||||
trigger = TriggerBuilder.Create()
|
||||
.WithIdentity("Modbus.Net.DataQuery.Trigger", "Modbus.Net.DataQuery.Group")
|
||||
.WithIdentity("Modbus.Net.DataQuery.Trigger."+ triggerKey, "Modbus.Net.DataQuery.Group")
|
||||
.StartNow()
|
||||
.WithSimpleSchedule(b => b.WithIntervalInSeconds(interval).WithRepeatCount(count))
|
||||
.Build();
|
||||
else
|
||||
trigger = TriggerBuilder.Create()
|
||||
.WithIdentity("Modbus.Net.DataQuery.Trigger", "Modbus.Net.DataQuery.Group")
|
||||
.WithIdentity("Modbus.Net.DataQuery.Trigger."+ triggerKey, "Modbus.Net.DataQuery.Group")
|
||||
.StartNow()
|
||||
.WithSimpleSchedule(b => b.WithIntervalInSeconds(interval).RepeatForever())
|
||||
.Build();
|
||||
@@ -59,6 +58,26 @@ namespace Modbus.Net.Job
|
||||
|
||||
return new MachineQueryJobScheduler(_scheduler, _trigger, jobKey);
|
||||
}
|
||||
|
||||
public async Task<MachineSetJobScheduler> To(string queryId, Dictionary<string, ReturnUnit> values, IMachineMethodData machine, MachineDataType machineDataType)
|
||||
{
|
||||
JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group");
|
||||
|
||||
IJobDetail job = JobBuilder.Create<MachineSetDataJob>()
|
||||
.WithIdentity(jobKey)
|
||||
.Build();
|
||||
|
||||
job.JobDataMap.Put("DataType", machineDataType);
|
||||
job.JobDataMap.Put("Machine", machine);
|
||||
job.JobDataMap.Put("Value", values);
|
||||
|
||||
await _scheduler.ScheduleJob(job, _trigger);
|
||||
|
||||
JobChainingJobListenerWithDataMap listener = new JobChainingJobListenerWithDataMap("Modbus.Net.DataQuery.Chain", false);
|
||||
_scheduler.ListenerManager.AddJobListener(listener, GroupMatcher<JobKey>.GroupEquals("Modbus.Net.DataQuery.Group"));
|
||||
|
||||
return new MachineSetJobScheduler(_scheduler, _trigger, listener, jobKey);
|
||||
}
|
||||
}
|
||||
|
||||
public class MachineQueryJobScheduler
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace Modbus.Net
|
||||
@@ -17,7 +17,7 @@ namespace Modbus.Net
|
||||
/// <param name="dataBits">数据位</param>
|
||||
/// <param name="slaveAddress">从站地址</param>
|
||||
protected ComProtocolLinker(int baudRate, Parity parity, StopBits stopBits, int dataBits, int slaveAddress)
|
||||
: this(ConfigurationManager.AppSettings["COM"], baudRate, parity, stopBits, dataBits, slaveAddress)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["COM"], baudRate, parity, stopBits, dataBits, slaveAddress)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Modbus.Net
|
||||
int slaveAddress, bool isFullDuplex = false)
|
||||
: this(
|
||||
com, baudRate, parity, stopBits, dataBits,
|
||||
int.Parse(ConfigurationManager.AppSettings["ComConnectionTimeout"] ?? "-1"), slaveAddress, isFullDuplex)
|
||||
int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ComConnectionTimeout"] ?? "-1"), slaveAddress, isFullDuplex)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
|
||||
namespace Modbus.Net
|
||||
{
|
||||
@@ -11,7 +12,7 @@ namespace Modbus.Net
|
||||
/// 构造器
|
||||
/// </summary>
|
||||
protected TcpProtocolLinker(int port)
|
||||
: this(ConfigurationManager.AppSettings["IP"], port)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], port)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ namespace Modbus.Net
|
||||
/// <param name="port">端口</param>
|
||||
/// <param name="isFullDuplex">是否为全双工</param>
|
||||
protected TcpProtocolLinker(string ip, int port, bool isFullDuplex = true)
|
||||
: this(ip, port, int.Parse(ConfigurationManager.AppSettings["IPConnectionTimeout"] ?? "-1"), isFullDuplex)
|
||||
: this(ip, port, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IPConnectionTimeout"] ?? "-1"), isFullDuplex)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
|
||||
namespace Modbus.Net
|
||||
{
|
||||
@@ -11,7 +12,7 @@ namespace Modbus.Net
|
||||
/// 构造器
|
||||
/// </summary>
|
||||
protected UdpProtocolLinker(int port)
|
||||
: this(ConfigurationManager.AppSettings["IP"], port)
|
||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], port)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ namespace Modbus.Net
|
||||
/// <param name="port">端口</param>
|
||||
/// <param name="isFullDuplex">是否为全双工</param>
|
||||
protected UdpProtocolLinker(string ip, int port, bool isFullDuplex = true)
|
||||
: this(ip, port, int.Parse(ConfigurationManager.AppSettings["IPConnectionTimeout"] ?? "-1"), isFullDuplex)
|
||||
: this(ip, port, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IPConnectionTimeout"] ?? "-1"), isFullDuplex)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Modbus.Net.Interface;
|
||||
using Serilog;
|
||||
|
||||
namespace Modbus.Net
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
|
||||
<PackageReference Include="Quartz" Version="3.6.0" />
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
||||
<PackageReference Include="System.IO.Ports" Version="7.0.0" />
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
using Modbus.Net.Interface;
|
||||
|
||||
/// <summary>
|
||||
/// 端格式
|
||||
|
||||
11
Modbus.Net/Modbus.Net/appsettings.json
Normal file
11
Modbus.Net/Modbus.Net/appsettings.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"Config": {
|
||||
"COM": "COM1",
|
||||
"IP": "192.168.1.1",
|
||||
"ComConnectionTimeout": "3000",
|
||||
"IPConnectionTimeout": "5000",
|
||||
"ModbusPort": "502",
|
||||
"SiemensPort": "102",
|
||||
"FetchSleepTime": "100"
|
||||
}
|
||||
}
|
||||
36
Samples/Modbus.Net.Modbus.Test/DatabaseWrite.cs
Normal file
36
Samples/Modbus.Net.Modbus.Test/DatabaseWrite.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
|
||||
namespace Modbus.Net.Modbus.Test
|
||||
{
|
||||
public class DatabaseWriteContext : DbContext
|
||||
{
|
||||
static readonly string connectionString = new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetConnectionString("DatabaseWriteConnectionString")!;
|
||||
|
||||
public DbSet<DatabaseWriteEntity> DatabaseWrites { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
|
||||
}
|
||||
}
|
||||
|
||||
public class DatabaseWriteEntity
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public double? Value1 { get; set; }
|
||||
public double? Value2 { get; set; }
|
||||
public double? Value3 { get; set; }
|
||||
public double? Value4 { get; set; }
|
||||
public double? Value5 { get; set; }
|
||||
public double? Value6 { get; set; }
|
||||
public double? Value7 { get; set; }
|
||||
public double? Value8 { get; set; }
|
||||
public double? Value9 { get; set; }
|
||||
public double? Value10 { get; set; }
|
||||
public DateTime UpdateTime { get; set; }
|
||||
}
|
||||
}
|
||||
71
Samples/Modbus.Net.Modbus.Test/Migrations/20230212103438_InitialCreate.Designer.cs
generated
Normal file
71
Samples/Modbus.Net.Modbus.Test/Migrations/20230212103438_InitialCreate.Designer.cs
generated
Normal file
@@ -0,0 +1,71 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Modbus.Net.Modbus.Test;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Modbus.Net.Modbus.Test.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseWriteContext))]
|
||||
[Migration("20230212103438_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.2")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("Modbus.Net.Modbus.Test.DatabaseWriteEntity", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("UpdateTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<double?>("Value1")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value10")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value2")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value3")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value4")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value5")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value6")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value7")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value8")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value9")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("DatabaseWrites");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Modbus.Net.Modbus.Test.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterDatabase()
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "DatabaseWrites",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Value1 = table.Column<double>(type: "double", nullable: true),
|
||||
Value2 = table.Column<double>(type: "double", nullable: true),
|
||||
Value3 = table.Column<double>(type: "double", nullable: true),
|
||||
Value4 = table.Column<double>(type: "double", nullable: true),
|
||||
Value5 = table.Column<double>(type: "double", nullable: true),
|
||||
Value6 = table.Column<double>(type: "double", nullable: true),
|
||||
Value7 = table.Column<double>(type: "double", nullable: true),
|
||||
Value8 = table.Column<double>(type: "double", nullable: true),
|
||||
Value9 = table.Column<double>(type: "double", nullable: true),
|
||||
Value10 = table.Column<double>(type: "double", nullable: true),
|
||||
UpdateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_DatabaseWrites", x => x.Id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "DatabaseWrites");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Modbus.Net.Modbus.Test;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Modbus.Net.Modbus.Test.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseWriteContext))]
|
||||
partial class DatabaseWriteContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.2")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("Modbus.Net.Modbus.Test.DatabaseWriteEntity", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("UpdateTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<double?>("Value1")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value10")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value2")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value3")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value4")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value5")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value6")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value7")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value8")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.Property<double?>("Value9")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("DatabaseWrites");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,24 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net.Modbus\Modbus.Net.Modbus.csproj" />
|
||||
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net\Modbus.Net.csproj" />
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
using Modbus.Net;
|
||||
using Modbus.Net.Modbus;
|
||||
using Modbus.Net.Interface;
|
||||
using Modbus.Net.Job;
|
||||
using Modbus.Net.Modbus.Test;
|
||||
|
||||
List<AddressUnit> _addresses = new List<AddressUnit>
|
||||
{
|
||||
@@ -20,7 +19,7 @@ List<AddressUnit> _addresses = new List<AddressUnit>
|
||||
|
||||
IMachine<string> machine = new ModbusMachine<string, string>("ModbusMachine1", ModbusType.Tcp, "192.168.0.172:502", _addresses, true, 1, 2, Endian.BigEndianLsb);
|
||||
|
||||
await MachineJobSchedulerCreator.CreateScheduler(-1, 5).Result.From(machine.Id, machine, MachineDataType.Name).Result.Query("ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Run();
|
||||
await MachineJobSchedulerCreator.CreateScheduler("Trigger1", -1, 5).Result.From(machine.Id, machine, MachineDataType.Name).Result.Query("ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Run();
|
||||
|
||||
Console.ReadLine();
|
||||
|
||||
@@ -29,6 +28,29 @@ Dictionary<string, ReturnUnit> QueryConsole(Dictionary<string, ReturnUnit> value
|
||||
foreach (var value in values)
|
||||
{
|
||||
Console.WriteLine(value.Key + " " + value.Value.DeviceValue);
|
||||
}
|
||||
|
||||
using (var context = new DatabaseWriteContext())
|
||||
{
|
||||
context.DatabaseWrites.Add(new DatabaseWriteEntity
|
||||
{
|
||||
Value1 = values["Test1"].DeviceValue,
|
||||
Value2 = values["Test2"].DeviceValue,
|
||||
Value3 = values["Test3"].DeviceValue,
|
||||
Value4 = values["Test4"].DeviceValue,
|
||||
Value5 = values["Test5"].DeviceValue,
|
||||
Value6 = values["Test6"].DeviceValue,
|
||||
Value7 = values["Test7"].DeviceValue,
|
||||
Value8 = values["Test8"].DeviceValue,
|
||||
Value9 = values["Test9"].DeviceValue,
|
||||
Value10 = values["Test10"].DeviceValue,
|
||||
UpdateTime = DateTime.Now,
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
foreach (var value in values)
|
||||
{
|
||||
value.Value.DeviceValue = new Random().Next(65536) - 32768;
|
||||
}
|
||||
|
||||
|
||||
8
Samples/Modbus.Net.Modbus.Test/appsettings.json
Normal file
8
Samples/Modbus.Net.Modbus.Test/appsettings.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DatabaseWriteConnectionString": "Server=localhost; User ID=root; Password=123456; Database=modbusnettest;"
|
||||
},
|
||||
"Config": {
|
||||
"FetchSleepTime": "100"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user