110,825
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
[Obsolete]
public void Execute(IJobExecutionContext context)
{
try
{
system_dateTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
//初始化设备列表
InitSubDeviceList();
//存储日志
List<RunLogEntity> _runLogList = new List<RunLogEntity>();
//按照 采集站IP、采集站Port 进行分组,读取4G模块数据
var _group = treeSubDeviceList.GroupBy(a => new { a.StationIP, a.StationPort });
foreach (var _ in _group)
{
StationGroupDto groupDto = new StationGroupDto()
{
StationIP = _.Key.StationIP,
StationPort = _.Key.StationPort,
DeviceList = _.ToList()
};
ReadSPM33Data_Gai(groupDto, out List<RunLogEntity> runLogList);
_runLogList.AddRange(runLogList);
}
//运行日志入库
if (_runLogList.Count() > 0)
{
runLogService.InsertRunLogList(_runLogList);
}
}
catch (Exception ex)
{
//新增运行日志异常信息
RunLogEntity runLogEntity = new RunLogEntity()
{
ID = Guid.NewGuid(),
LogTime = DateTime.Now,
LogCategory = (int)LogCategoryEnum.数据采集日志,
LogContent = "派诺SPM33计量仪表启动失败," + ex.Message,
RunState = (int)ProgramStateEnum.采数程序异常
};
runLogService.InsertRunLog(runLogEntity);
}
}
[Obsolete]
[Obsolete]
public void ReadSPM33Data_Gai(StationGroupDto groupDto, out List<RunLogEntity> runLogList_)
{
List<RunLogEntity> runLogList = new List<RunLogEntity>();
List<PointData> points = new List<PointData>();
try
{
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(groupDto.StationIP, groupDto.StationPort);
ModbusSerialMaster master = ModbusSerialMaster.CreateRtu(tcpClient);
//设置读取超时时间
master.Transport.ReadTimeout = 2000;
master.Transport.Retries = 1;
master.Transport.WaitToRetryMilliseconds = 150;
if (tcpClient.Connected)
{
foreach (var deviceInfo in groupDto.DeviceList)
{
if (deviceInfo.PointList.Count() > 0)
{
try
{
var data_List = master.ReadHoldingRegisters(Convert.ToByte(deviceInfo.SlaveID), Convert.ToUInt16(0), Convert.ToUInt16(40));
foreach (var item in deviceInfo.PointList)
{
double Value = 0;
if (item.DataType == (int)DataTypeEnum.二进制16位)
{
int index = Convert.ToInt32(item.Address);
Value = handleDataType(item.DataBit, data_List[index]);
}
else
{
if (item.IsHighLowBit)
{
int index = Convert.ToInt32(item.Address);
Value = CommonHelper.DealWidthLowHighHex_unSigned(data_List[index + 1], data_List[index]) * item.Multiple * item.Ratio;
}
else
{
int index = Convert.ToInt32(item.Address);
Value = data_List[index] * item.Multiple * item.Ratio;
}
}
var point = PointData
.Measurement(deviceInfo.ParentCode)
.Tag("PointTag", item.PointTag.ToString())
.Tag("PointID", item.ID.ToString())
.Field("Value", Math.Round(Value, 4))
.Timestamp(TimeZoneInfo.ConvertTimeToUtc(system_dateTime), WritePrecision.Ns);
points.Add(point);
//验证数据是否报警
alarmRecordService.VerifyAlarm(deviceInfo, item, thresholdList, Value);
}
//通讯正常
var entity = breakEventService.WriteCommunicateEvent(deviceInfo, null, 1, deviceInfo.PointList.Count().ToString());
runLogList.Add(entity);
}
catch (Exception ex)
{
// 通讯异常
var entity = breakEventService.WriteCommunicateEvent(deviceInfo, null, 2, ex.Message);
runLogList.Add(entity);
}
//线程休眠
Thread.Sleep(1);
}
}
}
else
{
// tcp/ip 连接失败
var entity = breakEventService.WriteCommunicateEvent(null, groupDto, 3, "请检查网络通讯环境!");
runLogList.Add(entity);
}
//释放寄存器资源
master.Dispose();
//释放tcp握手资源
tcpClient.Close();
//线程休眠
Thread.Sleep(1);
//运行日志推出
runLogList_ = runLogList;
//往influxdb写入数据
if (points.Count > 0)
{
helper.WriteData(points);
}
}
catch (Exception ex)
{
//新增运行日志异常信息
RunLogEntity runLogEntity = new RunLogEntity()
{
ID = Guid.NewGuid(),
LogTime = DateTime.Now,
LogCategory = (int)LogCategoryEnum.数据采集日志,
LogContent = "派诺SPM33计量仪表设备数据采集失败," + ex.Message,
RunState = (int)ProgramStateEnum.采数程序异常
};
runLogService.InsertRunLog(runLogEntity);
//运行日志推出
runLogList_ = new List<RunLogEntity>();
}
}
优质好文,博主的文章细节很到位,兼顾实用性和可操作性,感谢博主的分享,文章思路清晰,图文并茂,详略得当,三连支持,期待博主持续输出好文!