You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.9 KiB
C#
113 lines
3.9 KiB
C#
using GuideScreen.Common.Common;
|
|
using GuideScreen.Common.Constants;
|
|
using GuideScreen.Common.Repositories;
|
|
using GuideScreen.Common.Repositories.Entities;
|
|
using GuideScreen.Common.Services;
|
|
using GuideScreen.Common.Services.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GuideScreen.Common.Services.Impl
|
|
{
|
|
/// <summary>
|
|
/// PLC点位服务 实现
|
|
/// </summary>
|
|
internal class PLCPointService : IPLCPointService
|
|
{
|
|
private IPLCPointRepository plcPointRepository;
|
|
private IPLCMonitorService plcMonitorService;
|
|
|
|
|
|
public PLCPointService(IPLCPointRepository plcPointRepository, IPLCMonitorService pLCMonitorService)
|
|
{
|
|
this.plcPointRepository = plcPointRepository;
|
|
this.plcMonitorService = pLCMonitorService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取 PLC 点位 列表
|
|
/// </summary>
|
|
/// <param name="note"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <param name="pageIndex"></param>
|
|
/// <returns></returns>
|
|
public PageModel<List<PLCPointModel>> GetPLCPointList(string deviceName, string note, int pageSize, int pageIndex)
|
|
{
|
|
var pageModel = plcPointRepository.GetPLCPointList(deviceName, note, pageSize, pageIndex);
|
|
if (pageModel.Content != null && plcMonitorService.IsRun)
|
|
{
|
|
foreach (var model in pageModel.Content)
|
|
{
|
|
model.PointValue = plcMonitorService.ReadValue(model.PointAddress, Type.GetType(model.PointDataType))?.ToString();
|
|
}
|
|
}
|
|
return pageModel;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取 控制器时间参数显示及设置 列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<PLCPointModel> GetControllerTimeParametersList()
|
|
{
|
|
var list = plcPointRepository.GetPLCPointList(PLCDeviceNames.SetControllerTimeParameters, "", 0, 0);
|
|
var points = plcMonitorService.Points;
|
|
if (points != null && points.Count > 0)
|
|
{
|
|
foreach (var c in list.Content)
|
|
{
|
|
var point = points.Where(f => f.Address == c.PointAddress).FirstOrDefault();
|
|
if (point != null)
|
|
{
|
|
c.PointValue = point.ObjectValue?.ToString();
|
|
}
|
|
}
|
|
}
|
|
return list.Content;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取设备名称
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<string> GetDeviceNames()
|
|
{
|
|
var list = plcPointRepository.GetDeviceNames();
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取PLC点位明细
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public PLCPointModel GetPLCPointDetail(int id)
|
|
{
|
|
var entity = plcPointRepository.GetPLCPointDetail(id);
|
|
var model = ModelTools.PubClone<PLCPointEntity, PLCPointModel>.Trans(entity);
|
|
if (model != null && plcMonitorService.IsRun)
|
|
{
|
|
model.PointValue = plcMonitorService.ReadValue(model.PointAddress, Type.GetType(model.PointDataType))?.ToString();
|
|
}
|
|
return model;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新PLC点位信息
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
public void UpdatePLCPoint(PLCPointModel model)
|
|
{
|
|
var entity = ModelTools.PubClone<PLCPointModel, PLCPointEntity>.Trans(model);
|
|
plcPointRepository.UpdatePLCPoint(entity);
|
|
if (model != null && plcMonitorService.IsRun)
|
|
{
|
|
model.PointValue = plcMonitorService.WriteValue(model.PointAddress, Type.GetType(model.PointDataType), model.PointValue)?.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|