|
|
using HighWayIot.Plc;
|
|
|
using HighWayIot.Plc.PlcHelper;
|
|
|
using HighWayIot.Repository.domain;
|
|
|
using HighWayIot.Repository.service;
|
|
|
using HighWayIot.Winform.UserControlPages;
|
|
|
using HslCommunication.Profinet.Keyence;
|
|
|
using Models;
|
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace HighWayIot.Winform.Business
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 报表数据刷新业务类
|
|
|
/// </summary>
|
|
|
public class MonitorDataRefreshBusiness
|
|
|
{
|
|
|
TransferSingal transferSingal = new TransferSingal();
|
|
|
|
|
|
private Timer refreshTimer;
|
|
|
|
|
|
public MonitorDataRefreshBusiness()
|
|
|
{
|
|
|
// 启动定时器,每隔1秒刷新一次报表数据
|
|
|
refreshTimer = new System.Threading.Timer(RefreshData, null, 0, 1000);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 数据刷新
|
|
|
/// </summary>
|
|
|
/// <param name="o"></param>
|
|
|
private void RefreshData(object o)
|
|
|
{
|
|
|
byte[] signals = transferSingal.ReadStationReportSignal();
|
|
|
if (signals == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//解析返回的信号数据
|
|
|
ushort[] rgvNo = new ushort[7];
|
|
|
ushort[] rgvState = new ushort[7];
|
|
|
float[] weights = new float[4];
|
|
|
|
|
|
for (int i = 0; i < 7; i++)
|
|
|
{
|
|
|
rgvNo[i] = BitConverter.ToUInt16(signals, i * 2);
|
|
|
rgvState[i] = BitConverter.ToUInt16(signals, (i * 2) + 20);
|
|
|
if (i > 2)
|
|
|
{
|
|
|
weights[i - 3] = BitConverter.ToSingle(signals, ((i - 3) * 4) + 40);
|
|
|
}
|
|
|
}
|
|
|
//装圈工位
|
|
|
if (rgvState[0] == 1)
|
|
|
{
|
|
|
// 监控画面信息插入
|
|
|
MonitorInsert(RecipeSendBusiness.NowRecipeCode, RecipeSendBusiness.NowDeviceNo, rgvNo[0]);
|
|
|
MonitorMainPage.MonitorRefreshAction.Invoke();
|
|
|
transferSingal.WriteStationReportSignal(1); // 复位信号
|
|
|
}
|
|
|
//基部胶
|
|
|
if (rgvState[1] == 1)
|
|
|
{
|
|
|
ZxDailyReportEntity entity = ZxDailyReportService.Instance.GetNearData(rgvNo[1]);
|
|
|
if (entity == null)
|
|
|
{
|
|
|
goto n1;
|
|
|
}
|
|
|
entity.BaseEndTime = DateTime.Now;
|
|
|
ZxDailyReportService.Instance.UpdateDailyReportInfo(entity);
|
|
|
MonitorMainPage.MonitorRefreshAction.Invoke();
|
|
|
transferSingal.WriteStationReportSignal(2); // 复位信号
|
|
|
}
|
|
|
n1:
|
|
|
|
|
|
//中层胶
|
|
|
if (rgvState[2] == 1)
|
|
|
{
|
|
|
ZxDailyReportEntity entity = ZxDailyReportService.Instance.GetNearData(rgvNo[2]);
|
|
|
if(entity == null)
|
|
|
{
|
|
|
goto n2;
|
|
|
}
|
|
|
entity.MidEndTime = DateTime.Now;
|
|
|
ZxDailyReportService.Instance.UpdateDailyReportInfo(entity);
|
|
|
MonitorMainPage.MonitorRefreshAction.Invoke();
|
|
|
transferSingal.WriteStationReportSignal(3); // 复位信号
|
|
|
}
|
|
|
n2:
|
|
|
|
|
|
//胎面胶
|
|
|
for (int i = 3; i <= 5; i++)
|
|
|
{
|
|
|
if (rgvState[i] == 1)
|
|
|
{
|
|
|
// 监控画面信息插入
|
|
|
ZxDailyReportEntity entity = ZxDailyReportService.Instance.GetNearData(rgvNo[i]);
|
|
|
if (entity == null)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
entity.BaseEndTime = DateTime.Now;
|
|
|
entity.RawTireWeight = (int)weights[i - 3];
|
|
|
ZxDailyReportService.Instance.UpdateDailyReportInfo(entity);
|
|
|
MonitorMainPage.MonitorRefreshAction.Invoke();
|
|
|
transferSingal.WriteStationReportSignal(i + 1); // 复位信号
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//结束
|
|
|
if (rgvState[6] == 1)
|
|
|
{
|
|
|
ZxDailyReportEntity entity = ZxDailyReportService.Instance.GetNearData(rgvNo[6]);
|
|
|
entity.RepeatWeight = (int)weights[3];
|
|
|
entity.IsDone = 1;
|
|
|
ZxDailyReportService.Instance.UpdateDailyReportInfo(entity);
|
|
|
MonitorMainPage.MonitorRefreshAction.Invoke();
|
|
|
transferSingal.WriteStationReportSignal(7); // 复位信号
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 监控画面信息插入
|
|
|
/// </summary>
|
|
|
/// <param name="deviceNo">机台号</param>
|
|
|
/// <param name="recipeCode">硫化机台编号</param>
|
|
|
/// <param name="rgvNo">RGV编号</param>
|
|
|
public void MonitorInsert(string recipeCode, string deviceNo, int rgvNo)
|
|
|
{
|
|
|
ZxRecipeEntity recipeEntity = ZxRecipeService.Instance.GetRecipeInfosByRecipeCode(recipeCode).FirstOrDefault();
|
|
|
if (recipeEntity == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
ZxDailyReportEntity entity = new ZxDailyReportEntity()
|
|
|
{
|
|
|
Uuid = Guid.NewGuid().ToString("N"),
|
|
|
VulcanizationNo = deviceNo,
|
|
|
StartTime = DateTime.Now,
|
|
|
RecipeName = recipeEntity.RecipeName,
|
|
|
RecipeCode = recipeEntity.RecipeCode,
|
|
|
SpecCode = recipeEntity.RecipeSpecCode,
|
|
|
DeviceNo = rgvNo,
|
|
|
RawTireWeight = (int)ZxRecipeParaService.Instance.GetRecipeParaInfoByRecipeCode(recipeCode).FirstOrDefault()?.TireWeight,
|
|
|
IsDone = 0
|
|
|
};
|
|
|
|
|
|
ZxDailyReportService.Instance.InsertDailyReportInfo(entity);
|
|
|
}
|
|
|
}
|
|
|
}
|