change - 设备初始化逻辑修改

master
WenJY 2 weeks ago
parent 54151e8536
commit a59bac4ccc

@ -68,22 +68,22 @@ public class DeviceCollectionBusiness
{ {
try try
{ {
_serilog.Info($"开始采集{item.deviceName}"); _serilog.Info($"开始采集{item.deviceName};参数:{JsonConvert.SerializeObject(item.deviceParams)}");
var opcItemValues = await this.ReadParam(item, opcua); var opcItemValues = await this.ReadParam(item, opcua);
this.SaveParam(item, opcItemValues, out List<BaseDeviceParamVal> paramValues); this.SaveParam(item, opcItemValues, out List<BaseDeviceParamVal> paramValues);
_serilog.Info($"{item.deviceName}数据采集完成:{JsonConvert.SerializeObject(opcItemValues)}"); _serilog.Info($"{item.deviceName}数据采集完成:{JsonConvert.SerializeObject(opcItemValues)}");
if(i == 10) // if(i == 10)
{ // {
//
isFlag = false; // isFlag = false;
//
opcua.DisconnectAsync().Wait(); // opcua.DisconnectAsync().Wait();
//
_serilog.Info($"读取完成断开连接"); // _serilog.Info($"读取完成断开连接");
} // }
} }
catch (Exception e) catch (Exception e)
@ -213,7 +213,16 @@ public class DeviceCollectionBusiness
paramValues.Add(deviceParamVal); paramValues.Add(deviceParamVal);
} }
_paramValService.Insert(paramValues);
var isRes = _paramValService.Insert(paramValues);
if (isRes)
{
_serilog.Info(($"{device.deviceName} 设备参数保存成功"));
}
else
{
_serilog.Info(($"{device.deviceName} 设备参数保存失败"));
}
}catch (Exception e) }catch (Exception e)
{ {
throw new InvalidOperationException($"设备参数保存异常:{e.Message}"); throw new InvalidOperationException($"设备参数保存异常:{e.Message}");

@ -12,10 +12,10 @@ namespace Sln.Imm.Daemon.Model.dao;
public class BaseDeviceParamVal public class BaseDeviceParamVal
{ {
/// <summary> /// <summary>
/// 备 注:主键 /// 备 注:主键 PARAMRECORD_SEQ_ID
///</summary> ///</summary>
[SugarColumn(ColumnName = "RECORD_ID", IsPrimaryKey = true)] [SugarColumn(ColumnName = "RECORD_ID", OracleSequenceName = "PARAMRECORD_SEQ_ID",IsPrimaryKey = true)]
public decimal objId { get; set; } public int objId { get; set; }
/// <summary> /// <summary>
/// 备 注:参数编号 /// 备 注:参数编号
@ -33,7 +33,7 @@ public class BaseDeviceParamVal
/// 备 注:设备ID /// 备 注:设备ID
///</summary> ///</summary>
[SugarColumn(ColumnName = "DEVICE_ID")] [SugarColumn(ColumnName = "DEVICE_ID")]
public decimal? deviceId { get; set; } public int deviceId { get; set; }
/// <summary> /// <summary>
/// 备 注:参数名称 /// 备 注:参数名称

@ -41,16 +41,24 @@ namespace Sln.Imm.Daemon.Opc
if (opcDev != null) if (opcDev != null)
{ {
var res = opcDev.ConnectAsync(item.networkAddress).Result; try
if (!res)
{ {
Console.WriteLine($"{item.deviceName}设备连接失败"); var res = opcDev.ConnectAsync(item.networkAddress).Result;
if (!res)
{
Console.WriteLine($"{item.deviceName}设备连接失败");
}
else
{
Console.WriteLine($"{item.deviceName}设备连接成功");
opcs.Add(item, opcDev);
}
} }
else catch (Exception ex)
{ {
opcs.Add(item, opcDev); Console.WriteLine($"{item.deviceName}设备连接异常:{ex.Message}");
} }
} }
} }

Loading…
Cancel
Save