333 lines
15 KiB
C#
333 lines
15 KiB
C#
using JinYuan.CommunicationLib.Enum;
|
|
using JinYuan.DataConvertLib;
|
|
using JinYuan.Helper;
|
|
using JinYuan.MES.Enums;
|
|
using JinYuan.MES.Models;
|
|
using JinYuan.Models;
|
|
using JinYuan.VirtualDataLibrary;
|
|
using PLCCommunication;
|
|
using PLCCommunication.Language;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace JinYuan.ControlCenters
|
|
{
|
|
public partial class ControlCenter
|
|
{
|
|
#region 刷新12小时产能
|
|
public void Refresh12HourProdQty()
|
|
{
|
|
List<Chart12HourData> chart12Hours = new List<Chart12HourData>();
|
|
int j = 0;
|
|
int m = 0;
|
|
int n = 0;
|
|
DateTime dtTime = DateTime.Now;
|
|
string strDate = dtTime.ToString("yyyy-MM-dd");
|
|
int Hour = GetHour();
|
|
var listTotal = CommonMethods.db.QueryWhereList<Hourprod>(t => t.FDate == strDate);// 查询稼动率表中total数据
|
|
if (listTotal != null && listTotal.Count > 0)
|
|
{
|
|
for (int i = 1; i < 13; i++)
|
|
{
|
|
#region X轴数据
|
|
|
|
if (CommonMethods.strClass != "白班")
|
|
{
|
|
j = i + 21;
|
|
|
|
if (j >= 25 && j < 26)
|
|
{
|
|
m = j - 2;
|
|
n = j - 25;
|
|
}
|
|
else if (j >= 26)
|
|
{
|
|
m = j - 26;
|
|
n = j - 25;
|
|
}
|
|
else
|
|
{
|
|
m = j - 2;
|
|
n = j - 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
j = i + 9;
|
|
m = j - 2;
|
|
n = j - 1;
|
|
}
|
|
#endregion
|
|
|
|
int Fhour = Convert.ToInt32(m);
|
|
var hour1 = listTotal.Where(p => p.FHour == Fhour).FirstOrDefault();
|
|
int ProdALLQty = 0;
|
|
int ProdOKQty = 0;
|
|
int ProdNGQty = 0;
|
|
string strOkRatio = "0.00";
|
|
|
|
if (hour1 != null)
|
|
{
|
|
ProdALLQty += hour1.ProdIn;
|
|
ProdOKQty += hour1.ProdOut;
|
|
}
|
|
|
|
ProdNGQty = ProdALLQty - ProdOKQty;
|
|
if (ProdOKQty >= 0 && ProdALLQty > 0)
|
|
{
|
|
strOkRatio = (Math.Round(decimal.Parse(ProdOKQty.ToString()) / decimal.Parse(ProdALLQty.ToString()), 4)).ToString();
|
|
}
|
|
else
|
|
{
|
|
strOkRatio = "0.00";
|
|
}
|
|
|
|
chart12Hours.Add(new Chart12HourData()
|
|
{
|
|
DisplayTime = m + ":30~" + (n) + ":30",
|
|
ProdIn = ProdALLQty,
|
|
ProdOut = ProdOKQty,
|
|
ProdNg = ProdNGQty,
|
|
OKRatio = strOkRatio
|
|
});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 1; i < 13; i++)
|
|
{
|
|
#region X轴数据
|
|
|
|
if (CommonMethods.strClass != "白班")
|
|
{
|
|
j = i + 21;
|
|
|
|
if (j >= 25 && j < 26)
|
|
{
|
|
m = j - 2;
|
|
n = j - 25;
|
|
}
|
|
else if (j >= 26)
|
|
{
|
|
m = j - 26;
|
|
n = j - 25;
|
|
}
|
|
else
|
|
{
|
|
m = j - 2;
|
|
n = j - 1;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
j = i + 9;
|
|
m = j - 2;
|
|
n = j - 1;
|
|
}
|
|
#endregion
|
|
|
|
Random rand = new Random();
|
|
int ranOK = rand.Next(1000, 3000);
|
|
int ranNG = rand.Next(400, 1200);
|
|
int total = ranOK + ranNG;
|
|
|
|
chart12Hours.Add(new Chart12HourData()
|
|
{
|
|
DisplayTime = m + ":30~" + n + ":30",
|
|
ProdIn = ranOK + ranNG,
|
|
ProdOut = ranOK,
|
|
ProdNg = ranNG,
|
|
OKRatio = (Math.Round(decimal.Parse(ranOK.ToString()) / decimal.Parse(total.ToString()) * 0.01m, 2) * 100).ToString()
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
|
|
if (chart12Hours != null)
|
|
{
|
|
CommonMethods.Lst_Prod12HourData = chart12Hours;
|
|
}
|
|
}
|
|
|
|
|
|
public int GetHour()
|
|
{
|
|
DateTime now = DateTime.Now;
|
|
int nowHour = Convert.ToInt32($"{now.Hour}30");
|
|
int hour = 0;
|
|
if (CommonMethods.LastHour != nowHour)
|
|
{
|
|
hour = Convert.ToInt32($"{now.Hour - 1}30");
|
|
if (now.Hour == 0)
|
|
{
|
|
hour = 2330;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
hour = Convert.ToInt32($"{now.Hour}30");
|
|
}
|
|
return hour;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region 检测项不良
|
|
/// <summary>
|
|
/// 读取检测项不良
|
|
/// </summary>
|
|
private void GetDefectTypeQty()
|
|
{
|
|
|
|
try
|
|
{
|
|
if (CommonMethods.Lst_DefectTypeQty.Count <= 0)
|
|
{
|
|
|
|
CommonMethods.Lst_DefectTypeQty.Add(new ChartDataType { DataType = "极性检测不良", DataCount = 0 });
|
|
CommonMethods.Lst_DefectTypeQty.Add(new ChartDataType { DataType = "称重不良", DataCount = 0 });
|
|
CommonMethods.Lst_DefectTypeQty.Add(new ChartDataType { DataType = "铜极耳剪切不良", DataCount = 0 });
|
|
CommonMethods.Lst_DefectTypeQty.Add(new ChartDataType { DataType = "铝极耳剪切不良", DataCount = 0 });
|
|
//CommonMethods.Lst_DefectTypeQty.Add(new ChartDataType { DataType = "厚度不良", DataCount = 0 });
|
|
//CommonMethods.Lst_DefectTypeQty.Add(new ChartDataType { DataType = "焊前CCD正极耳顶面不良", DataCount = 0 });
|
|
}
|
|
else //读取PLC数据
|
|
{
|
|
if (CommonMethods.plcDevice != null && CommonMethods.plcDevice.IsConnected)
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
int ProdDRFIDNgQty = CommonMethods.PlcLink.ReadInt16("D1000");//极性不良
|
|
int ProdDXNgQty = CommonMethods.PlcLink.ReadInt16("D1002");//称重不良
|
|
int ProdGRFIDNgQty = CommonMethods.PlcLink.ReadInt16("D1006");//测厚压力值1不良
|
|
int ProdYLZNgQty = CommonMethods.PlcLink.ReadInt16("D1004");//测厚压力值2不良
|
|
|
|
//從PLC讀取數據賦值給到NGList
|
|
CommonMethods.Lst_DefectTypeQty.Where(p => p.DataType == "极性检测不良").FirstOrDefault().DataCount = ProdDRFIDNgQty;
|
|
CommonMethods.Lst_DefectTypeQty.Where(p => p.DataType == "称重不良").FirstOrDefault().DataCount = ProdDXNgQty;
|
|
CommonMethods.Lst_DefectTypeQty.Where(p => p.DataType == "铜极耳剪切不良").FirstOrDefault().DataCount = ProdGRFIDNgQty;
|
|
CommonMethods.Lst_DefectTypeQty.Where(p => p.DataType == "铝极耳剪切不良").FirstOrDefault().DataCount = ProdYLZNgQty;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Instance.WriteEX(ex);
|
|
}
|
|
});
|
|
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Instance.WriteEX(ex);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 智能电表 ---默认D1100开始
|
|
public void GetEnergyData()
|
|
{
|
|
if (CommonMethods.plcDevice != null && CommonMethods.plcDevice.IsConnected)
|
|
{
|
|
|
|
List<ElectricEnergy> listM = new List<ElectricEnergy>();
|
|
JYResult<byte[]> resByte = CommonMethods.PlcLink.ReadValue<JYResult<byte[]>>("D1100", Data_Type.ArrByte, 60);
|
|
|
|
if (resByte.IsSuccess && resByte.Content.Length > 108)
|
|
{
|
|
ElectricEnergy m = new ElectricEnergy();
|
|
m.AccumulatedElectricity = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 0)); //有功电能(累计电能)D1100
|
|
m.PhaseVoltageA = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 4)); //A相电压 D1102
|
|
m.PhaseVoltageB = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 8));//B相电压 D1104
|
|
m.PhaseVoltageC = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 12));//C相电压 D1106
|
|
m.PhaseCurrentA = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 16)); //电流IA D1108
|
|
m.PhaseCurrentB = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 20));//电流IB D1110
|
|
m.PhaseCurrentC = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 24));//电流IC D1112
|
|
m.PhasePowerA = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 28)); //A相有功功率 D1114
|
|
m.PhasePowerB = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 32)); //B相有功功率 D1116
|
|
m.PhasePowerC = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 36));//C相有功功率 D1118
|
|
m.ActivePower = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 40)); //总有功功率 D1120
|
|
m.PowerFactor = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 44)); //总功率因数 D1122
|
|
m.pt = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 48)); //电压变比 D1124
|
|
m.ct = Convert.ToDecimal(FloatLib.GetFloatFromByteArray(resByte.Content, 52)); //电流变比 D1126
|
|
listM.Add(m);
|
|
CommonMethods.listElectricEnergy = listM;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 能耗上传MES
|
|
/// </summary>
|
|
public void UploadEquEnergy()
|
|
{
|
|
if (CommonMethods.listElectricEnergy.Count > 0)
|
|
{
|
|
if (CommonMethods.mesConfig.isUpMes)
|
|
{
|
|
string msg = string.Empty;
|
|
DateTime nowDate = DateTime.Now;
|
|
string filePath = string.Empty;
|
|
string fileName = string.Empty;
|
|
string fileTitle = string.Empty;
|
|
string fileContent = string.Empty;
|
|
List<WattrMeter> listP = new List<WattrMeter>();
|
|
int i = 0;
|
|
foreach (ElectricEnergy m in CommonMethods.listElectricEnergy)
|
|
{
|
|
WattrMeter param = new WattrMeter();
|
|
param.siteCode = CommonMethods.mesConfig.siteCode;
|
|
param.lineCode = CommonMethods.mesConfig.lineCode;
|
|
param.equipNum = CommonMethods.mesConfig.equipNum;
|
|
param.userName = CommonMethods.mesConfig.mesUserName;
|
|
param.electricMeterNum = CommonMethods.mesConfig.electricMeterNum[i];
|
|
param.recordDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss");
|
|
param.accumulatedElectricity = (decimal)m.AccumulatedElectricity;
|
|
param.phaseVoltageA = (decimal)m.PhaseVoltageA;
|
|
param.phaseVoltageB = (decimal)m.PhaseVoltageB;
|
|
param.phaseVoltageC = (decimal)m.PhaseVoltageC;
|
|
param.phaseCurrentA = (decimal)m.PhaseCurrentA;
|
|
param.phaseCurrentB = (decimal)m.PhaseCurrentB;
|
|
param.phaseCurrentC = (decimal)m.PhaseCurrentC;
|
|
param.phasePowerA = (decimal)m.PhasePowerA;
|
|
param.phasePowerB = (decimal)m.PhasePowerB;
|
|
param.phasePowerC = (decimal)m.PhasePowerC;
|
|
param.activePower = (decimal)m.ActivePower;
|
|
param.powerFactor = (decimal)m.PowerFactor;
|
|
param.pt = (decimal)m.pt;
|
|
param.ct = (decimal)m.ct;
|
|
|
|
listP.Add(param);
|
|
i++;
|
|
|
|
// 写csv文件
|
|
string productName = string.Empty;
|
|
|
|
filePath = $@"{CommonMethods.strWattrMeterpath}\{nowDate.Year}\{nowDate.Month}";
|
|
fileName = $@"{nowDate.Day}.csv";
|
|
fileTitle = "工序名称,生产机台编号,拉线,型号,物料编号,操作人员,班次,电表编号,采集时间,有功电能(累计电能)KwH,A相电压 V,B相电压 V,C相电压 V,A相电流 A,B相电流 A,C相电流 A,A相功率 Kw,B相功率 Kw,C相功率 Kw,总有功功率 Kw,总功率因数 %,电压变比,电流变比";
|
|
fileContent = $"入壳A工序,{CommonMethods.mesConfig.equipNum},{CommonMethods.mesConfig.lineCode},{productName},{CommonMethods.mesConfig.MaterialCode},{CommonMethods.mesConfig.mesUserName},{CommonMethods.strClass},{param.electricMeterNum},{nowDate.ToString("yyyy-MM-dd HH:mm:ss")}," +
|
|
$"{param.accumulatedElectricity},{param.phaseVoltageA},{param.phaseVoltageB},{param.phaseVoltageC},{param.phaseCurrentA},{param.phaseCurrentB},{param.phaseCurrentC}," +
|
|
$"{param.phasePowerA},{param.phasePowerB},{param.phasePowerC},{param.activePower},{param.powerFactor},{param.pt},{param.ct}";
|
|
CSVHelper<object>.WriterCSV(filePath, fileName, fileTitle, fileContent);
|
|
}
|
|
//上传MES
|
|
string Mesage = "";
|
|
bool b = CommonMethods.hbgMes.UploadEquEnergy(CommonMethods.mesConfig.WattrMeterUrl, CommonMethods.mesConfig.equipNum, CommonMethods.mesConfig.siteCode, CommonMethods.mesConfig.lineCode,
|
|
CommonMethods.mesConfig.mesUserName, CommonMethods.mesConfig.electricMeterNum, listP, ref Mesage);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|