update code collation
This commit is contained in:
@@ -7,7 +7,7 @@ using Xunit.Abstractions;
|
||||
|
||||
namespace ThingsGateway.Foundation.Tests
|
||||
{
|
||||
public class ModbusServerTest:IDisposable
|
||||
public class ModbusServerTest : IDisposable
|
||||
{
|
||||
private ModbusServer ModbusServer;
|
||||
private ITestOutputHelper _output;
|
||||
@@ -45,11 +45,11 @@ namespace ThingsGateway.Foundation.Tests
|
||||
|
||||
private void ModbusServerClient(string url)
|
||||
{
|
||||
var config = new TouchSocketConfig();
|
||||
var config = new TouchSocketConfig();
|
||||
config.SetListenIPHosts(new IPHost[] { new IPHost(url) })
|
||||
.SetBufferLength(300);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
var service = config.Container.Resolve<TcpService>();
|
||||
var service = config.Container.Resolve<TcpService>();
|
||||
service.Setup(config);
|
||||
ModbusServer = new(service);
|
||||
ModbusServer.ConnectTimeOut = 5000;
|
||||
|
@@ -27,35 +27,35 @@ namespace ThingsGateway.Foundation.Tests
|
||||
List<Task> tasks = new List<Task>();
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
tasks.Add( TestWaiting());
|
||||
tasks.Add(TestWaiting());
|
||||
}
|
||||
_output.WriteLine(data.ToString("yyyy-MM-dd hh:mm:ss fff"));
|
||||
_output.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff"));
|
||||
while (true)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
int dd = 0;
|
||||
private Task TestWaiting()
|
||||
{
|
||||
////然后使用SendThenReturn。
|
||||
return Task.Factory.StartNew(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
int i = Interlocked.Increment(ref dd);
|
||||
IWaitingClient<TcpClient> waitClient = list[i];
|
||||
var returnData = await waitClient.SendThenResponseAsync(new byte[] { 1, 2, 3, 4 }, 0, 4, 5000);
|
||||
_output.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff") + "----" + i);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_output.WriteLine(ex.Message);
|
||||
////然后使用SendThenReturn。
|
||||
return Task.Factory.StartNew(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
int i = Interlocked.Increment(ref dd);
|
||||
IWaitingClient<TcpClient> waitClient = list[i];
|
||||
var returnData = await waitClient.SendThenResponseAsync(new byte[] { 1, 2, 3, 4 }, 0, 4, 5000);
|
||||
_output.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff") + "----" + i);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_output.WriteLine(ex.Message);
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -78,9 +78,9 @@ namespace ThingsGateway.Modbus
|
||||
return await _plc.WriteAsync(deviceVariable.DataType, deviceVariable.VariableAddress, value);
|
||||
}
|
||||
|
||||
protected override Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken)
|
||||
protected override Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken)
|
||||
{
|
||||
return _plc.ReadAsync(address, length);
|
||||
return _plc.ReadAsync(address, length);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -55,8 +55,8 @@ namespace ThingsGateway.Modbus
|
||||
public override void Dispose()
|
||||
{
|
||||
_ModbusTags?.Values?.ToList()?.ForEach(a => a.VariableValueChange -= VariableValueChange);
|
||||
if(_plc!=null)
|
||||
_plc.Write -= Write;
|
||||
if (_plc != null)
|
||||
_plc.Write -= Write;
|
||||
_plc?.Stop();
|
||||
_plc?.Dispose();
|
||||
}
|
||||
@@ -170,11 +170,9 @@ namespace ThingsGateway.Modbus
|
||||
IsFirst = false;
|
||||
|
||||
var list = Values.ToListWithDequeue();
|
||||
await Task.Yield();
|
||||
foreach (var item in list)
|
||||
{
|
||||
await _plc.WriteAsync(item.Item2.DataType, item.Item1, item.Item2.Value?.ToString());
|
||||
//直接异步等待1s
|
||||
}
|
||||
await Task.Delay(100, cancellationToken);
|
||||
}
|
||||
|
@@ -44,8 +44,8 @@ namespace ThingsGateway.OPCDA
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if(PLC != null )
|
||||
PLC.DataChangedHandler -= dataChangedHandler;
|
||||
if (PLC != null)
|
||||
PLC.DataChangedHandler -= dataChangedHandler;
|
||||
PLC?.Disconnect();
|
||||
PLC?.Dispose();
|
||||
PLC = null;
|
||||
|
@@ -46,7 +46,7 @@ namespace ThingsGateway.OPCUA
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if(PLC != null)
|
||||
if (PLC != null)
|
||||
{
|
||||
PLC.DataChangedHandler -= dataChangedHandler;
|
||||
PLC.OpcStatusChange -= opcStatusChange;
|
||||
@@ -102,7 +102,7 @@ namespace ThingsGateway.OPCUA
|
||||
public override async Task<OperResult> WriteValueAsync(CollectVariableRunTime deviceVariable, string value)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
var result = PLC.WriteNode(deviceVariable.VariableAddress,Convert.ChangeType( value,deviceVariable.DataType));
|
||||
var result = PLC.WriteNode(deviceVariable.VariableAddress, Convert.ChangeType(value, deviceVariable.DataType));
|
||||
return result ? OperResult.CreateSuccessResult() : new OperResult();
|
||||
}
|
||||
|
||||
|
@@ -76,7 +76,7 @@ namespace ThingsGateway.RabbitMQ
|
||||
protected override void Init(UploadDevice device)
|
||||
{
|
||||
_curDevice = device;
|
||||
_connectionFactory = new ConnectionFactory
|
||||
_connectionFactory = new ConnectionFactory
|
||||
{
|
||||
HostName = IP,
|
||||
Port = Port,
|
||||
@@ -132,7 +132,7 @@ namespace ThingsGateway.RabbitMQ
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_model==null)
|
||||
if (_model == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -154,7 +154,7 @@ namespace ThingsGateway.RabbitMQ
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////变化推送
|
||||
|
@@ -71,11 +71,11 @@ namespace ThingsGateway.Siemens
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public override OperResult<List<DeviceVariableSourceRead>> LoadSourceRead(List<CollectVariableRunTime> deviceVariables)
|
||||
public override OperResult<List<DeviceVariableSourceRead>> LoadSourceRead(List<CollectVariableRunTime> deviceVariables)
|
||||
{
|
||||
Init(null);
|
||||
_plc.Connect();
|
||||
var data= deviceVariables.LoadSourceRead(_logger, ThingsGatewayBitConverter, _plc);
|
||||
var data = deviceVariables.LoadSourceRead(_logger, ThingsGatewayBitConverter, _plc);
|
||||
_plc?.Disconnect();
|
||||
return data;
|
||||
}
|
||||
|
@@ -1,7 +1,4 @@
|
||||
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
namespace ThingsGateway.Siemens
|
||||
namespace ThingsGateway.Siemens
|
||||
{
|
||||
public class S7_1200 : S7
|
||||
{
|
||||
@@ -23,11 +20,11 @@ namespace ThingsGateway.Siemens
|
||||
_plc.DataFormat = DataFormat;
|
||||
_plc.ConnectTimeOut = ConnectTimeOut;
|
||||
_plc.TimeOut = TimeOut;
|
||||
if(LocalTSAP !=0)
|
||||
if (LocalTSAP != 0)
|
||||
{
|
||||
_plc.LocalTSAP = LocalTSAP;
|
||||
}
|
||||
if(DestTSAP!=0)
|
||||
if (DestTSAP != 0)
|
||||
{
|
||||
_plc.DestTSAP = DestTSAP;
|
||||
}
|
||||
|
@@ -1,6 +1,4 @@
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
namespace ThingsGateway.Siemens
|
||||
namespace ThingsGateway.Siemens
|
||||
{
|
||||
public class S7_1500 : S7
|
||||
{
|
||||
|
@@ -1,6 +1,4 @@
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
namespace ThingsGateway.Siemens
|
||||
namespace ThingsGateway.Siemens
|
||||
{
|
||||
public class S7_200 : S7
|
||||
{
|
||||
|
@@ -1,6 +1,4 @@
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
namespace ThingsGateway.Siemens
|
||||
namespace ThingsGateway.Siemens
|
||||
{
|
||||
public class S7_200SMART : S7
|
||||
{
|
||||
|
@@ -1,6 +1,4 @@
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
namespace ThingsGateway.Siemens
|
||||
namespace ThingsGateway.Siemens
|
||||
{
|
||||
public class S7_300 : S7
|
||||
{
|
||||
|
@@ -1,6 +1,4 @@
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
namespace ThingsGateway.Siemens
|
||||
namespace ThingsGateway.Siemens
|
||||
{
|
||||
public class S7_400 : S7
|
||||
{
|
||||
|
@@ -70,7 +70,7 @@ namespace ThingsGateway.Core
|
||||
//如果配置不写入mongitor日志和日志名称为System.Logging.LoggingMonitor
|
||||
if (!WriteMonitor && logMsg.LogName == "System.Logging.LoggingMonitor")
|
||||
return false;
|
||||
if(!logMsg.LogName.StartsWith("System") &&
|
||||
if (!logMsg.LogName.StartsWith("System") &&
|
||||
!logMsg.LogName.StartsWith("Microsoft"))
|
||||
{ return false; }
|
||||
return logMsg.LogLevel == logLevel;
|
||||
|
@@ -7,9 +7,9 @@ namespace ThingsGateway.Foundation.Extension
|
||||
/// <summary>
|
||||
/// 批量出队
|
||||
/// </summary>
|
||||
public static List<T> ToListWithDequeue<T>(this ConcurrentQueue<T> values, int conut=0)
|
||||
public static List<T> ToListWithDequeue<T>(this ConcurrentQueue<T> values, int conut = 0)
|
||||
{
|
||||
if(conut==0)
|
||||
if (conut == 0)
|
||||
{
|
||||
conut = values.Count;
|
||||
}
|
||||
|
@@ -16,8 +16,8 @@ namespace ThingsGateway.Foundation.Serial
|
||||
PortName = strs[0];
|
||||
BaudRate = Convert.ToInt32(strs[1]);
|
||||
DataBits = Convert.ToInt32(strs[2]);
|
||||
Parity = (Parity)Enum.Parse(typeof(Parity),strs[3]);
|
||||
StopBits = (StopBits)Enum.Parse(typeof(StopBits),strs[4]);
|
||||
Parity = (Parity)Enum.Parse(typeof(Parity), strs[3]);
|
||||
StopBits = (StopBits)Enum.Parse(typeof(StopBits), strs[4]);
|
||||
return this;
|
||||
}
|
||||
public override string ToString()
|
||||
|
@@ -110,7 +110,7 @@ namespace ThingsGateway.Foundation
|
||||
|
||||
while (true)
|
||||
{
|
||||
_locker.Lock();
|
||||
_locker.Lock();
|
||||
{
|
||||
if (_waitQueue.Count == 0)
|
||||
{
|
||||
@@ -125,7 +125,7 @@ namespace ThingsGateway.Foundation
|
||||
|
||||
private bool _isDisposed;
|
||||
|
||||
private readonly EasyLock _locker = new ();
|
||||
private readonly EasyLock _locker = new();
|
||||
|
||||
private readonly Queue<TaskCompletionSource<bool>> _waitQueue =
|
||||
new Queue<TaskCompletionSource<bool>>();
|
||||
|
@@ -91,7 +91,7 @@ namespace ThingsGateway.Foundation
|
||||
/// 等待指定毫秒
|
||||
/// </summary>
|
||||
/// <param name="millisecond"></param>
|
||||
public WaitDataStatus Wait(int millisecond)
|
||||
public WaitDataStatus Wait(int millisecond)
|
||||
{
|
||||
|
||||
var task = m_waitHandle.WaitOneAsync();
|
||||
@@ -123,7 +123,6 @@ namespace ThingsGateway.Foundation
|
||||
/// <param name="millisecond"></param>
|
||||
public async Task<WaitDataStatus> WaitAsync(int millisecond)
|
||||
{
|
||||
await Task.Yield();
|
||||
var task = m_waitHandle.WaitOneAsync();
|
||||
if (await Task.WhenAny(task, Task.Delay(millisecond)) != task)
|
||||
{
|
||||
|
@@ -7,7 +7,7 @@ namespace ThingsGateway.Foundation
|
||||
private readonly TGWaitData<ResponsedData> m_waitData;
|
||||
|
||||
private volatile bool breaked;
|
||||
|
||||
|
||||
public TGWaitingClient(TClient client, WaitingOptions waitingOptions)
|
||||
{
|
||||
Client = client ?? throw new ArgumentNullException(nameof(client));
|
||||
@@ -418,7 +418,7 @@ namespace ThingsGateway.Foundation
|
||||
{
|
||||
responsedData = new ResponsedData(null, requestInfo);
|
||||
}
|
||||
m_waitData.Set(responsedData);
|
||||
m_waitData.Set(responsedData);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -60,7 +60,7 @@ public static class DataTypeExtension
|
||||
return typeof(ulong);
|
||||
case DataTypeEnum.Single:
|
||||
return typeof(float);
|
||||
|
||||
|
||||
case DataTypeEnum.Double:
|
||||
return typeof(double);
|
||||
default:
|
||||
|
@@ -166,7 +166,7 @@ public class CollectDeviceCore : DisposableObject
|
||||
try
|
||||
{
|
||||
await Task.Delay(100, StoppingToken.Token);
|
||||
|
||||
|
||||
if (_driver == null) continue;
|
||||
|
||||
if (Device?.Enable == false)
|
||||
@@ -178,7 +178,7 @@ public class CollectDeviceCore : DisposableObject
|
||||
{
|
||||
if (Device.DeviceStatus != DeviceStatusEnum.OnLineButNoInitialValue && Device.DeviceStatus != DeviceStatusEnum.OnLine)
|
||||
Device.DeviceStatus = DeviceStatusEnum.OnLineButNoInitialValue;
|
||||
if(DeviceVariableSourceReads.Count==0&&Device.DeviceVariableRunTimes.Where(a=>a.OtherMethod.IsNullOrEmpty()).Count()>0)
|
||||
if (DeviceVariableSourceReads.Count == 0 && Device.DeviceVariableRunTimes.Where(a => a.OtherMethod.IsNullOrEmpty()).Count() > 0)
|
||||
{
|
||||
Device.DeviceStatus = DeviceStatusEnum.OnLineButNoInitialValue;
|
||||
Device.DeviceOffMsg = "分包失败,请检查变量地址是否符合规则";
|
||||
@@ -249,11 +249,11 @@ public class CollectDeviceCore : DisposableObject
|
||||
}
|
||||
|
||||
|
||||
if(deviceMedsVariableFailedNum == 0 && deviceSourceVariableFailedNum == 0)
|
||||
if (deviceMedsVariableFailedNum == 0 && deviceSourceVariableFailedNum == 0)
|
||||
{
|
||||
Device.ActiveTime = DateTime.Now;
|
||||
}
|
||||
if (deviceMedsVariableFailedNum == 0 && deviceSourceVariableFailedNum == 0&&(DeviceVariableSourceReads.Count != 0|| DeviceVariableMedReads.Count!=0))
|
||||
if (deviceMedsVariableFailedNum == 0 && deviceSourceVariableFailedNum == 0 && (DeviceVariableSourceReads.Count != 0 || DeviceVariableMedReads.Count != 0))
|
||||
{
|
||||
Device.DeviceStatus = DeviceStatusEnum.OnLine;
|
||||
|
||||
|
@@ -3,11 +3,11 @@
|
||||
|
||||
public class CollectMulDeviceCore : CollectDeviceCore
|
||||
{
|
||||
public CollectMulDeviceCore(IServiceScopeFactory scopeFactory):base(scopeFactory)
|
||||
public CollectMulDeviceCore(IServiceScopeFactory scopeFactory) : base(scopeFactory)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public override void StartThread()
|
||||
|
@@ -3,10 +3,8 @@
|
||||
using System.Threading;
|
||||
|
||||
using ThingsGateway.Foundation;
|
||||
using ThingsGateway.Foundation.Serial;
|
||||
|
||||
using TouchSocket.Core;
|
||||
using TouchSocket.Sockets;
|
||||
|
||||
namespace ThingsGateway.Web.Foundation;
|
||||
/// <summary>
|
||||
|
@@ -4,8 +4,6 @@ using System.Collections.Concurrent;
|
||||
|
||||
using ThingsGateway.Core;
|
||||
|
||||
using TouchSocket.Core;
|
||||
|
||||
namespace ThingsGateway.Web.Foundation
|
||||
{
|
||||
/// <summary>
|
||||
|
@@ -231,7 +231,7 @@ namespace ThingsGateway.Web.Foundation
|
||||
foreach (var devData in devDatas)
|
||||
{
|
||||
var propertyExcels = devData.DevicePropertys.Adapt<List<DevicePropertyExport>>();
|
||||
if(propertyExcels != null)
|
||||
if (propertyExcels != null)
|
||||
{
|
||||
//需要手动改正设备名称
|
||||
propertyExcels.ForEach(it => it.DeviceName = devData.Name);
|
||||
|
@@ -33,7 +33,7 @@ namespace ThingsGateway.Application
|
||||
[Description("设备名称")]
|
||||
public string Name { get; set; }
|
||||
[Description("插件名称")]
|
||||
public string PluginName { get; set; }
|
||||
public string PluginName { get; set; }
|
||||
[Description("设备组")]
|
||||
public string DeviceGroup { get; set; }
|
||||
}
|
||||
|
@@ -55,12 +55,12 @@
|
||||
<MTabItem>
|
||||
<MRow NoGutters>
|
||||
<MCol Md=2 Cols="12">
|
||||
<MCard Class="ma-2" Style="height:100%">
|
||||
<MCard Class="ma-2" Style="height: calc(100vh - 300px)">
|
||||
<MCardTitle>
|
||||
<MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="mx-2 my-1" @bind-Value="_collectDeviceGroupSearchName"
|
||||
Outlined Label=@typeof(CollectDevice).GetDescription(nameof(CollectDevice.DeviceGroup)) />
|
||||
</MCardTitle>
|
||||
<MTreeview Dense TItem="string" TKey="string" ActiveChanged=@(async a=>
|
||||
<MTreeview Style="height: calc(100vh - 320px);overflow-y:auto" Dense TItem="string" TKey="string" ActiveChanged=@(async a=>
|
||||
{
|
||||
if(_collectDeviceGroup!=a.FirstOrDefault())
|
||||
{
|
||||
@@ -114,12 +114,12 @@
|
||||
<MTabItem>
|
||||
<MRow>
|
||||
<MCol Md=2 Cols="12">
|
||||
<MCard Class="ma-2" Style="height:100%">
|
||||
<MCard Class="ma-2" Style="height: calc(100vh - 300px)">
|
||||
<MCardTitle>
|
||||
<MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="mx-2 my-1" @bind-Value="_uploadDeviceGroupSearchName"
|
||||
Outlined Label=@typeof(UploadDevice).GetDescription(nameof(UploadDevice.DeviceGroup)) />
|
||||
</MCardTitle>
|
||||
<MTreeview Dense TItem="string" TKey="string" ActiveChanged=@(async a=>
|
||||
<MTreeview Style="height: calc(100vh - 320px);overflow-y:auto" Dense TItem="string" TKey="string" ActiveChanged=@(async a=>
|
||||
{
|
||||
if(_uploadDeviceGroup!=a.FirstOrDefault())
|
||||
{
|
||||
@@ -446,7 +446,7 @@
|
||||
uploadDeviceInfoItem = item;
|
||||
isShowUploadDeviceInfo = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@code {
|
||||
StringNumber panel { get; set; }
|
||||
|
@@ -192,7 +192,6 @@ namespace ThingsGateway.Web.Rcl.Core
|
||||
{
|
||||
QueryLoading = true;
|
||||
StateHasChanged();
|
||||
await Task.Yield();
|
||||
PageItems = await QueryCall.Invoke(SearchModel);
|
||||
Items = PageItems.Records;
|
||||
|
||||
|
Reference in New Issue
Block a user