|
|
|
@ -27,6 +27,8 @@ using System.Data.Common;
|
|
|
|
|
using static Org.BouncyCastle.Math.EC.ECCurve;
|
|
|
|
|
using Admin.Core.IRepository;
|
|
|
|
|
using Admin.Core.Service;
|
|
|
|
|
using System.Windows.Forms.VisualStyles;
|
|
|
|
|
using Microsoft.IdentityModel.Logging;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 成品分舵入库首页信息
|
|
|
|
@ -40,18 +42,70 @@ namespace Aucma.Core.ProductOffLine.ViewModels
|
|
|
|
|
private readonly IBaseOrderInfoServices _baseOrderInfoServices;
|
|
|
|
|
private readonly IProductPlanInfoServices? _productPlanInfoServices;
|
|
|
|
|
private readonly IProductOffLineServices ? _productOffLineServices;
|
|
|
|
|
|
|
|
|
|
System.Timers.Timer timer = new System.Timers.Timer(1000);
|
|
|
|
|
int a = 0;
|
|
|
|
|
public IndexPageViewModel()
|
|
|
|
|
{
|
|
|
|
|
_productOffLineServices = App.ServiceProvider.GetService<IProductOffLineServices>();
|
|
|
|
|
_baseOrderInfoServices = App.ServiceProvider.GetService<IBaseOrderInfoServices>();
|
|
|
|
|
_productPlanInfoServices = App.ServiceProvider.GetService<IProductPlanInfoServices>();
|
|
|
|
|
|
|
|
|
|
_productPlanInfoServices = App.ServiceProvider.GetService<IProductPlanInfoServices>();
|
|
|
|
|
MvCodeHelper.ReceiveCodeEvent += ReceiveCode;
|
|
|
|
|
test33();
|
|
|
|
|
// test33();
|
|
|
|
|
StartPlcTimer();
|
|
|
|
|
InitEveryDayMethod();
|
|
|
|
|
//*** test2();
|
|
|
|
|
test2();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开启plc读取定时器
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void StartPlcTimer()
|
|
|
|
|
{
|
|
|
|
|
if (!timer.Enabled)
|
|
|
|
|
{
|
|
|
|
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(readPlcStatus);
|
|
|
|
|
timer.AutoReset = true;
|
|
|
|
|
timer.Enabled = false;
|
|
|
|
|
timer.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 定时读取plc扫码信号,放行完成反馈信号
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void readPlcStatus(object source, System.Timers.ElapsedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
startGrab();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取开启扫码信号
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void startGrab()
|
|
|
|
|
{
|
|
|
|
|
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("成品下线Plc"));
|
|
|
|
|
if (obj != null)
|
|
|
|
|
{
|
|
|
|
|
if (obj.plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
// 扫码器1开启扫码信号
|
|
|
|
|
if (obj.plc.ReadInt32("D300") == 1)
|
|
|
|
|
{
|
|
|
|
|
obj.plc.WriteInt32("D300", 0);
|
|
|
|
|
// string code = MvCodeHelper.StartGrabByPlc(Appsettings.app("Middleware", "Scanner1", "Ip"));
|
|
|
|
|
//if (string.IsNullOrEmpty(code)) return;
|
|
|
|
|
string code = "11111";
|
|
|
|
|
ReceiveCode(code, 1);
|
|
|
|
|
}// 扫码器2开启扫码信号
|
|
|
|
|
else if (obj.plc.ReadInt32("D302") == 2)
|
|
|
|
|
{
|
|
|
|
|
obj.plc.WriteInt32("D302", 0);
|
|
|
|
|
//string code = MvCodeHelper.StartGrabByPlc(Appsettings.app("Middleware", "Scanner1", "Ip"));
|
|
|
|
|
//if (string.IsNullOrEmpty(code)) return;
|
|
|
|
|
string code = "11111";
|
|
|
|
|
ReceiveCode(code, 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#region 扫描信息
|
|
|
|
|
|
|
|
|
@ -222,84 +276,92 @@ namespace Aucma.Core.ProductOffLine.ViewModels
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="code"></param>
|
|
|
|
|
/// <param name="direction">扫码器方向,1左边分A库,2右边分B库</param>
|
|
|
|
|
private async void ReceiveCode(string code, int scannerNo)
|
|
|
|
|
private async void ReceiveCode(string code, int scannerNo)
|
|
|
|
|
{
|
|
|
|
|
//1.扫描的SN条码去条码系统查询GET_BARCODE_DATA
|
|
|
|
|
//条码系统返回校验数据
|
|
|
|
|
//string result = _productOffLineServices.QueryChecked(code).Result
|
|
|
|
|
string result = "Y@1104@16160030000000910780@000010034895@@ @000000@000000009000000807@BCD-160C,家电下乡@@BCD-160C@皓月白-家电下乡@161601300@160@1-00版@家电下乡产品@默认@2010-09-01";
|
|
|
|
|
// 如果校验失败,下发报警
|
|
|
|
|
if("N".Equals(result.Substring(0,1)))
|
|
|
|
|
//1.扫描的SN条码去条码系统查询GET_BARCODE_DATA
|
|
|
|
|
//条码系统返回校验数据
|
|
|
|
|
// string result = await _productOffLineServices.QueryChecked(code);
|
|
|
|
|
string result = "Y@1104@16160030000000910780@000010034895@@ @000000@000000009000000807@BCD-160C,家电下乡@@BCD-160C@皓月白-家电下乡@161601300@160@1-00版@家电下乡产品@默认@2010-09-01";
|
|
|
|
|
// 如果校验失败,下发报警
|
|
|
|
|
if ("N".Equals(result.Substring(0, 1)))
|
|
|
|
|
{
|
|
|
|
|
sendPlcError();
|
|
|
|
|
// 刷新页面提示信息 result.Substring(2)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//2.查询到的数据分割处理,结果中用"@"号分隔,刷新页面显示并存到scada数据库(表待建)
|
|
|
|
|
string[] resultArray = result.Split('@');
|
|
|
|
|
// 输出结果
|
|
|
|
|
foreach (string item in resultArray)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//3.分垛A,B库逻辑(先左边读到的条码分A库,右边读到的B库==>预留分库逻辑)
|
|
|
|
|
|
|
|
|
|
//4.下发plc信号
|
|
|
|
|
bool flag = SendPlcPass(scannerNo);
|
|
|
|
|
if (!flag)
|
|
|
|
|
{
|
|
|
|
|
log.Error("获取plc反馈失败");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine(code);
|
|
|
|
|
return;
|
|
|
|
|
//5.调条码系统保存入库接口SaveBarcodeInfo
|
|
|
|
|
string saveResult = await _productOffLineServices.SaveBarcodeInfo("333", "ILS_SORT","11111", 1);
|
|
|
|
|
if (string.IsNullOrEmpty(saveResult) ||"E".Equals(saveResult.Substring(0, 1)))
|
|
|
|
|
{
|
|
|
|
|
log.Error("条码系统保存接口出错");
|
|
|
|
|
sendPlcError();
|
|
|
|
|
// 刷新页面提示信息 result.Substring(2)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//2.查询到的数据分割处理,结果中用"@"号分隔,刷新页面显示并存到scada数据库(表待建)
|
|
|
|
|
string[] resultArray = result.Split('@');
|
|
|
|
|
// 输出结果
|
|
|
|
|
foreach (string item in resultArray)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//3.调条码系统保存接口入库SaveBarcodeInfo
|
|
|
|
|
_productOffLineServices.SaveBarcodeInfo();
|
|
|
|
|
|
|
|
|
|
//4.更新mes数据库完成数量和时间(BASE_ORDERINFO,PRODUCT_PLANINFO) 注意:查询的字段可能需要修改,确保数据一致
|
|
|
|
|
//6.更新mes数据库完成数量和时间(BASE_ORDERINFO,PRODUCT_PLANINFO) 注意:查询的字段可能需要修改,确保数据一致
|
|
|
|
|
|
|
|
|
|
//4.1截取订单号去查询更新BASE_ORDERINFO,全放到service处理
|
|
|
|
|
//6.1截取订单号去查询更新BASE_ORDERINFO,全放到service处理
|
|
|
|
|
string orderCode = "11215484";
|
|
|
|
|
List<BaseOrderInfo> orders = await _baseOrderInfoServices.QueryAsync(x => x.OrderCode == orderCode);
|
|
|
|
|
List<BaseOrderInfo> orders = await _baseOrderInfoServices.QueryAsync(x => x.OrderCode == orderCode);
|
|
|
|
|
BaseOrderInfo order = orders.FirstOrDefault();
|
|
|
|
|
if (order.CompleteAmount == 0)
|
|
|
|
|
{
|
|
|
|
|
order.CompleteAmount++;
|
|
|
|
|
order.BeginDate = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
if(order.CompleteAmount==order.OrderAmount)
|
|
|
|
|
if (order.CompleteAmount == order.OrderAmount)
|
|
|
|
|
{
|
|
|
|
|
order.EndDate = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
order.UpdatedTime = DateTime.Now;
|
|
|
|
|
_baseOrderInfoServices.UpdateAsync(order);
|
|
|
|
|
//4.2根据订单号去更新PRODUCT_PLANINFO
|
|
|
|
|
List<ProductPlanInfo> productInfos =await _productPlanInfoServices.QueryAsync(x => x.OrderCode == orderCode);
|
|
|
|
|
//6.2根据订单号去更新PRODUCT_PLANINFO
|
|
|
|
|
List<ProductPlanInfo> productInfos = await _productPlanInfoServices.QueryAsync(x => x.OrderCode == orderCode);
|
|
|
|
|
ProductPlanInfo productInfo = productInfos.FirstOrDefault();
|
|
|
|
|
if (productInfo.CompleteAmount == 0)
|
|
|
|
|
{
|
|
|
|
|
productInfo.CompleteAmount++;
|
|
|
|
|
productInfo.BeginTime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
if(productInfo.CompleteAmount==productInfo.PlanAmount)
|
|
|
|
|
if (productInfo.CompleteAmount == productInfo.PlanAmount)
|
|
|
|
|
{
|
|
|
|
|
productInfo.EndTime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
productInfo.UpdatedTime = DateTime.Now;
|
|
|
|
|
await _productPlanInfoServices.UpdateAsync(productInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//5.分垛A,B库逻辑(先左边读到的条码分A库,右边读到的B库==>预留分库逻辑)
|
|
|
|
|
|
|
|
|
|
//6.下发plc信号
|
|
|
|
|
SendPlcPass(scannerNo);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region plc交互
|
|
|
|
|
|
|
|
|
|
// private SemaphoreSlim semaphore = new SemaphoreSlim(0);
|
|
|
|
|
private SemaphoreSlim semaphore = new SemaphoreSlim(0);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下发plc放行信号,根据接收到的scannerNo不同,两条道的plc信号地址也不同
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="materialType"></param>
|
|
|
|
|
private bool SendPlcPass(int scannerNo)
|
|
|
|
|
private bool SendPlcPass(int scannerNo)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("成品下线Plc"));
|
|
|
|
|
if (obj != null)
|
|
|
|
|
{
|
|
|
|
@ -322,7 +384,7 @@ namespace Aucma.Core.ProductOffLine.ViewModels
|
|
|
|
|
|
|
|
|
|
// 等待plc反馈信号
|
|
|
|
|
waitPlcSignal(scannerNo);
|
|
|
|
|
// semaphore.Wait();
|
|
|
|
|
// semaphore.Wait();
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -349,12 +411,9 @@ namespace Aucma.Core.ProductOffLine.ViewModels
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lock (string.Empty)
|
|
|
|
|
{
|
|
|
|
|
bool isFlag = true;
|
|
|
|
|
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("成品下线Plc"));
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (obj != null && obj.plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
@ -385,17 +444,14 @@ namespace Aucma.Core.ProductOffLine.ViewModels
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
} while (isFlag);
|
|
|
|
|
// 释放信号量
|
|
|
|
|
// semaphore.Release();
|
|
|
|
|
|
|
|
|
|
// 释放信号量
|
|
|
|
|
//semaphore.Release();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log.Info("成品下线plc连接失败");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
@ -465,9 +521,12 @@ namespace Aucma.Core.ProductOffLine.ViewModels
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
SendPlcPass(1);
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
SendPlcPass(2);
|
|
|
|
|
ReceiveCode("123456", 1);
|
|
|
|
|
});
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(3000);
|
|
|
|
|
ReceiveCode("654321", 2);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|