Add more params to appsettings.json
This commit is contained in:
@@ -9,19 +9,13 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusAsciiInTcpProtocol : ModbusProtocol
|
public class ModbusAsciiInTcpProtocol : ModbusProtocol
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="slaveAddress">从站号</param>
|
/// <param name="slaveAddress">从站号</param>
|
||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
public ModbusAsciiInTcpProtocol(byte slaveAddress, byte masterAddress)
|
public ModbusAsciiInTcpProtocol(byte slaveAddress, byte masterAddress)
|
||||||
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
: this(ConfigurationReader.GetValueDirect("TCP:Modbus", "IP"), slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,18 +10,12 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusAsciiInTcpProtocolLinker : TcpProtocolLinker
|
public class ModbusAsciiInTcpProtocolLinker : TcpProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ip">IP地址</param>
|
/// <param name="ip">IP地址</param>
|
||||||
public ModbusAsciiInTcpProtocolLinker(string ip)
|
public ModbusAsciiInTcpProtocolLinker(string ip)
|
||||||
: base(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"), false)
|
: base(ip, int.Parse(ConfigurationReader.GetValueDirect("TCP:" + ip, "ModbusPort") ?? ConfigurationReader.GetValueDirect("TCP:Modbus", "ModbusPort")))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +27,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusAsciiInTcpProtocolLinker(string ip, int port)
|
public ModbusAsciiInTcpProtocolLinker(string ip, int port)
|
||||||
: base(ip, port)
|
: base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "100")));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "FetchSleepTime")), waitingListMaxCount: ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "WaitingListCount") != null ? int.Parse(ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "WaitingListCount")) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusAsciiInUdpProtocol : ModbusProtocol
|
public class ModbusAsciiInUdpProtocol : ModbusProtocol
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="slaveAddress">从站号</param>
|
/// <param name="slaveAddress">从站号</param>
|
||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
public ModbusAsciiInUdpProtocol(byte slaveAddress, byte masterAddress)
|
public ModbusAsciiInUdpProtocol(byte slaveAddress, byte masterAddress)
|
||||||
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
: this(ConfigurationReader.GetValueDirect("UDP:Modbus","IP"), slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,18 +10,12 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusAsciiInUdpProtocolLinker : UdpProtocolLinker
|
public class ModbusAsciiInUdpProtocolLinker : UdpProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ip">IP地址</param>
|
/// <param name="ip">IP地址</param>
|
||||||
public ModbusAsciiInUdpProtocolLinker(string ip)
|
public ModbusAsciiInUdpProtocolLinker(string ip)
|
||||||
: base(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"), false)
|
: base(ip, int.Parse(ConfigurationReader.GetValueDirect("UDP:" + ip, "ModbusPort") ?? ConfigurationReader.GetValueDirect("UDP:Modbus", "ModbusPort")))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +27,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusAsciiInUdpProtocolLinker(string ip, int port)
|
public ModbusAsciiInUdpProtocolLinker(string ip, int port)
|
||||||
: base(ip, port)
|
: base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0")));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationReader.GetValue("UDP:" + ip + ":" + port, "FetchSleepTime")), waitingListMaxCount: ConfigurationReader.GetValue("UDP:" + ip + ":" + port, "WaitingListCount") != null ? int.Parse(ConfigurationReader.GetValue("UDP:" + ip + ":" + port, "WaitingListCount")) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusAsciiProtocol : ModbusProtocol
|
public class ModbusAsciiProtocol : ModbusProtocol
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="slaveAddress">从站号</param>
|
/// <param name="slaveAddress">从站号</param>
|
||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
public ModbusAsciiProtocol(byte slaveAddress, byte masterAddress)
|
public ModbusAsciiProtocol(byte slaveAddress, byte masterAddress)
|
||||||
: this(configuration.GetSection("Modbus.Net")["COM"], slaveAddress, masterAddress)
|
: this(ConfigurationReader.GetValueDirect("COM:Modbus", "COM"), slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,6 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusAsciiProtocolLinker : ComProtocolLinker
|
public class ModbusAsciiProtocolLinker : ComProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -26,7 +20,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusAsciiProtocolLinker(string com, int slaveAddress)
|
public ModbusAsciiProtocolLinker(string com, int slaveAddress)
|
||||||
: base(com, slaveAddress)
|
: base(com, 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(configuration.GetSection("Modbus.Net")["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(ConfigurationReader.GetValue("COM:" + com + ":" + slaveAddress, "FetchSleepTime")), waitingListMaxCount: ConfigurationReader.GetValue("COM:" + com + ":" + slaveAddress, "WaitingListCount") != null ? int.Parse(ConfigurationReader.GetValue("COM:" + com + ":" + slaveAddress, "WaitingListCount")) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusRtuInTcpProtocol : ModbusProtocol
|
public class ModbusRtuInTcpProtocol : ModbusProtocol
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="slaveAddress">从站号</param>
|
/// <param name="slaveAddress">从站号</param>
|
||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
public ModbusRtuInTcpProtocol(byte slaveAddress, byte masterAddress)
|
public ModbusRtuInTcpProtocol(byte slaveAddress, byte masterAddress)
|
||||||
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
: this(ConfigurationReader.GetValueDirect("TCP:Modbus", "IP"), slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,18 +9,12 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusRtuInTcpProtocolLinker : TcpProtocolLinker
|
public class ModbusRtuInTcpProtocolLinker : TcpProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ip">IP地址</param>
|
/// <param name="ip">IP地址</param>
|
||||||
public ModbusRtuInTcpProtocolLinker(string ip)
|
public ModbusRtuInTcpProtocolLinker(string ip)
|
||||||
: base(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"), false)
|
: base(ip, int.Parse(ConfigurationReader.GetValueDirect("TCP:" + ip, "ModbusPort") ?? ConfigurationReader.GetValueDirect("TCP:Modbus", "ModbusPort")))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +26,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusRtuInTcpProtocolLinker(string ip, int port)
|
public ModbusRtuInTcpProtocolLinker(string ip, int port)
|
||||||
: base(ip, port)
|
: base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0")));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "FetchSleepTime")), waitingListMaxCount: ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "WaitingListCount") != null ? int.Parse(ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "WaitingListCount")) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusRtuInUdpProtocol : ModbusProtocol
|
public class ModbusRtuInUdpProtocol : ModbusProtocol
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="slaveAddress">从站号</param>
|
/// <param name="slaveAddress">从站号</param>
|
||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
public ModbusRtuInUdpProtocol(byte slaveAddress, byte masterAddress)
|
public ModbusRtuInUdpProtocol(byte slaveAddress, byte masterAddress)
|
||||||
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
: this(ConfigurationReader.GetValueDirect("UDP:Modbus", "IP"), slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,18 +9,12 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusRtuInUdpProtocolLinker : UdpProtocolLinker
|
public class ModbusRtuInUdpProtocolLinker : UdpProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ip">IP地址</param>
|
/// <param name="ip">IP地址</param>
|
||||||
public ModbusRtuInUdpProtocolLinker(string ip)
|
public ModbusRtuInUdpProtocolLinker(string ip)
|
||||||
: base(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"), false)
|
: base(ip, int.Parse(ConfigurationReader.GetValueDirect("UDP:" + ip, "ModbusPort") ?? ConfigurationReader.GetValueDirect("UDP:Modbus", "ModbusPort")))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +26,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusRtuInUdpProtocolLinker(string ip, int port)
|
public ModbusRtuInUdpProtocolLinker(string ip, int port)
|
||||||
: base(ip, port)
|
: base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0")));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationReader.GetValue("UDP:" + ip + ":" + port, "FetchSleepTime")), waitingListMaxCount: ConfigurationReader.GetValue("UDP:" + ip + ":" + port, "WaitingListCount") != null ? int.Parse(ConfigurationReader.GetValue("UDP:" + ip + ":" + port, "WaitingListCount")) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusRtuProtocol : ModbusProtocol
|
public class ModbusRtuProtocol : ModbusProtocol
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="slaveAddress">从站号</param>
|
/// <param name="slaveAddress">从站号</param>
|
||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
public ModbusRtuProtocol(byte slaveAddress, byte masterAddress)
|
public ModbusRtuProtocol(byte slaveAddress, byte masterAddress)
|
||||||
: this(configuration.GetSection("Modbus.Net")["COM"], slaveAddress, masterAddress)
|
: this(ConfigurationReader.GetValueDirect("COM:Modbus", "COM"), slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,6 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusRtuProtocolLinker : ComProtocolLinker
|
public class ModbusRtuProtocolLinker : ComProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -25,7 +19,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusRtuProtocolLinker(string com, int slaveAddress)
|
public ModbusRtuProtocolLinker(string com, int slaveAddress)
|
||||||
: base(com, slaveAddress)
|
: base(com, slaveAddress)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int, int)>[] { new List<(int, int)> { (0, 0) }, new List<(int, int)> { (1, 1) } }, int.Parse(configuration.GetSection("Modbus.Net")["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(ConfigurationReader.GetValue("COM:" + com + ":" + slaveAddress, "FetchSleepTime")), waitingListMaxCount: ConfigurationReader.GetValue("COM:" + com + ":" + slaveAddress, "WaitingListCount") != null ? int.Parse(ConfigurationReader.GetValue("COM:" + com + ":" + slaveAddress, "WaitingListCount")) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusTcpProtocol : ModbusProtocol
|
public class ModbusTcpProtocol : ModbusProtocol
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="slaveAddress">从站号</param>
|
/// <param name="slaveAddress">从站号</param>
|
||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
public ModbusTcpProtocol(byte slaveAddress, byte masterAddress)
|
public ModbusTcpProtocol(byte slaveAddress, byte masterAddress)
|
||||||
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
: this(ConfigurationReader.GetValueDirect("TCP:Modbus", "IP"), slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,18 +10,12 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusTcpProtocolLinker : TcpProtocolLinker
|
public class ModbusTcpProtocolLinker : TcpProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ip">IP地址</param>
|
/// <param name="ip">IP地址</param>
|
||||||
public ModbusTcpProtocolLinker(string ip)
|
public ModbusTcpProtocolLinker(string ip)
|
||||||
: this(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"))
|
: this(ip, int.Parse(ConfigurationReader.GetValueDirect("TCP:" + ip, "ModbusPort") ?? ConfigurationReader.GetValueDirect("TCP:Modbus", "ModbusPort")))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +26,7 @@ namespace Modbus.Net.Modbus
|
|||||||
/// <param name="port">端口</param>
|
/// <param name="port">端口</param>
|
||||||
public ModbusTcpProtocolLinker(string ip, int port) : base(ip, port)
|
public ModbusTcpProtocolLinker(string ip, int port) : base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int> { 4, 5 }, 6)));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "FetchSleepTime")), waitingListMaxCount: ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "WaitingListCount") != null ? int.Parse(ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "WaitingListCount")) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusUdpProtocol : ModbusProtocol
|
public class ModbusUdpProtocol : ModbusProtocol
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="slaveAddress">从站号</param>
|
/// <param name="slaveAddress">从站号</param>
|
||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
public ModbusUdpProtocol(byte slaveAddress, byte masterAddress)
|
public ModbusUdpProtocol(byte slaveAddress, byte masterAddress)
|
||||||
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
: this(ConfigurationReader.GetValueDirect("UDP:Modbus", "IP"), slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,18 +10,12 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusUdpProtocolLinker : UdpProtocolLinker
|
public class ModbusUdpProtocolLinker : UdpProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ip">IP地址</param>
|
/// <param name="ip">IP地址</param>
|
||||||
public ModbusUdpProtocolLinker(string ip)
|
public ModbusUdpProtocolLinker(string ip)
|
||||||
: this(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"))
|
: this(ip, int.Parse(ConfigurationReader.GetValue("UDP:" + ip, "ModbusPort")))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +26,7 @@ namespace Modbus.Net.Modbus
|
|||||||
/// <param name="port">端口</param>
|
/// <param name="port">端口</param>
|
||||||
public ModbusUdpProtocolLinker(string ip, int port) : base(ip, port)
|
public ModbusUdpProtocolLinker(string ip, int port) : base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int> { 4, 5 }, 6)));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationReader.GetValue("UDP:" + ip + ":" + port, "FetchSleepTime")), waitingListMaxCount: ConfigurationReader.GetValue("UDP:" + ip + ":" + port, "WaitingListCount") != null ? int.Parse(ConfigurationReader.GetValue("UDP:" + ip + ":" + port, "WaitingListCount")) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -11,12 +11,6 @@ namespace Modbus.Net.Siemens
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SiemensPpiProtocol : SiemensProtocol
|
public class SiemensPpiProtocol : SiemensProtocol
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
private readonly string _com;
|
private readonly string _com;
|
||||||
private readonly AsyncLock _lock = new AsyncLock();
|
private readonly AsyncLock _lock = new AsyncLock();
|
||||||
|
|
||||||
@@ -26,7 +20,7 @@ namespace Modbus.Net.Siemens
|
|||||||
/// <param name="slaveAddress">从站号</param>
|
/// <param name="slaveAddress">从站号</param>
|
||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
public SiemensPpiProtocol(byte slaveAddress, byte masterAddress)
|
public SiemensPpiProtocol(byte slaveAddress, byte masterAddress)
|
||||||
: this(configuration.GetSection("Modbus.Net")["COM"], slaveAddress, masterAddress)
|
: this(ConfigurationReader.GetValueDirect("COM:Siemens", "COM"), slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,6 @@ namespace Modbus.Net.Siemens
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SiemensPpiProtocolLinker : ComProtocolLinker
|
public class SiemensPpiProtocolLinker : ComProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -27,7 +21,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public SiemensPpiProtocolLinker(string com, int slaveAddress)
|
public SiemensPpiProtocolLinker(string com, int slaveAddress)
|
||||||
: base(com, slaveAddress)
|
: base(com, slaveAddress)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0"), true, null, 100));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationReader.GetValue("COM:" + com + ":" + slaveAddress, "FetchSleepTime")), waitingListMaxCount: ConfigurationReader.GetValue("COM:" + com + ":" + slaveAddress, "WaitingListCount") != null ? int.Parse(ConfigurationReader.GetValue("COM:" + com + ":" + slaveAddress, "WaitingListCount")) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -22,12 +22,6 @@ namespace Modbus.Net.Siemens
|
|||||||
private int _connectTryCount;
|
private int _connectTryCount;
|
||||||
private readonly AsyncLock _lock = new AsyncLock();
|
private readonly AsyncLock _lock = new AsyncLock();
|
||||||
|
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -39,7 +33,7 @@ namespace Modbus.Net.Siemens
|
|||||||
/// <param name="maxPdu"></param>
|
/// <param name="maxPdu"></param>
|
||||||
public SiemensTcpProtocol(byte tdpuSize, ushort tsapSrc, ushort tsapDst, ushort maxCalling, ushort maxCalled,
|
public SiemensTcpProtocol(byte tdpuSize, ushort tsapSrc, ushort tsapDst, ushort maxCalling, ushort maxCalled,
|
||||||
ushort maxPdu)
|
ushort maxPdu)
|
||||||
: this(tdpuSize, tsapSrc, tsapDst, maxCalling, maxCalled, maxPdu, configuration.GetSection("Modbus.Net")["IP"])
|
: this(tdpuSize, tsapSrc, tsapDst, maxCalling, maxCalled, maxPdu, ConfigurationReader.GetValueDirect("TCP:Siemens", "IP"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +51,7 @@ namespace Modbus.Net.Siemens
|
|||||||
ushort maxPdu, string ip)
|
ushort maxPdu, string ip)
|
||||||
: this(
|
: this(
|
||||||
tdpuSize, tsapSrc, tsapDst, maxCalling, maxCalled, maxPdu, ip,
|
tdpuSize, tsapSrc, tsapDst, maxCalling, maxCalled, maxPdu, ip,
|
||||||
int.Parse(configuration.GetSection("Modbus.Net")["SiemensPort"] ?? "102"))
|
int.Parse(ConfigurationReader.GetValueDirect("TCP:Siemens", "SiemensPort")))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,18 +10,12 @@ namespace Modbus.Net.Siemens
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SiemensTcpProtocolLinker : TcpProtocolLinker
|
public class SiemensTcpProtocolLinker : TcpProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ip">IP地址</param>
|
/// <param name="ip">IP地址</param>
|
||||||
public SiemensTcpProtocolLinker(string ip)
|
public SiemensTcpProtocolLinker(string ip)
|
||||||
: this(ip, int.Parse(configuration.GetSection("Modbus.Net")["SiemensPort"] ?? "102"))
|
: this(ip, int.Parse(ConfigurationReader.GetValueDirect("TCP:" + ip, "Siemens") ?? ConfigurationReader.GetValueDirect("TCP:Siemens", "SiemensPort")))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +27,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public SiemensTcpProtocolLinker(string ip, int port)
|
public SiemensTcpProtocolLinker(string ip, int port)
|
||||||
: base(ip, port)
|
: base(ip, port)
|
||||||
{
|
{
|
||||||
((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), 100));
|
((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), waitingListMaxCount: ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "WaitingListCount") != null ? int.Parse(ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "WaitingListCount")) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -24,17 +24,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MachineJob", "..\Samples\Ma
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.Modbus.NA200H", "Modbus.Net.Modbus.NA200H\Modbus.Net.Modbus.NA200H.csproj", "{D4AF0E1E-676E-43B6-BAA3-BFC329D68C80}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.Modbus.NA200H", "Modbus.Net.Modbus.NA200H\Modbus.Net.Modbus.NA200H.csproj", "{D4AF0E1E-676E-43B6-BAA3-BFC329D68C80}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.PersistedTests", "..\Tests\Modbus.Net.PersistedTests\Modbus.Net.PersistedTests.csproj", "{4B946C56-D09F-4EEB-BE88-4A2C97815A77}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnyType", "..\Samples\AnyType\AnyType.csproj", "{1857DA63-3335-428F-84D8-1FA4F8178643}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnyType", "..\Samples\AnyType\AnyType.csproj", "{1857DA63-3335-428F-84D8-1FA4F8178643}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.OPC", "Modbus.Net.OPC\Modbus.Net.OPC.csproj", "{C854A379-C5EA-4CAC-9C5F-7291372D1D3F}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.OPC", "Modbus.Net.OPC\Modbus.Net.OPC.csproj", "{C854A379-C5EA-4CAC-9C5F-7291372D1D3F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "h-opc", "..\Libraries\h-opc\h-opc.csproj", "{347D0027-45F6-48C9-A917-1B1DF6C66DC5}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "h-opc", "..\Libraries\h-opc\h-opc.csproj", "{347D0027-45F6-48C9-A917-1B1DF6C66DC5}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrossLamp", "..\Samples\CrossLamp\CrossLamp.csproj", "{AA3A42D2-0502-41D3-929A-BAB729DF07D6}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CrossLamp", "..\Samples\CrossLamp\CrossLamp.csproj", "{AA3A42D2-0502-41D3-929A-BAB729DF07D6}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TripleAdd", "..\Samples\TripleAdd\TripleAdd.csproj", "{414956B8-DBD4-414C-ABD3-565580739646}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TripleAdd", "..\Samples\TripleAdd\TripleAdd.csproj", "{414956B8-DBD4-414C-ABD3-565580739646}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -66,10 +64,6 @@ Global
|
|||||||
{D4AF0E1E-676E-43B6-BAA3-BFC329D68C80}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
|
||||||
{D4AF0E1E-676E-43B6-BAA3-BFC329D68C80}.Release|Any CPU.Build.0 = Release|Any CPU
|
{D4AF0E1E-676E-43B6-BAA3-BFC329D68C80}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{4B946C56-D09F-4EEB-BE88-4A2C97815A77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{4B946C56-D09F-4EEB-BE88-4A2C97815A77}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{4B946C56-D09F-4EEB-BE88-4A2C97815A77}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{4B946C56-D09F-4EEB-BE88-4A2C97815A77}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{1857DA63-3335-428F-84D8-1FA4F8178643}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{1857DA63-3335-428F-84D8-1FA4F8178643}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{1857DA63-3335-428F-84D8-1FA4F8178643}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{1857DA63-3335-428F-84D8-1FA4F8178643}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{1857DA63-3335-428F-84D8-1FA4F8178643}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{1857DA63-3335-428F-84D8-1FA4F8178643}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
@@ -97,7 +91,6 @@ Global
|
|||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{3BB01E98-3D45-454A-A1BD-49D7B2C83B74} = {D8DD32FC-CF39-4A1A-8FBF-9E82C5278C34}
|
{3BB01E98-3D45-454A-A1BD-49D7B2C83B74} = {D8DD32FC-CF39-4A1A-8FBF-9E82C5278C34}
|
||||||
{22A35CA8-CDCF-416D-BA84-08C933B4A3DE} = {3597B5C5-45B9-4ECB-92A3-D0FFBE47920A}
|
{22A35CA8-CDCF-416D-BA84-08C933B4A3DE} = {3597B5C5-45B9-4ECB-92A3-D0FFBE47920A}
|
||||||
{4B946C56-D09F-4EEB-BE88-4A2C97815A77} = {D8DD32FC-CF39-4A1A-8FBF-9E82C5278C34}
|
|
||||||
{1857DA63-3335-428F-84D8-1FA4F8178643} = {3597B5C5-45B9-4ECB-92A3-D0FFBE47920A}
|
{1857DA63-3335-428F-84D8-1FA4F8178643} = {3597B5C5-45B9-4ECB-92A3-D0FFBE47920A}
|
||||||
{AA3A42D2-0502-41D3-929A-BAB729DF07D6} = {3597B5C5-45B9-4ECB-92A3-D0FFBE47920A}
|
{AA3A42D2-0502-41D3-929A-BAB729DF07D6} = {3597B5C5-45B9-4ECB-92A3-D0FFBE47920A}
|
||||||
{414956B8-DBD4-414C-ABD3-565580739646} = {3597B5C5-45B9-4ECB-92A3-D0FFBE47920A}
|
{414956B8-DBD4-414C-ABD3-565580739646} = {3597B5C5-45B9-4ECB-92A3-D0FFBE47920A}
|
||||||
|
|||||||
68
Modbus.Net/Modbus.Net/Configuration/ConfigurationReader.cs
Normal file
68
Modbus.Net/Modbus.Net/Configuration/ConfigurationReader.cs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Modbus.Net
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Modbus.Net专用配置读取类
|
||||||
|
/// </summary>
|
||||||
|
public static class ConfigurationReader
|
||||||
|
{
|
||||||
|
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.default.json")
|
||||||
|
.AddJsonFile("appsettings.json")
|
||||||
|
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
/// <summary>
|
||||||
|
/// 根据路径,依次查找路径与父路径上是否有该元素
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">路径,冒号隔开</param>
|
||||||
|
/// <param name="key">元素的键</param>
|
||||||
|
/// <returns>元素的值</returns>
|
||||||
|
public static string? GetValue(string path, string key)
|
||||||
|
{
|
||||||
|
var split = path.Split(":");
|
||||||
|
string? ans = null;
|
||||||
|
while (split.Length > 0)
|
||||||
|
{
|
||||||
|
var root = configuration.GetSection("Modbus.Net");
|
||||||
|
foreach (var entry in split)
|
||||||
|
{
|
||||||
|
root = root?.GetSection(entry);
|
||||||
|
}
|
||||||
|
ans = ans ?? root?[key];
|
||||||
|
split = split.Take(split.Length - 1).ToArray();
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据路径,直接查找路径上是否有该元素
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">路径,冒号隔开</param>
|
||||||
|
/// <param name="key">元素的键</param>
|
||||||
|
/// <returns>元素的值</returns>
|
||||||
|
public static string? GetValueDirect(string path, string key)
|
||||||
|
{
|
||||||
|
var root = configuration.GetSection("Modbus.Net");
|
||||||
|
var firstColon = path.IndexOf(":");
|
||||||
|
while (firstColon != -1)
|
||||||
|
{
|
||||||
|
root = root?.GetSection(path.Substring(0,firstColon));
|
||||||
|
path = path.Substring(firstColon + 1);
|
||||||
|
firstColon = path.IndexOf(":");
|
||||||
|
}
|
||||||
|
root = root?.GetSection(path);
|
||||||
|
return root?[key];
|
||||||
|
}
|
||||||
|
#nullable disable
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,7 @@ namespace Modbus.Net
|
|||||||
protected BaseConnector(int timeoutTime = 10000, bool isFullDuplex = true)
|
protected BaseConnector(int timeoutTime = 10000, bool isFullDuplex = true)
|
||||||
{
|
{
|
||||||
IsFullDuplex = isFullDuplex;
|
IsFullDuplex = isFullDuplex;
|
||||||
|
if (timeoutTime < -1) timeoutTime = -1;
|
||||||
TimeoutTime = timeoutTime;
|
TimeoutTime = timeoutTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,6 @@ namespace Modbus.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class FifoController : BaseController
|
public class FifoController : BaseController
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
private static readonly ILogger<FifoController> logger = LogProvider.CreateLogger<FifoController>();
|
private static readonly ILogger<FifoController> logger = LogProvider.CreateLogger<FifoController>();
|
||||||
|
|
||||||
private MessageWaitingDef _currentSendingPos;
|
private MessageWaitingDef _currentSendingPos;
|
||||||
@@ -41,10 +35,10 @@ namespace Modbus.Net
|
|||||||
/// <param name="activateSema">是否开启信号量</param>
|
/// <param name="activateSema">是否开启信号量</param>
|
||||||
/// <param name="duplicateFunc">包切分函数</param>
|
/// <param name="duplicateFunc">包切分函数</param>
|
||||||
/// <param name="waitingListMaxCount">包等待队列长度</param>
|
/// <param name="waitingListMaxCount">包等待队列长度</param>
|
||||||
public FifoController(int acquireTime, bool activateSema = true, Func<byte[], ICollection<byte[]>> duplicateFunc = null, int waitingListMaxCount = 100)
|
public FifoController(int acquireTime, bool activateSema = true, Func<byte[], ICollection<byte[]>> duplicateFunc = null, int? waitingListMaxCount = null)
|
||||||
: base(duplicateFunc)
|
: base(duplicateFunc)
|
||||||
{
|
{
|
||||||
_waitingListMaxCount = int.Parse(configuration.GetSection("Modbus.Net")["WaitingListCount"] ?? waitingListMaxCount.ToString());
|
_waitingListMaxCount = int.Parse(waitingListMaxCount != null ? waitingListMaxCount.ToString() : null ?? ConfigurationReader.GetValueDirect("Controller","WaitingListCount"));
|
||||||
if (activateSema)
|
if (activateSema)
|
||||||
{
|
{
|
||||||
_taskCycleSema = new Semaphore(0, _waitingListMaxCount);
|
_taskCycleSema = new Semaphore(0, _waitingListMaxCount);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="duplicateFunc">包切分函数</param>
|
/// <param name="duplicateFunc">包切分函数</param>
|
||||||
/// <param name="waitingListMaxCount">包等待队列长度</param>
|
/// <param name="waitingListMaxCount">包等待队列长度</param>
|
||||||
public MatchController(ICollection<(int, int)>[] keyMatches, int acquireTime, bool activateSema = true,
|
public MatchController(ICollection<(int, int)>[] keyMatches, int acquireTime, bool activateSema = true,
|
||||||
Func<byte[], ICollection<byte[]>> duplicateFunc = null, int waitingListMaxCount = 100) : base(acquireTime, activateSema, duplicateFunc, waitingListMaxCount)
|
Func<byte[], ICollection<byte[]>> duplicateFunc = null, int? waitingListMaxCount = null) : base(acquireTime, activateSema, duplicateFunc, waitingListMaxCount)
|
||||||
{
|
{
|
||||||
KeyMatches = keyMatches;
|
KeyMatches = keyMatches;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Modbus.Net
|
|||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MatchDirectlySendController(ICollection<(int, int)>[] keyMatches,
|
public MatchDirectlySendController(ICollection<(int, int)>[] keyMatches,
|
||||||
Func<byte[], ICollection<byte[]>> duplicateFunc = null, int waitingListMaxCount = 100) : base(keyMatches,
|
Func<byte[], ICollection<byte[]>> duplicateFunc = null, int? waitingListMaxCount = null) : base(keyMatches,
|
||||||
0, false, duplicateFunc, waitingListMaxCount)
|
0, false, duplicateFunc, waitingListMaxCount)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Modbus.Net
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 多设备任务调度器
|
||||||
|
/// </summary>
|
||||||
|
public sealed class MultipleMachinesJobScheduler
|
||||||
|
{
|
||||||
|
private static int _machineCount = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建设备调度器
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="machines">设备的集合</param>
|
||||||
|
/// <param name="machineJobTemplate">设备的运行模板</param>
|
||||||
|
/// <param name="count">重复次数,负数为无限循环,0为执行一次</param>
|
||||||
|
/// <param name="intervalSecond">间隔秒数</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static ParallelLoopResult RunScheduler<TKey>(IEnumerable<IMachine<TKey>> machines, Func<IMachine<TKey>, MachineGetJobScheduler, Task> machineJobTemplate, int count = 0, int intervalSecond = 1) where TKey: IEquatable<TKey>
|
||||||
|
{
|
||||||
|
_machineCount = machines.Count();
|
||||||
|
return Parallel.ForEach(machines, (machine, state, index) =>
|
||||||
|
{
|
||||||
|
Task.Factory.StartNew(async () =>
|
||||||
|
{
|
||||||
|
Thread.Sleep((int)(intervalSecond * 1000.0 / _machineCount * index));
|
||||||
|
var getJobScheduler = await MachineJobSchedulerCreator.CreateScheduler("Trigger" + index, count, intervalSecond);
|
||||||
|
await machineJobTemplate(machine, getJobScheduler);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建设备调度器
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="machines">设备的集合</param>
|
||||||
|
/// <param name="machineJobTemplate">设备的运行模板</param>
|
||||||
|
/// <param name="count">重复次数,负数为无限循环,0为执行一次</param>
|
||||||
|
/// <param name="intervalSecond">间隔秒数</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static ParallelLoopResult RunScheduler(IEnumerable<IMachine<string>> machines, Func<IMachine<string>, MachineGetJobScheduler, Task> machineJobTemplate, int count = 0, int intervalSecond = 1)
|
||||||
|
{
|
||||||
|
return RunScheduler<string>(machines, machineJobTemplate, count, intervalSecond);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取消任务
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static ParallelLoopResult CancelJob()
|
||||||
|
{
|
||||||
|
return Parallel.For(0, _machineCount, async index =>
|
||||||
|
{
|
||||||
|
await MachineJobSchedulerCreator.CancelJob("Trigger" + index);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,49 +10,6 @@ namespace Modbus.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ComProtocolLinker : ProtocolLinker
|
public abstract class ComProtocolLinker : ProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造器
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="slaveAddress">从站地址</param>
|
|
||||||
protected ComProtocolLinker(int slaveAddress)
|
|
||||||
: this(configuration.GetSection("Modbus.Net")["COM"] ?? "COM1", slaveAddress)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造器
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="com">串口端口号</param>
|
|
||||||
/// <param name="slaveAddress">从站地址</param>
|
|
||||||
protected ComProtocolLinker(string com, int slaveAddress)
|
|
||||||
: this(com, slaveAddress, int.Parse(configuration.GetSection("Modbus.Net")["ComBaudRate"] ?? "9600"), Enum.Parse<Parity>(configuration.GetSection("Modbus.Net")["ComParity"] ?? "Parity.None"), Enum.Parse<StopBits>(configuration.GetSection("Modbus.Net")["ComStopBits"] ?? "StopBits.One"), int.Parse(configuration.GetSection("Modbus.Net")["ComDataBits"] ?? "8"))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造器
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="com">串口端口号</param>
|
|
||||||
/// <param name="baudRate">波特率</param>
|
|
||||||
/// <param name="parity">校验位</param>
|
|
||||||
/// <param name="stopBits">停止位</param>
|
|
||||||
/// <param name="dataBits">数据位</param>
|
|
||||||
/// <param name="slaveAddress">从站地址</param>
|
|
||||||
/// <param name="isFullDuplex">是否为全双工</param>
|
|
||||||
protected ComProtocolLinker(string com, int slaveAddress, int baudRate, Parity parity, StopBits stopBits, int dataBits,
|
|
||||||
bool isFullDuplex = false)
|
|
||||||
: this(
|
|
||||||
com, slaveAddress, baudRate, parity, stopBits, dataBits,
|
|
||||||
int.Parse(configuration.GetSection("Modbus.Net")["ComConnectionTimeout"] ?? "-1"), isFullDuplex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造器
|
/// 构造器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -64,19 +21,16 @@ namespace Modbus.Net
|
|||||||
/// <param name="connectionTimeout">超时时间</param>
|
/// <param name="connectionTimeout">超时时间</param>
|
||||||
/// <param name="slaveAddress">从站地址</param>
|
/// <param name="slaveAddress">从站地址</param>
|
||||||
/// <param name="isFullDuplex">是否为全双工</param>
|
/// <param name="isFullDuplex">是否为全双工</param>
|
||||||
protected ComProtocolLinker(string com, int slaveAddress, int baudRate, Parity parity, StopBits stopBits, int dataBits,
|
protected ComProtocolLinker(string com, int slaveAddress, int? baudRate = null, Parity? parity = null, StopBits? stopBits = null, int? dataBits = null,
|
||||||
int connectionTimeout, bool isFullDuplex = false)
|
int? connectionTimeout = null, bool? isFullDuplex = null)
|
||||||
{
|
{
|
||||||
if (connectionTimeout == -1)
|
baudRate = int.Parse(baudRate != null ? baudRate.ToString() : null ?? ConfigurationReader.GetValue("COM:"+com, "BaudRate"));
|
||||||
{
|
parity = Enum.Parse<Parity>(parity != null ? parity.ToString() : null ?? ConfigurationReader.GetValue("COM:" + com, "Parity"));
|
||||||
BaseConnector = new ComConnector(com + ":" + slaveAddress, baudRate, parity, stopBits, dataBits, isFullDuplex: isFullDuplex);
|
stopBits = Enum.Parse<StopBits>(stopBits != null ? stopBits.ToString() : null ?? ConfigurationReader.GetValue("COM:" + com, "StopBits"));
|
||||||
}
|
dataBits = int.Parse(dataBits != null ? dataBits.ToString() : null ?? ConfigurationReader.GetValue("COM:" + com, "DataBits"));
|
||||||
else
|
connectionTimeout = int.Parse(connectionTimeout != null ? connectionTimeout.ToString() : null ?? ConfigurationReader.GetValue("COM:" + com, "ConnectionTimeout"));
|
||||||
{
|
isFullDuplex = bool.Parse(isFullDuplex != null ? isFullDuplex.ToString() : null ?? ConfigurationReader.GetValue("COM:" + com, "FullDuplex"));
|
||||||
BaseConnector = new ComConnector(com + ":" + slaveAddress, baudRate, parity, stopBits, dataBits,
|
BaseConnector = new ComConnector(com + ":" + slaveAddress, baudRate.Value, parity.Value, stopBits.Value, dataBits.Value, connectionTimeout.Value, isFullDuplex.Value);
|
||||||
connectionTimeout, isFullDuplex: isFullDuplex);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net
|
namespace Modbus.Net
|
||||||
@@ -9,31 +10,6 @@ namespace Modbus.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class TcpProtocolLinker : ProtocolLinker
|
public abstract class TcpProtocolLinker : ProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造器
|
|
||||||
/// </summary>
|
|
||||||
protected TcpProtocolLinker(int port)
|
|
||||||
: this(configuration.GetSection("Modbus.Net")["IP"], port)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造器
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ip">Ip地址</param>
|
|
||||||
/// <param name="port">端口</param>
|
|
||||||
/// <param name="isFullDuplex">是否为全双工</param>
|
|
||||||
protected TcpProtocolLinker(string ip, int port, bool isFullDuplex = true)
|
|
||||||
: this(ip, port, int.Parse(configuration.GetSection("Modbus.Net")["IPConnectionTimeout"] ?? "-1"), isFullDuplex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造器
|
/// 构造器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -41,18 +17,12 @@ namespace Modbus.Net
|
|||||||
/// <param name="port">端口</param>
|
/// <param name="port">端口</param>
|
||||||
/// <param name="connectionTimeout">超时时间</param>
|
/// <param name="connectionTimeout">超时时间</param>
|
||||||
/// <param name="isFullDuplex">是否为全双工</param>
|
/// <param name="isFullDuplex">是否为全双工</param>
|
||||||
protected TcpProtocolLinker(string ip, int port, int connectionTimeout, bool isFullDuplex = true)
|
protected TcpProtocolLinker(string ip, int port, int? connectionTimeout = null, bool? isFullDuplex = null)
|
||||||
{
|
|
||||||
if (connectionTimeout == -1)
|
|
||||||
{
|
{
|
||||||
|
connectionTimeout = int.Parse(connectionTimeout != null ? connectionTimeout.ToString() : null ?? ConfigurationReader.GetValue("TCP:"+ip+":"+port, "ConnectionTimeout"));
|
||||||
|
isFullDuplex = bool.Parse(isFullDuplex != null ? isFullDuplex.ToString() : null ?? ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "FullDuplex"));
|
||||||
//初始化连接对象
|
//初始化连接对象
|
||||||
BaseConnector = new TcpConnector(ip, port, isFullDuplex: isFullDuplex);
|
BaseConnector = new TcpConnector(ip, port, connectionTimeout.Value, isFullDuplex.Value);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//初始化连接对象
|
|
||||||
BaseConnector = new TcpConnector(ip, port, connectionTimeout, isFullDuplex: isFullDuplex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,31 +9,6 @@ namespace Modbus.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class UdpProtocolLinker : ProtocolLinker
|
public abstract class UdpProtocolLinker : ProtocolLinker
|
||||||
{
|
{
|
||||||
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造器
|
|
||||||
/// </summary>
|
|
||||||
protected UdpProtocolLinker(int port)
|
|
||||||
: this(configuration.GetSection("Modbus.Net")["IP"], port)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造器
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ip">Ip地址</param>
|
|
||||||
/// <param name="port">端口</param>
|
|
||||||
/// <param name="isFullDuplex">是否为全双工</param>
|
|
||||||
protected UdpProtocolLinker(string ip, int port, bool isFullDuplex = true)
|
|
||||||
: this(ip, port, int.Parse(configuration.GetSection("Modbus.Net")["IPConnectionTimeout"] ?? "-1"), isFullDuplex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造器
|
/// 构造器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -41,18 +16,12 @@ namespace Modbus.Net
|
|||||||
/// <param name="port">端口</param>
|
/// <param name="port">端口</param>
|
||||||
/// <param name="connectionTimeout">超时时间</param>
|
/// <param name="connectionTimeout">超时时间</param>
|
||||||
/// <param name="isFullDuplex">是否为全双工</param>
|
/// <param name="isFullDuplex">是否为全双工</param>
|
||||||
protected UdpProtocolLinker(string ip, int port, int connectionTimeout, bool isFullDuplex = true)
|
protected UdpProtocolLinker(string ip, int port, int? connectionTimeout = null, bool? isFullDuplex = null)
|
||||||
{
|
|
||||||
if (connectionTimeout == -1)
|
|
||||||
{
|
{
|
||||||
|
connectionTimeout = int.Parse(connectionTimeout != null ? connectionTimeout.ToString() : null ?? ConfigurationReader.GetValue("UDP:" + ip + ":" + port, "ConnectionTimeout"));
|
||||||
|
isFullDuplex = bool.Parse(isFullDuplex != null ? isFullDuplex.ToString() : null ?? ConfigurationReader.GetValue("UDP:" + ip + ":" + port, "FullDuplex"));
|
||||||
//初始化连接对象
|
//初始化连接对象
|
||||||
BaseConnector = new UdpConnector(ip, port, isFullDuplex: isFullDuplex);
|
BaseConnector = new UdpConnector(ip, port, connectionTimeout.Value, isFullDuplex.Value);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//初始化连接对象
|
|
||||||
BaseConnector = new UdpConnector(ip, port, connectionTimeout, isFullDuplex: isFullDuplex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
44
Modbus.Net/Modbus.Net/appsettings.default.json
Normal file
44
Modbus.Net/Modbus.Net/appsettings.default.json
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"Modbus.Net": {
|
||||||
|
"TCP": {
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"ModbusPort": "502",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
},
|
||||||
|
"Siemens": {
|
||||||
|
"SiemensPort": "102",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"UDP": {
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"ModbusPort": "502",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"COM": {
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"BaudRate": "9600",
|
||||||
|
"Parity": "Parity.None",
|
||||||
|
"StopBits": "StopBits.One",
|
||||||
|
"DataBits": "8",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"COM": "COM1"
|
||||||
|
},
|
||||||
|
"Siemens": {
|
||||||
|
"COM": "COM2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Controller": {
|
||||||
|
"WaitingListCount": "100"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"Modbus.Net": {
|
|
||||||
"COM": "COM1",
|
|
||||||
"IP": "192.168.1.1",
|
|
||||||
"ComConnectionTimeout": "3000",
|
|
||||||
"ComBaudRate": "9600",
|
|
||||||
"ComParity": "Parity.None",
|
|
||||||
"ComStopBits": "StopBits.One",
|
|
||||||
"ComDataBits": "8",
|
|
||||||
"IPConnectionTimeout": "5000",
|
|
||||||
"ModbusPort": "502",
|
|
||||||
"SiemensPort": "102",
|
|
||||||
"FetchSleepTime": "100",
|
|
||||||
"WaitingListCount": "100"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
|||||||
44
Samples/AnyType/appsettings.default.json
Normal file
44
Samples/AnyType/appsettings.default.json
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"Modbus.Net": {
|
||||||
|
"TCP": {
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"ModbusPort": "502",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
},
|
||||||
|
"Siemens": {
|
||||||
|
"SiemensPort": "102",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"UDP": {
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"ModbusPort": "502",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"COM": {
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"BaudRate": "9600",
|
||||||
|
"Parity": "Parity.None",
|
||||||
|
"StopBits": "StopBits.One",
|
||||||
|
"DataBits": "8",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"COM": "COM1"
|
||||||
|
},
|
||||||
|
"Siemens": {
|
||||||
|
"COM": "COM2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Controller": {
|
||||||
|
"WaitingListCount": "100"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,5 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*"
|
||||||
"Modbus.Net": {
|
|
||||||
"ModbusPort": "502"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
|||||||
44
Samples/CrossLamp/appsettings.default.json
Normal file
44
Samples/CrossLamp/appsettings.default.json
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"Modbus.Net": {
|
||||||
|
"TCP": {
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"ModbusPort": "502",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
},
|
||||||
|
"Siemens": {
|
||||||
|
"SiemensPort": "102",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"UDP": {
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"ModbusPort": "502",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"COM": {
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"BaudRate": "9600",
|
||||||
|
"Parity": "Parity.None",
|
||||||
|
"StopBits": "StopBits.One",
|
||||||
|
"DataBits": "8",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"COM": "COM1"
|
||||||
|
},
|
||||||
|
"Siemens": {
|
||||||
|
"COM": "COM2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Controller": {
|
||||||
|
"WaitingListCount": "100"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace MachineJob.Service
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
|
|
||||||
List<AddressUnit> _addresses = new List<AddressUnit>
|
List<AddressUnit> _addresses = new List<AddressUnit>
|
||||||
@@ -47,15 +47,16 @@ namespace MachineJob.Service
|
|||||||
IMachine<string> machine = new ModbusMachine<string, string>("ModbusMachine1", ModbusType.Tcp, null, _addresses, true, 1, 2, Endian.BigEndianLsb);
|
IMachine<string> machine = new ModbusMachine<string, string>("ModbusMachine1", ModbusType.Tcp, null, _addresses, true, 1, 2, Endian.BigEndianLsb);
|
||||||
IMachine<string> machine2 = new SiemensMachine<string, string>("SiemensMachine1", SiemensType.Tcp, null, SiemensMachineModel.S7_1200, _addresses2, true, 1, 2);
|
IMachine<string> machine2 = new SiemensMachine<string, string>("SiemensMachine1", SiemensType.Tcp, null, SiemensMachineModel.S7_1200, _addresses2, true, 1, 2);
|
||||||
|
|
||||||
await MachineJobSchedulerCreator.CreateScheduler("Trigger1", -1, 10).Result.From(machine.Id, machine, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Deal(machine.Id + ".Deal", OnSuccess, OnFailure).Result.Run();
|
var machines = new List<IMachine<string>>() { machine, machine2 };
|
||||||
Thread.Sleep(5000);
|
return Task.Run(() => MultipleMachinesJobScheduler.RunScheduler(machines, async (machine, scheduler) =>
|
||||||
await MachineJobSchedulerCreator.CreateScheduler("Trigger2", -1, 10).Result.From(machine2.Id, machine2, MachineDataType.Name).Result.Query(machine2.Id + ".ConsoleQuery", QueryConsole).Result.To(machine2.Id + ".To", machine2).Result.Deal(machine2.Id + ".Deal", OnSuccess, OnFailure).Result.Run();
|
{
|
||||||
|
await scheduler.From(machine.Id, machine, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Deal(machine.Id + ".Deal", OnSuccess, OnFailure).Result.Run();
|
||||||
|
}, -1, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
public override Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await MachineJobSchedulerCreator.CancelJob("Trigger1");
|
return Task.Run(()=>MultipleMachinesJobScheduler.CancelJob());
|
||||||
await MachineJobSchedulerCreator.CancelJob("Trigger2");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task OnSuccess(string machineId)
|
public Task OnSuccess(string machineId)
|
||||||
|
|||||||
44
Samples/MachineJob/appsettings.default.json
Normal file
44
Samples/MachineJob/appsettings.default.json
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"Modbus.Net": {
|
||||||
|
"TCP": {
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"ModbusPort": "502",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
},
|
||||||
|
"Siemens": {
|
||||||
|
"SiemensPort": "102",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"UDP": {
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"ModbusPort": "502",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"COM": {
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"BaudRate": "9600",
|
||||||
|
"Parity": "Parity.None",
|
||||||
|
"StopBits": "StopBits.One",
|
||||||
|
"DataBits": "8",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"COM": "COM1"
|
||||||
|
},
|
||||||
|
"Siemens": {
|
||||||
|
"COM": "COM2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Controller": {
|
||||||
|
"WaitingListCount": "100"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,13 +9,17 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DatabaseWriteConnectionString": "Server=localhost; User ID=root; Password=123456; Database=modbusnettest;"
|
"DatabaseWriteConnectionString": "Server=192.168.8.225; User ID=root; Password=123456; Database=modbusnettest;"
|
||||||
},
|
},
|
||||||
|
|
||||||
"Modbus.Net": {
|
"Modbus.Net": {
|
||||||
"FetchSleepTime": "100",
|
"TCP": {
|
||||||
"IP": "192.168.8.210",
|
"Modbus": {
|
||||||
"IPConnectionTimeout": "5000",
|
"IP": "192.168.8.210"
|
||||||
"ModbusPort": "502",
|
},
|
||||||
"SiemensPort": "102"
|
"Siemens": {
|
||||||
|
"IP": "192.168.8.210"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
|||||||
44
Samples/TripleAdd/appsettings.default.json
Normal file
44
Samples/TripleAdd/appsettings.default.json
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"Modbus.Net": {
|
||||||
|
"TCP": {
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"ModbusPort": "502",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
},
|
||||||
|
"Siemens": {
|
||||||
|
"SiemensPort": "102",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"UDP": {
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"ModbusPort": "502",
|
||||||
|
"IP": "192.168.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"COM": {
|
||||||
|
"FetchSleepTime": "100",
|
||||||
|
"ConnectionTimeout": "5000",
|
||||||
|
"BaudRate": "9600",
|
||||||
|
"Parity": "Parity.None",
|
||||||
|
"StopBits": "StopBits.One",
|
||||||
|
"DataBits": "8",
|
||||||
|
"FullDuplex": "False",
|
||||||
|
"Modbus": {
|
||||||
|
"COM": "COM1"
|
||||||
|
},
|
||||||
|
"Siemens": {
|
||||||
|
"COM": "COM2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Controller": {
|
||||||
|
"WaitingListCount": "100"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFrameworks>net6.0</TargetFrameworks>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net.Modbus\Modbus.Net.Modbus.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net.Siemens\Modbus.Net.Siemens.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net\Modbus.Net.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Modbus.Net;
|
|
||||||
using Modbus.Net.Modbus;
|
|
||||||
using Serilog;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
Log.Logger = new LoggerConfiguration()
|
|
||||||
.MinimumLevel.Information()
|
|
||||||
.WriteTo.Console()
|
|
||||||
.CreateLogger();
|
|
||||||
|
|
||||||
var loggerFactory = new LoggerFactory()
|
|
||||||
.AddSerilog(Log.Logger);
|
|
||||||
LogProvider.SetLogProvider(loggerFactory);
|
|
||||||
|
|
||||||
ModbusMachine<int, string> machine = new ModbusMachine<int, string>(1, ModbusType.Rtu, "COM1",
|
|
||||||
new List<AddressUnit>()
|
|
||||||
{
|
|
||||||
new AddressUnit()
|
|
||||||
{
|
|
||||||
Id = "1",
|
|
||||||
Area = "4X",
|
|
||||||
Address = 1,
|
|
||||||
Name = "test 1",
|
|
||||||
DataType = typeof(ushort)
|
|
||||||
},
|
|
||||||
new AddressUnit()
|
|
||||||
{
|
|
||||||
Id = "2",
|
|
||||||
Area = "4X",
|
|
||||||
Address = 2,
|
|
||||||
Name = "test 2",
|
|
||||||
DataType = typeof(ushort)
|
|
||||||
},
|
|
||||||
new AddressUnit()
|
|
||||||
{
|
|
||||||
Id = "3",
|
|
||||||
Area = "4X",
|
|
||||||
Address = 3,
|
|
||||||
Name = "test 3",
|
|
||||||
DataType = typeof(ushort)
|
|
||||||
},
|
|
||||||
}, true, 2, 1);
|
|
||||||
ModbusMachine<int, string> machine2 = new ModbusMachine<int, string>(2, ModbusType.Rtu, "COM1",
|
|
||||||
new List<AddressUnit>()
|
|
||||||
{
|
|
||||||
new AddressUnit()
|
|
||||||
{
|
|
||||||
Id = "1",
|
|
||||||
Area = "4X",
|
|
||||||
Address = 11,
|
|
||||||
Name = "test 1",
|
|
||||||
DataType = typeof(ushort)
|
|
||||||
},
|
|
||||||
new AddressUnit()
|
|
||||||
{
|
|
||||||
Id = "2",
|
|
||||||
Area = "4X",
|
|
||||||
Address = 12,
|
|
||||||
Name = "test 2",
|
|
||||||
DataType = typeof(ushort)
|
|
||||||
},
|
|
||||||
new AddressUnit()
|
|
||||||
{
|
|
||||||
Id = "3",
|
|
||||||
Area = "4X",
|
|
||||||
Address = 13,
|
|
||||||
Name = "test 3",
|
|
||||||
DataType = typeof(ushort)
|
|
||||||
},
|
|
||||||
}, true, 3, 1);
|
|
||||||
ModbusMachine<int, string> machine3 = new ModbusMachine<int, string>(3, ModbusType.Rtu, "COM1",
|
|
||||||
new List<AddressUnit>()
|
|
||||||
{
|
|
||||||
new AddressUnit()
|
|
||||||
{
|
|
||||||
Id = "1",
|
|
||||||
Area = "4X",
|
|
||||||
Address = 21,
|
|
||||||
Name = "test 1",
|
|
||||||
DataType = typeof(ushort)
|
|
||||||
},
|
|
||||||
new AddressUnit()
|
|
||||||
{
|
|
||||||
Id = "2",
|
|
||||||
Area = "4X",
|
|
||||||
Address = 22,
|
|
||||||
Name = "test 2",
|
|
||||||
DataType = typeof(ushort)
|
|
||||||
},
|
|
||||||
new AddressUnit()
|
|
||||||
{
|
|
||||||
Id = "3",
|
|
||||||
Area = "4X",
|
|
||||||
Address = 23,
|
|
||||||
Name = "test 3",
|
|
||||||
DataType = typeof(ushort)
|
|
||||||
},
|
|
||||||
}, true, 4, 1);
|
|
||||||
Random r = new Random();
|
|
||||||
await MachineJobSchedulerCreator.CreateScheduler("Trigger1", -1, 10).Result.Apply(machine.Id + ".Apply", null, MachineDataType.Address).Result.Query(machine.Id + ".Query", returnDef =>
|
|
||||||
{
|
|
||||||
return new Dictionary<string, double>() {{
|
|
||||||
"4X 1.0", r.Next() % 65536
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"4X 2.0", r.Next() % 65536
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"4X 3.0", r.Next() % 65536
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}).Result.To(machine.Id + ".To", machine).Result.Deal().Result.Run();
|
|
||||||
await MachineJobSchedulerCreator.CreateScheduler("Trigger2", -1, 10).Result.Apply(machine2.Id + ".Apply", null, MachineDataType.Address).Result.Query(machine2.Id + ".Query", returnDef =>
|
|
||||||
{
|
|
||||||
return new Dictionary<string, double>() {{
|
|
||||||
"4X 1.0", r.Next() % 65536
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"4X 2.0", r.Next() % 65536
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"4X 3.0", r.Next() % 65536
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}).Result.To(machine2.Id + ".To", machine2).Result.Deal().Result.Run();
|
|
||||||
await MachineJobSchedulerCreator.CreateScheduler("Trigger3", -1, 10).Result.Apply(machine3.Id + ".Apply", null, MachineDataType.Address).Result.Query(machine3.Id + ".Query", returnDef =>
|
|
||||||
{
|
|
||||||
return new Dictionary<string, double>() {{
|
|
||||||
"4X 1.0", r.Next() % 65536
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"4X 2.0", r.Next() % 65536
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"4X 3.0", r.Next() % 65536
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}).Result.To(machine3.Id + ".To", machine3).Result.Deal().Result.Run();
|
|
||||||
Console.ReadLine();
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"profiles": {
|
|
||||||
"WSL": {
|
|
||||||
"commandName": "WSL2",
|
|
||||||
"distributionName": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user