Application settings change
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -7,13 +9,19 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
@@ -8,12 +10,18 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"), false)
|
: base(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"), false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +33,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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "100")));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "100")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -7,13 +9,19 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
@@ -8,12 +10,18 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"), false)
|
: base(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"), false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +33,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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0")));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -7,13 +9,19 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["COM"], slaveAddress, masterAddress)
|
: this(configuration.GetSection("Modbus.Net")["COM"], slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -10,6 +12,12 @@ 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>
|
||||||
@@ -18,7 +26,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusAsciiProtocolLinker(string com, int slaveAddress)
|
public ModbusAsciiProtocolLinker(string com, int slaveAddress)
|
||||||
: base(com, 9600, Parity.None, StopBits.One, 8, 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["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(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -7,13 +9,19 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -7,12 +9,18 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"), false)
|
: base(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"), false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +32,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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0")));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -7,13 +9,19 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -7,12 +9,18 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"), false)
|
: base(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"), false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +32,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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0")));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -7,13 +9,19 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["COM"], slaveAddress, masterAddress)
|
: this(configuration.GetSection("Modbus.Net")["COM"], slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
@@ -9,6 +11,12 @@ 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>
|
||||||
@@ -17,7 +25,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusRtuProtocolLinker(string com, int slaveAddress)
|
public ModbusRtuProtocolLinker(string com, int slaveAddress)
|
||||||
: base(com, 9600, Parity.None, StopBits.One, 8, 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["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(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -7,13 +9,19 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -8,12 +10,18 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"))
|
: this(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +32,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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int> { 4, 5 }, 6)));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int> { 4, 5 }, 6)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -7,13 +9,19 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], slaveAddress, masterAddress)
|
: this(configuration.GetSection("Modbus.Net")["IP"], slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
{
|
{
|
||||||
@@ -8,12 +10,18 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ModbusPort"] ?? "502"))
|
: this(ip, int.Parse(configuration.GetSection("Modbus.Net")["ModbusPort"] ?? "502"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +32,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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int> { 4, 5 }, 6)));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int> { 4, 5 }, 6)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Nito.AsyncEx;
|
using Nito.AsyncEx;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Modbus.Net.Siemens
|
namespace Modbus.Net.Siemens
|
||||||
@@ -9,6 +11,12 @@ 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();
|
||||||
|
|
||||||
@@ -18,7 +26,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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["COM"], slaveAddress, masterAddress)
|
: this(configuration.GetSection("Modbus.Net")["COM"], slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -11,6 +13,12 @@ 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>
|
||||||
@@ -19,7 +27,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public SiemensPpiProtocolLinker(string com, int slaveAddress)
|
public SiemensPpiProtocolLinker(string com, int slaveAddress)
|
||||||
: base(com, 9600, Parity.Even, StopBits.One, 8, slaveAddress)
|
: base(com, 9600, Parity.Even, StopBits.One, 8, slaveAddress)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0"), true, null, 100));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(configuration.GetSection("Modbus.Net")["FetchSleepTime"] ?? "0"), true, null, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Nito.AsyncEx;
|
using Nito.AsyncEx;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Modbus.Net.Siemens
|
namespace Modbus.Net.Siemens
|
||||||
@@ -20,6 +22,12 @@ 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>
|
||||||
@@ -31,7 +39,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, new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"])
|
: this(tdpuSize, tsapSrc, tsapDst, maxCalling, maxCalled, maxPdu, configuration.GetSection("Modbus.Net")["IP"])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +57,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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["SiemensPort"] ?? "102"))
|
int.Parse(configuration.GetSection("Modbus.Net")["SiemensPort"] ?? "102"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net.Siemens
|
namespace Modbus.Net.Siemens
|
||||||
{
|
{
|
||||||
@@ -9,12 +10,18 @@ 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(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["SiemensPort"] ?? "102"))
|
: this(ip, int.Parse(configuration.GetSection("Modbus.Net")["SiemensPort"] ?? "102"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
|
|
||||||
namespace Modbus.Net
|
namespace Modbus.Net
|
||||||
@@ -8,6 +10,12 @@ 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>
|
||||||
/// 构造器
|
/// 构造器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -17,7 +25,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="dataBits">数据位</param>
|
/// <param name="dataBits">数据位</param>
|
||||||
/// <param name="slaveAddress">从站地址</param>
|
/// <param name="slaveAddress">从站地址</param>
|
||||||
protected ComProtocolLinker(int baudRate, Parity parity, StopBits stopBits, int dataBits, int slaveAddress)
|
protected ComProtocolLinker(int baudRate, Parity parity, StopBits stopBits, int dataBits, int slaveAddress)
|
||||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["COM"], baudRate, parity, stopBits, dataBits, slaveAddress)
|
: this(configuration.GetSection("Modbus.Net")["COM"], baudRate, parity, stopBits, dataBits, slaveAddress)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +43,7 @@ namespace Modbus.Net
|
|||||||
int slaveAddress, bool isFullDuplex = false)
|
int slaveAddress, bool isFullDuplex = false)
|
||||||
: this(
|
: this(
|
||||||
com, baudRate, parity, stopBits, dataBits,
|
com, baudRate, parity, stopBits, dataBits,
|
||||||
int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["ComConnectionTimeout"] ?? "-1"), slaveAddress, isFullDuplex)
|
int.Parse(configuration.GetSection("Modbus.Net")["ComConnectionTimeout"] ?? "-1"), slaveAddress, isFullDuplex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net
|
namespace Modbus.Net
|
||||||
{
|
{
|
||||||
@@ -8,11 +9,17 @@ 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>
|
||||||
/// 构造器
|
/// 构造器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected TcpProtocolLinker(int port)
|
protected TcpProtocolLinker(int port)
|
||||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], port)
|
: this(configuration.GetSection("Modbus.Net")["IP"], port)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +30,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="port">端口</param>
|
/// <param name="port">端口</param>
|
||||||
/// <param name="isFullDuplex">是否为全双工</param>
|
/// <param name="isFullDuplex">是否为全双工</param>
|
||||||
protected TcpProtocolLinker(string ip, int port, bool isFullDuplex = true)
|
protected TcpProtocolLinker(string ip, int port, bool isFullDuplex = true)
|
||||||
: this(ip, port, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IPConnectionTimeout"] ?? "-1"), isFullDuplex)
|
: this(ip, port, int.Parse(configuration.GetSection("Modbus.Net")["IPConnectionTimeout"] ?? "-1"), isFullDuplex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Modbus.Net
|
namespace Modbus.Net
|
||||||
{
|
{
|
||||||
@@ -8,11 +9,17 @@ 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>
|
||||||
/// 构造器
|
/// 构造器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected UdpProtocolLinker(int port)
|
protected UdpProtocolLinker(int port)
|
||||||
: this(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IP"], port)
|
: this(configuration.GetSection("Modbus.Net")["IP"], port)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +30,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="port">端口</param>
|
/// <param name="port">端口</param>
|
||||||
/// <param name="isFullDuplex">是否为全双工</param>
|
/// <param name="isFullDuplex">是否为全双工</param>
|
||||||
protected UdpProtocolLinker(string ip, int port, bool isFullDuplex = true)
|
protected UdpProtocolLinker(string ip, int port, bool isFullDuplex = true)
|
||||||
: this(ip, port, int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["IPConnectionTimeout"] ?? "-1"), isFullDuplex)
|
: this(ip, port, int.Parse(configuration.GetSection("Modbus.Net")["IPConnectionTimeout"] ?? "-1"), isFullDuplex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"Config": {
|
"Modbus.Net": {
|
||||||
"COM": "COM1",
|
"COM": "COM1",
|
||||||
"IP": "192.168.1.1",
|
"IP": "192.168.1.1",
|
||||||
"ComConnectionTimeout": "3000",
|
"ComConnectionTimeout": "3000",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"Config": {
|
"Modbus.Net": {
|
||||||
"ModbusPort": "502"
|
"ModbusPort": "502"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,13 @@ namespace MachineJob
|
|||||||
{
|
{
|
||||||
public class DatabaseWriteContext : DbContext
|
public class DatabaseWriteContext : DbContext
|
||||||
{
|
{
|
||||||
static readonly string connectionString = new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetConnectionString("DatabaseWriteConnectionString")!;
|
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 string connectionString = configuration.GetConnectionString("DatabaseWriteConnectionString")!;
|
||||||
|
|
||||||
public DbSet<DatabaseWriteEntity> DatabaseWrites { get; set; }
|
public DbSet<DatabaseWriteEntity> DatabaseWrites { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ namespace MachineJob.Service
|
|||||||
new AddressUnit() { Area = "DB1", Address = 18, DataType = typeof(short), Id = "10", Name = "Test10" }
|
new AddressUnit() { Area = "DB1", Address = 18, DataType = typeof(short), Id = "10", Name = "Test10" }
|
||||||
};
|
};
|
||||||
|
|
||||||
IMachine<string> machine = new ModbusMachine<string, string>("ModbusMachine1", ModbusType.Tcp, "192.168.0.161", _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, "192.168.0.161", 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();
|
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();
|
||||||
Thread.Sleep(5000);
|
Thread.Sleep(5000);
|
||||||
|
|||||||
@@ -11,7 +11,11 @@
|
|||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DatabaseWriteConnectionString": "Server=localhost; User ID=root; Password=123456; Database=modbusnettest;"
|
"DatabaseWriteConnectionString": "Server=localhost; User ID=root; Password=123456; Database=modbusnettest;"
|
||||||
},
|
},
|
||||||
"Config": {
|
"Modbus.Net": {
|
||||||
"FetchSleepTime": "100"
|
"FetchSleepTime": "100",
|
||||||
|
"IP": "192.168.8.210",
|
||||||
|
"IPConnectionTimeout": "5000",
|
||||||
|
"ModbusPort": "502",
|
||||||
|
"SiemensPort": "102"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,8 @@ ModbusMachine<int, string> machine3 = new ModbusMachine<int, string>(3, ModbusTy
|
|||||||
},
|
},
|
||||||
}, true, 4, 1);
|
}, true, 4, 1);
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
await MachineJobSchedulerCreator.CreateScheduler("Trigger1", -1, 10).Result.Apply(machine.Id + ".Apply", null, MachineDataType.Address).Result.Query(machine.Id + ".Query", returnDef => {
|
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>() {{
|
return new Dictionary<string, double>() {{
|
||||||
"4X 1.0", r.Next() % 65536
|
"4X 1.0", r.Next() % 65536
|
||||||
},
|
},
|
||||||
@@ -111,7 +112,8 @@ await MachineJobSchedulerCreator.CreateScheduler("Trigger1", -1, 10).Result.Appl
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}).Result.To(machine.Id + ".To", machine).Result.Deal().Result.Run();
|
}).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 => {
|
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>() {{
|
return new Dictionary<string, double>() {{
|
||||||
"4X 1.0", r.Next() % 65536
|
"4X 1.0", r.Next() % 65536
|
||||||
},
|
},
|
||||||
@@ -123,7 +125,8 @@ await MachineJobSchedulerCreator.CreateScheduler("Trigger2", -1, 10).Result.Appl
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}).Result.To(machine2.Id + ".To", machine2).Result.Deal().Result.Run();
|
}).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 => {
|
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>() {{
|
return new Dictionary<string, double>() {{
|
||||||
"4X 1.0", r.Next() % 65536
|
"4X 1.0", r.Next() % 65536
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user