|
|
|
@ -24,7 +24,6 @@ using System.Linq;
|
|
|
|
|
using Aucma.Core.Scanner;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using NPOI.HSSF.Record;
|
|
|
|
|
using Aucma.Core.PLc;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
|
|
|
using Admin.Core.Model.ViewModels;
|
|
|
|
@ -34,6 +33,8 @@ using Brushes = System.Windows.Media.Brushes;
|
|
|
|
|
using Admin.Core.Model.Model_New;
|
|
|
|
|
using Microsoft.IdentityModel.Logging;
|
|
|
|
|
using static Npgsql.Replication.PgOutput.Messages.RelationMessage;
|
|
|
|
|
using Aucma.Core.HwPLc;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
/*
|
|
|
|
|
* 首页信息
|
|
|
|
|
*/
|
|
|
|
@ -69,19 +70,19 @@ namespace Aucma.Core.CodeBinding.ViewModels
|
|
|
|
|
MvCodeHelper.ReceiveCode1Event += receiveCode1;
|
|
|
|
|
MvCodeHelper.ReceiveCode2Event += receiveCode2;
|
|
|
|
|
LoadData();
|
|
|
|
|
|
|
|
|
|
add();
|
|
|
|
|
//实时绑定条码和实时下发plc放行信号
|
|
|
|
|
realBindingAndSendPlc();
|
|
|
|
|
|
|
|
|
|
//Task.Run(() =>
|
|
|
|
|
//{
|
|
|
|
|
// Thread.Sleep(5000);
|
|
|
|
|
// receiveCode1("L23000000899");
|
|
|
|
|
// Thread.Sleep(2000);
|
|
|
|
|
// receiveCode2("B23000000824");
|
|
|
|
|
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(3000);
|
|
|
|
|
receiveCode1("B24010181060282920002");
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
receiveCode2("16160030000000910780");
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
@ -119,29 +120,42 @@ namespace Aucma.Core.CodeBinding.ViewModels
|
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 实时下发plc放行信号
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
CodeBindingRecord record = _codeBindingRecordServices.FirstAsync(x => x.isPlcPass == 1 && x.RecordTime2 >= System.DateTime.Now.AddDays(-1)).Result;
|
|
|
|
|
if (record != null)
|
|
|
|
|
Thread.Sleep(3000);
|
|
|
|
|
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc"));
|
|
|
|
|
if (obj != null && obj.plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
// 下发plc放行信号
|
|
|
|
|
if (SendPlcPass())
|
|
|
|
|
CodeBindingRecord record = _codeBindingRecordServices.FirstAsync(x => x.isPlcPass == 1 && x.RecordTime2 >= System.DateTime.Now.AddDays(-1)).Result;
|
|
|
|
|
if (record != null)
|
|
|
|
|
{
|
|
|
|
|
record.isPlcPass = 2;
|
|
|
|
|
_ = _codeBindingRecordServices.UpdateAsync(record).Result;
|
|
|
|
|
// 下发plc放行信号
|
|
|
|
|
RefreshAndWriteLog($"条码[{record.BoxCode}]下发plc放行信号,等待plc反馈...");
|
|
|
|
|
if (SendPlcPass(obj))
|
|
|
|
|
{
|
|
|
|
|
RefreshAndWriteLog($"条码[{record.BoxCode}]放行成功");
|
|
|
|
|
record.isPlcPass = 2;
|
|
|
|
|
_ = _codeBindingRecordServices.UpdateAsync(record).Result;
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RefreshAndWriteLog("等待Plc反馈信号5秒超时!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error(ex.ToString());
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error(ex.ToString());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -153,13 +167,15 @@ namespace Aucma.Core.CodeBinding.ViewModels
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 赋值
|
|
|
|
|
Code1 = "B236000007811023002";
|
|
|
|
|
// Code1Time = "2023-10-23 16:05:23";
|
|
|
|
|
Code2 = "B236000007811023002";
|
|
|
|
|
// Code2Time = "2023-10-23 16:05:23";
|
|
|
|
|
BindingInfo = "条码[B236000007811023002]和SN条码[B236000007811023002]绑定成功!";
|
|
|
|
|
ListItems.Clear();
|
|
|
|
|
//// 赋值
|
|
|
|
|
//Code1 = "B236000007811023002";
|
|
|
|
|
//// Code1Time = "2023-10-23 16:05:23";
|
|
|
|
|
//Code2 = "B236000007811023002";
|
|
|
|
|
//// Code2Time = "2023-10-23 16:05:23";
|
|
|
|
|
//BindingInfo = "条码[B236000007811023002]和SN条码[B236000007811023002]绑定成功!";
|
|
|
|
|
LoadCharts();
|
|
|
|
|
|
|
|
|
|
List<CodeBindingRecord> records = null;
|
|
|
|
|
records = await _codeBindingRecordServices.QueryAsync(x => x.BoxCode != null && x.RecordTime2 >= System.DateTime.Now.AddDays(-1), "RECORD_TIME2 desc");
|
|
|
|
|
if (records != null)
|
|
|
|
@ -230,12 +246,16 @@ namespace Aucma.Core.CodeBinding.ViewModels
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// 测试方法
|
|
|
|
|
private async void add()
|
|
|
|
|
private async void add()
|
|
|
|
|
{
|
|
|
|
|
//String code = "9002006859";
|
|
|
|
|
//List<BaseBomInfo> bomInfo = await _baseBomInfoServices.QueryAsync(x => x.MaterialCode == code);
|
|
|
|
|
//string aa = bomInfo.FirstOrDefault().MaterialName;
|
|
|
|
|
//Console.WriteLine(aa);
|
|
|
|
|
//DateTime startTime = DateTime.Now;
|
|
|
|
|
//Thread.Sleep(5000);
|
|
|
|
|
|
|
|
|
|
//TimeSpan elapsedTime = DateTime.Now - startTime;
|
|
|
|
|
//Console.WriteLine(elapsedTime.TotalSeconds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
@ -429,9 +449,11 @@ namespace Aucma.Core.CodeBinding.ViewModels
|
|
|
|
|
/// <param name="logStr"></param>
|
|
|
|
|
private void RefreshAndWriteLog(string logStr)
|
|
|
|
|
{
|
|
|
|
|
DateTime time = System.DateTime.Now;
|
|
|
|
|
BindingInfo = time + ":" + logStr;
|
|
|
|
|
log.Info(logStr);
|
|
|
|
|
TimeSpan currentTime = DateTime.Now.TimeOfDay;
|
|
|
|
|
// DateTime time = System.DateTime.Now;
|
|
|
|
|
string timeString = currentTime.ToString(@"hh\:mm\:ss");
|
|
|
|
|
BindingInfo = timeString + ":" + logStr;
|
|
|
|
|
log.Info(BindingInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -451,14 +473,14 @@ namespace Aucma.Core.CodeBinding.ViewModels
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseMaterialInfo materialInfo = _baseMaterialInfoServices.FirstAsync(x => x.MaterialCode == code1.Substring(7, 10)).Result;
|
|
|
|
|
BaseMaterialInfo materialInfo = _baseMaterialInfoServices.FirstAsync(x => x.MaterialCode == code1.Substring(7, 10)).Result;
|
|
|
|
|
record.BoxName = materialInfo.MaterialName;
|
|
|
|
|
record.ProductCode = code2;
|
|
|
|
|
record.RecordTime1 = System.DateTime.Now;
|
|
|
|
|
record.RecordTime2 = System.DateTime.Now;
|
|
|
|
|
record.isPlcPass = 1;
|
|
|
|
|
record.BindingResult = "成功";
|
|
|
|
|
bool result =_codeBindingRecordServices.UpdateAsync(record).Result;
|
|
|
|
|
bool result = _codeBindingRecordServices.UpdateAsync(record).Result;
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
RefreshAndWriteLog("条码【" + record.BoxCode + "】与SN码【" + record.ProductCode + "】绑定成功");
|
|
|
|
@ -495,31 +517,17 @@ namespace Aucma.Core.CodeBinding.ViewModels
|
|
|
|
|
/// 下发plc放行信号
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="materialType"></param>
|
|
|
|
|
private bool SendPlcPass()
|
|
|
|
|
private bool SendPlcPass(PlcModel obj)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc"));
|
|
|
|
|
if (obj != null)
|
|
|
|
|
{
|
|
|
|
|
if (obj.plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
// 往plc写入放行信号
|
|
|
|
|
obj.plc.WriteInt32("D100", 1);
|
|
|
|
|
// 等待plc反馈信号
|
|
|
|
|
waitPlcSignal();
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log.Info("条码绑定plc连接失败,请检查plc连接");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log.Info("获取plc连接对象信息为空");
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
log.Info("D7100写1");
|
|
|
|
|
// 往plc写入放行信号
|
|
|
|
|
obj.plc.WriteInt16("D7100", "1");
|
|
|
|
|
// 等待plc反馈信号
|
|
|
|
|
result = waitPlcSignal(obj);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
@ -531,42 +539,35 @@ namespace Aucma.Core.CodeBinding.ViewModels
|
|
|
|
|
/// 读取plc放行反馈
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="materialType"></param>
|
|
|
|
|
private void waitPlcSignal()
|
|
|
|
|
private bool waitPlcSignal(PlcModel obj)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
bool isFlag = true;
|
|
|
|
|
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc"));
|
|
|
|
|
if (obj != null)
|
|
|
|
|
{
|
|
|
|
|
if (obj.plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
if (obj.plc.ReadInt32("D100") == 2)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("收到plc放行成功");
|
|
|
|
|
obj.plc.WriteInt32("D100", 0);
|
|
|
|
|
isFlag = false;
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
} while (isFlag);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log.Info("条码绑定plc连接失败,请检查plc连接");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log.Info("获取plc连接对象信息为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DateTime startTime = DateTime.Now;
|
|
|
|
|
bool isFlag = true;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
if (obj.plc.ReadInt16("D7200") == 2)
|
|
|
|
|
{
|
|
|
|
|
log.Info("D7100读2");
|
|
|
|
|
|
|
|
|
|
isFlag = false;
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
TimeSpan elapsedTime = DateTime.Now - startTime;
|
|
|
|
|
if (elapsedTime.TotalSeconds >= 5)
|
|
|
|
|
{
|
|
|
|
|
isFlag = false;
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
} while (isFlag);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error("读取plc放行反馈方法waitPlcSignal()出现异常,ex:" + ex);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|