写入使用类属性传值;
写入修改为单例服务
This commit is contained in:
15
HTCoreServiceApp/Common/WritePara.cs
Normal file
15
HTCoreServiceApp/Common/WritePara.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
namespace HTCoreServiceApp.Common
|
||||||
|
{
|
||||||
|
public class WritePara
|
||||||
|
{
|
||||||
|
public string TagName { get; set; }
|
||||||
|
public string GroupName { get; set; }
|
||||||
|
public string WriteAddress { get; set; }
|
||||||
|
public byte DataType { get; set; }
|
||||||
|
public string Value { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
//public record WritePara(string TagName, string GroupName, string WriteAddress, byte DataType, string Value)
|
||||||
|
//{
|
||||||
|
//}
|
||||||
|
}
|
@ -485,15 +485,15 @@ namespace HTCoreServiceApp.Communicate.AllenBradleyEIP
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="writePara"></param>
|
/// <param name="writePara"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Write(string writePara)
|
public int Write(WritePara writePara)
|
||||||
{
|
{
|
||||||
Result reCode = new Result() { ErrCode = 0} ;
|
Result reCode = new Result() { ErrCode = 0} ;
|
||||||
JObject valueJson = JObject.Parse(writePara);
|
//JObject valueJson = JObject.Parse(writePara);
|
||||||
var srcValue = valueJson[propertyName: "Value"].ToString();
|
var srcValue = writePara.Value; //valueJson[propertyName: "Value"].ToString();
|
||||||
var writeAddress = valueJson[propertyName: "WriteAddress"].ToString();
|
var writeAddress = writePara.WriteAddress;//valueJson[propertyName: "WriteAddress"].ToString();
|
||||||
var dataType =short.Parse(valueJson[propertyName: "DataType"].ToString());
|
var dataType = writePara.DataType;//short.Parse(valueJson[propertyName: "DataType"].ToString());
|
||||||
var groupName = valueJson[propertyName: "GroupName"].ToString();
|
var groupName = writePara.GroupName; //valueJson[propertyName: "GroupName"].ToString();
|
||||||
var tagName = valueJson[propertyName: "TagName"].ToString();
|
var tagName = writePara.TagName; //valueJson[propertyName: "TagName"].ToString();
|
||||||
|
|
||||||
decimal value = decimal.Parse(srcValue);
|
decimal value = decimal.Parse(srcValue);
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
|
@ -460,15 +460,15 @@ namespace HTCoreServiceApp.Communicate.AllenBradleyEIPTag
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="writePara"></param>
|
/// <param name="writePara"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Write(string writePara)
|
public int Write(WritePara writePara)
|
||||||
{
|
{
|
||||||
Result reCode = new Result() { ErrCode = 0} ;
|
Result reCode = new Result() { ErrCode = 0} ;
|
||||||
JObject valueJson = JObject.Parse(writePara);
|
//JObject valueJson = JObject.Parse(writePara);
|
||||||
var srcValue = valueJson[propertyName: "Value"].ToString();
|
var srcValue = writePara.Value; //valueJson[propertyName: "Value"].ToString();
|
||||||
var writeAddress = valueJson[propertyName: "WriteAddress"].ToString();
|
var writeAddress = writePara.WriteAddress;//valueJson[propertyName: "WriteAddress"].ToString();
|
||||||
var dataType =short.Parse(valueJson[propertyName: "DataType"].ToString());
|
var dataType = writePara.DataType;//short.Parse(valueJson[propertyName: "DataType"].ToString());
|
||||||
var groupName = valueJson[propertyName: "GroupName"].ToString();
|
var groupName = writePara.GroupName; //valueJson[propertyName: "GroupName"].ToString();
|
||||||
var tagName = valueJson[propertyName: "TagName"].ToString();
|
var tagName = writePara.TagName; //valueJson[propertyName: "TagName"].ToString();
|
||||||
|
|
||||||
decimal value = decimal.Parse(srcValue);
|
decimal value = decimal.Parse(srcValue);
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
|
@ -104,6 +104,7 @@ namespace HTCoreServiceApp.Communicate.DriverSiemensS7
|
|||||||
scanTagsPara.UpdateRate = MetaGroups.Where(x => x.GroupId == metaGroup.Key.GroupId).ToList().First().UpdateRate;
|
scanTagsPara.UpdateRate = MetaGroups.Where(x => x.GroupId == metaGroup.Key.GroupId).ToList().First().UpdateRate;
|
||||||
scanTagsPara.IsConsecutive = (bool)MetaGroups.Where(x => x.GroupId == metaGroup.Key.GroupId).ToList().First().IsActive;
|
scanTagsPara.IsConsecutive = (bool)MetaGroups.Where(x => x.GroupId == metaGroup.Key.GroupId).ToList().First().IsActive;
|
||||||
scanTagsPara.IsActive = MetaGroups.Where(x => x.GroupId == metaGroup.Key.GroupId).ToList().First().IsActive;
|
scanTagsPara.IsActive = MetaGroups.Where(x => x.GroupId == metaGroup.Key.GroupId).ToList().First().IsActive;
|
||||||
|
//scanTagsPara.IsActive = false;
|
||||||
scanTagsPara.ScanTags = MetaTags.Where(x => x.GroupId == metaGroup.Key.GroupId).ToList();
|
scanTagsPara.ScanTags = MetaTags.Where(x => x.GroupId == metaGroup.Key.GroupId).ToList();
|
||||||
short driverID = (short)MetaGroups.Where(x => x.GroupId == metaGroup.Key.GroupId).ToList().First().DriverId;
|
short driverID = (short)MetaGroups.Where(x => x.GroupId == metaGroup.Key.GroupId).ToList().First().DriverId;
|
||||||
scanTagsPara.DriverName = DriverName;
|
scanTagsPara.DriverName = DriverName;
|
||||||
@ -703,15 +704,17 @@ namespace HTCoreServiceApp.Communicate.DriverSiemensS7
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="writePara"></param>
|
/// <param name="writePara"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Write(string writePara)
|
public int Write(WritePara writePara)
|
||||||
{
|
{
|
||||||
|
//var t1 = DateTime.Now;
|
||||||
int reCode = 0;
|
int reCode = 0;
|
||||||
JObject valueJson = JObject.Parse(writePara);
|
//JObject valueJson = JObject.Parse(writePara);
|
||||||
var srcValue = valueJson[propertyName: "Value"].ToString();
|
var srcValue = writePara.Value; //valueJson[propertyName: "Value"].ToString();
|
||||||
var writeAddress = valueJson[propertyName: "WriteAddress"].ToString();
|
var writeAddress = writePara.WriteAddress;//valueJson[propertyName: "WriteAddress"].ToString();
|
||||||
var dataType =short.Parse(valueJson[propertyName: "DataType"].ToString());
|
var dataType = writePara.DataType;//short.Parse(valueJson[propertyName: "DataType"].ToString());
|
||||||
var groupName = valueJson[propertyName: "GroupName"].ToString();
|
var groupName = writePara.GroupName; //valueJson[propertyName: "GroupName"].ToString();
|
||||||
|
var windex = writeAddress.IndexOf(".");
|
||||||
|
writeAddress = writeAddress.Remove(windex, 1).Insert(windex, ",");
|
||||||
var array = writeAddress.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var array = writeAddress.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
var DBNum_string = array[0].ToString();
|
var DBNum_string = array[0].ToString();
|
||||||
var DBNum = int.Parse(Regex.Replace(DBNum_string, "[a-z]", "", RegexOptions.IgnoreCase));
|
var DBNum = int.Parse(Regex.Replace(DBNum_string, "[a-z]", "", RegexOptions.IgnoreCase));
|
||||||
@ -805,6 +808,9 @@ namespace HTCoreServiceApp.Communicate.DriverSiemensS7
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Console.WriteLine(writePara);
|
Console.WriteLine(writePara);
|
||||||
|
//var t2 = DateTime.Now;
|
||||||
|
//var timediff = t2 - t1;
|
||||||
|
//Console.WriteLine($"S7写入耗时:{timediff}");
|
||||||
return reCode;
|
return reCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -844,7 +850,7 @@ namespace HTCoreServiceApp.Communicate.DriverSiemensS7
|
|||||||
value = "0";
|
value = "0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var writePara = new
|
var writePara = new WritePara
|
||||||
{
|
{
|
||||||
TagName = tagName,
|
TagName = tagName,
|
||||||
GroupName = groupName,
|
GroupName = groupName,
|
||||||
@ -852,9 +858,9 @@ namespace HTCoreServiceApp.Communicate.DriverSiemensS7
|
|||||||
DataType = dataType,
|
DataType = dataType,
|
||||||
Value = value
|
Value = value
|
||||||
};
|
};
|
||||||
string serJson = JsonConvert.SerializeObject(writePara);
|
//string serJson = JsonConvert.SerializeObject(writePara);
|
||||||
|
|
||||||
Write(serJson);
|
Write(writePara);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -492,7 +492,7 @@ namespace HTCoreServiceApp.Communicate.Modbus
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Write(string writePara)
|
public int Write(WritePara writePara)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -501,7 +501,7 @@ namespace HTCoreServiceApp.Communicate.ModbusTcp
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Write(string writePara)
|
public int Write(WritePara writePara)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using HTCoreServiceApp.Common;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -29,7 +30,7 @@ namespace HTCoreServiceApp.DriverInterface
|
|||||||
/// 往cpu中写入
|
/// 往cpu中写入
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Write(string writePara);
|
public int Write(WritePara writePara);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 无用暂留
|
/// 无用暂留
|
||||||
|
@ -161,7 +161,7 @@ namespace HTCoreServiceApp
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int DriverWrite(string para)
|
public int DriverWrite(WritePara para)
|
||||||
{
|
{
|
||||||
return DriverEntity.Write(para);
|
return DriverEntity.Write(para);
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,8 @@ namespace HTCoreServiceApp
|
|||||||
|
|
||||||
//builder.Services.AddEndpointsApiExplorer();
|
//builder.Services.AddEndpointsApiExplorer();
|
||||||
|
|
||||||
builder.Services.AddScoped<DataLiveCache>();
|
builder.Services.AddSingleton<DataLiveCache>();
|
||||||
builder.Services.AddScoped<DeviceControl>();
|
builder.Services.AddSingleton<DeviceControl>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
@ -105,4 +105,5 @@ namespace HTCoreServiceApp
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
||||||
using Microsoft.Extensions.Caching.Distributed;
|
using Microsoft.Extensions.Caching.Distributed;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Newtonsoft.Json;
|
//using Newtonsoft.Json;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -14,6 +14,8 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace HTCoreServiceApp.WebApi
|
namespace HTCoreServiceApp.WebApi
|
||||||
@ -49,7 +51,7 @@ namespace HTCoreServiceApp.WebApi
|
|||||||
//[HttpGet]
|
//[HttpGet]
|
||||||
public async Task<string> SetDeviceData(string groupName,string tagName,string value)
|
public async Task<string> SetDeviceData(string groupName,string tagName,string value)
|
||||||
{
|
{
|
||||||
|
//var t1 = DateTime.Now;
|
||||||
//var ip = HttpContext.GetClientUserIp();
|
//var ip = HttpContext.GetClientUserIp();
|
||||||
//var cache = StaticLibrary.MemoryCacheHelper.Get<List<LiveGroupDictionary>>(driverName).Where(x=>x.GroupName == groupName).First();
|
//var cache = StaticLibrary.MemoryCacheHelper.Get<List<LiveGroupDictionary>>(driverName).Where(x=>x.GroupName == groupName).First();
|
||||||
//var val = new List<LiveGroupDictionary>();
|
//var val = new List<LiveGroupDictionary>();
|
||||||
@ -78,8 +80,8 @@ namespace HTCoreServiceApp.WebApi
|
|||||||
reCode = 1;
|
reCode = 1;
|
||||||
return reCode.ToString();
|
return reCode.ToString();
|
||||||
}
|
}
|
||||||
var windex = writeAddress.IndexOf(".");
|
//var windex = writeAddress.IndexOf(".");
|
||||||
writeAddress = writeAddress.Remove(windex, 1).Insert(windex, ",");
|
//writeAddress = writeAddress.Remove(windex, 1).Insert(windex, ",");
|
||||||
//var valueHandle = 0;
|
//var valueHandle = 0;
|
||||||
if (dataType == (short)DataType.BOOL)
|
if (dataType == (short)DataType.BOOL)
|
||||||
{
|
{
|
||||||
@ -97,7 +99,7 @@ namespace HTCoreServiceApp.WebApi
|
|||||||
var iFloatPlaces = (int)metaTags.Where(x => x.TagName == tagName && x.GroupId == groupID).First().IFloatPlaces;
|
var iFloatPlaces = (int)metaTags.Where(x => x.TagName == tagName && x.GroupId == groupID).First().IFloatPlaces;
|
||||||
value = ((int)(float.Parse(value) * (int)Math.Pow(10.0f, iFloatPlaces))).ToString();
|
value = ((int)(float.Parse(value) * (int)Math.Pow(10.0f, iFloatPlaces))).ToString();
|
||||||
}
|
}
|
||||||
var writePara = new
|
var writePara = new WritePara
|
||||||
{
|
{
|
||||||
TagName = tagName,
|
TagName = tagName,
|
||||||
GroupName = groupName,
|
GroupName = groupName,
|
||||||
@ -105,14 +107,17 @@ namespace HTCoreServiceApp.WebApi
|
|||||||
DataType = dataType,
|
DataType = dataType,
|
||||||
Value = value
|
Value = value
|
||||||
};
|
};
|
||||||
string serJson = JsonConvert.SerializeObject(writePara);
|
//string serJson = JsonSerializer.Serialize(writePara); //JsonConvert.SerializeObject(writePara);
|
||||||
|
|
||||||
|
//var t2 = DateTime.Now;
|
||||||
|
//var timediff = t2 - t1;
|
||||||
|
//Console.WriteLine($"写入参数初始化耗时:{timediff}");
|
||||||
|
|
||||||
foreach (var driverThread in _driverService.DriverThreads)
|
foreach (var driverThread in _driverService.DriverThreads)
|
||||||
{
|
{
|
||||||
if (driverThread.driverName == driverName)
|
if (driverThread.driverName == driverName)
|
||||||
{
|
{
|
||||||
reCode = driverThread.DriverWrite(serJson);
|
reCode = driverThread.DriverWrite(writePara);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,7 +129,9 @@ namespace HTCoreServiceApp.WebApi
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
reCode = 1;
|
reCode = 1;
|
||||||
|
GC.Collect();
|
||||||
}
|
}
|
||||||
|
GC.Collect();
|
||||||
return reCode.ToString();
|
return reCode.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,4 +22,8 @@ namespace HTCoreServiceApp.WebApi
|
|||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//public record WritePara(string TagName, string GroupName, string WriteAddress, byte DataType, string Value)
|
||||||
|
//{
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"Type": "SqlServer",
|
"Type": "SqlServer",
|
||||||
"SqlServer": "Zk48ARnbLq1Lk+lzxvCij/8Pt/tnmDwn+rE3IgYGjblF9G4nGtc0SdFjHwyesdp8uVH2ffnIhBBhZ4UAb8vy3t7LPWJUEb12fVMorU1o2h9vdd+2yPnv3Y7J4FI0mIFUtw6Pb2l37+KmJdGCN2JX/lQvZvJ3YxGt5OCJPbEH/R2XrtZoLtZ5dj/EEVhGxtrt/v65G8u14+Hsa6LpnchUmw=="
|
"SqlServer": "Zk48ARnbLq1Lk+lzxvCij/8Pt/tnmDwn+rE3IgYGjbm+C8BGXKBFaf7hraUiRoNfatF6eAiz2tK7uKmJVdp0NSLHsd5WiUB9dZ05VUn7ddOJqlxnIdmCERpNOuWW6zTH5gzFjvz0gHp2YRMwvwfeavVIuwxq1D1UYL9poZrBy9k9LIERYOVAfeYdaZb6AzQKFNz+6yOszCxvEhQOuQcBMw=="
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
|
Reference in New Issue
Block a user