change - 成品下线业务

dev
liuwf 1 year ago
parent 3c1a845d65
commit 3af2fc6c90

@ -6,7 +6,7 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d" mc:Ignorable="d"
Title="SCADA" Height="1080" Width="1920" Icon="/Assets/images/Icon.png" Title="SCADA" Height="1080" Width="1920" Icon="/Assets/images/Icon.png"
WindowState="Maximized" WindowStyle="None" ResizeMode="NoResize" Topmost="True"> WindowState="Maximized" WindowStyle="None" ResizeMode="NoResize">
<Window.Background> <Window.Background>
<ImageBrush ImageSource="/Assets/images/background.jpg" /> <ImageBrush ImageSource="/Assets/images/background.jpg" />
</Window.Background> </Window.Background>

@ -1,4 +1,5 @@
using Admin.Core.IService; using Admin.Core.Common;
using Admin.Core.IService;
using Admin.Core.Model; using Admin.Core.Model;
using Admin.Core.Model.Model_New; using Admin.Core.Model.Model_New;
using Admin.Core.Service; using Admin.Core.Service;
@ -8,6 +9,7 @@ using Aucma.Core.ProductOffLine.Models;
using log4net; using log4net;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Logging; using Microsoft.IdentityModel.Logging;
using NetTaste;
using RestSharp; using RestSharp;
using System; using System;
using System.Collections; using System.Collections;
@ -38,15 +40,19 @@ namespace Aucma.Core.ProductOffLine.Business
} }
#endregion #endregion
// public OffLineBusiness(){} // public OffLineBusiness(){}
#region 变量定义 #region 变量定义
public static TempInfo TempOffLineInfo = new TempInfo(); /// <summary>
public static TempInfo FDOffLineInfo = new TempInfo(); /// 扫码器1扫到条码的临时数据
/// </summary>
public static TempInfo TempOffLineInfo1 = new TempInfo();
/// <summary>
/// 扫码器2扫到条码的临时数据
/// </summary>
public static TempInfo TempOffLineInfo2 = new TempInfo();
// 河南工厂编码 // 河南工厂编码
private static string Werks = "1301"; private static string Werks = "1301";
#endregion #endregion
#region 接口引用 #region 接口引用
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(OffLineBusiness)); private static readonly log4net.ILog log = LogManager.GetLogger(typeof(OffLineBusiness));
@ -58,8 +64,6 @@ namespace Aucma.Core.ProductOffLine.Business
private readonly IOffLineInfoServices? _offLineInfoServices = App.ServiceProvider.GetService<IOffLineInfoServices>(); private readonly IOffLineInfoServices? _offLineInfoServices = App.ServiceProvider.GetService<IOffLineInfoServices>();
#endregion #endregion
#region 委托事件 #region 委托事件
/// <summary> /// <summary>
@ -87,148 +91,132 @@ namespace Aucma.Core.ProductOffLine.Business
#endregion #endregion
public async void test() public async void test()
{ {
//TempInfo info = new TempInfo(); string tt = "Y@1104@16160030000000910780@000010034895@@ @000000@000000009000000807@BCD-160C,家电下乡@@BCD-160C@皓月白-家电下乡@161601300@160@1-00版@家电下乡产品@默认@2010-09-01";
//string tt = "Y@1104@16160030000000910780@000010034895@@ @000000@000000009000000807@BCD-160C,家电下乡@@BCD-160C@皓月白-家电下乡@161601300@160@1-00版@家电下乡产品@默认@2010-09-01"; string[] FArrayList = tt.Split('@');
//string[] FArrayList = tt.Split('@'); if (FArrayList[0].ToUpper() == "Y") //查询数据成功
//if (FArrayList[0].ToUpper() == "Y") //查询数据成功 {
//{ #region 实体赋值
// #region 实体赋值 TempOffLineInfo1.ProductFactoryCode = FArrayList[1];
// info.ProductFactoryCode = FArrayList[1]; TempOffLineInfo1.ProductSNCode = FArrayList[2];
// info.ProductSNCode = FArrayList[2]; TempOffLineInfo1.ProductOrderNo = DBToString(FArrayList[3]);
// info.ProductOrderNo = DBToString(FArrayList[3]); TempOffLineInfo1.ProductSaleNo = DBToString(FArrayList[4]);
// info.ProductSaleNo = DBToString(FArrayList[4]); TempOffLineInfo1.ProductSaleLineNo = DBToString(FArrayList[5]);
// info.ProductSaleLineNo = DBToString(FArrayList[5]); TempOffLineInfo1.ProductCheckInfo = DBToString(FArrayList[6]); //验证组合
// info.ProductCheckInfo = DBToString(FArrayList[6]); //验证组合 TempOffLineInfo1.ProductCode = DBToString(FArrayList[7]);
// info.ProductCode = DBToString(FArrayList[7]); TempOffLineInfo1.ProductName = DBToString(FArrayList[8]); //产品描述
// info.ProductName = DBToString(FArrayList[8]); //产品描述 TempOffLineInfo1.ProductType = FArrayList[9];
// info.ProductType = FArrayList[9]; TempOffLineInfo1.ProductModel = FArrayList[10]; //产品型号
// info.ProductModel = FArrayList[10]; //产品型号 TempOffLineInfo1.ProductRemark = DBToString(FArrayList[11]);
// info.ProductRemark = DBToString(FArrayList[11]); TempOffLineInfo1.ProductBarNo = FArrayList[12];
// info.ProductBarNo = FArrayList[12]; TempOffLineInfo1.ProductMasterModel = FArrayList[13]; //产品主型号
// info.ProductMasterModel = FArrayList[13]; //产品主型号 TempOffLineInfo1.ProductVersion = FArrayList[14];
// info.ProductVersion = FArrayList[14]; TempOffLineInfo1.ProductUseInfo = FArrayList[15];//产品用途
// info.ProductUseInfo = FArrayList[15];//产品用途 TempOffLineInfo1.ProductCirculate = FArrayList[16];//流通特性
// info.ProductCirculate = FArrayList[16];//流通特性 TempOffLineInfo1.ProductCreateDate = FArrayList[17];
// info.ProductCreateDate = FArrayList[17]; #endregion
// #endregion TempOffLineInfo1.ProductScanTime = System.DateTime.Now;
// info.ProductScanTime = System.DateTime.Now; TempOffLineInfo1.number1 = "111";
// info.number1 = "111"; // OffLineInfo info11 = MapperTwo(TempOffLineInfo);
// OffLineInfo info11 = MapperTwo(info);
// int a = await _offLineInfoServices.AddAsync(info11); // int a = await _offLineInfoServices.AddAsync(info11);
// Console.WriteLine(a); // Console.WriteLine(a);
//} }
} }
/// <summary> /// <summary>
/// 处理条码 /// 处理条码
/// </summary> /// </summary>
/// <param name="code"></param> /// <param name="code"></param>
/// <param name="direction">扫码器方向</param> /// <param name="direction">扫码器方向</param>
public async void MaterialBarScanEvent(string code)//接收条码数据 public async void MaterialBarScanEvent(string code,string scannerIp)//接收条码数据
{
int ScannerNo = scannerIp== Appsettings.app("Middleware", "Scanner1", "Ip") ? 1:2 ; // 确定是哪个扫码器
bool BackResult = false;
if (ScannerNo==1)
{ {
//1.扫描的SN条码去条码系统校验 //1.扫描的SN条码去条码系统校验
bool BackResult = await HandleMaterialBarCode(code.Trim()); //处理条码信息 BackResult = await HandleMaterialBarCode(code.Trim(), TempOffLineInfo1); //扫码器1
TempOffLineInfo.ReadFlag = 0; // 2.更新mes数据库
if (BackResult == true) await updateMesData(TempOffLineInfo1);
{
TempOffLineInfo.ProductRefreshFlag = true;
// 更新mes数据库
OffLineInfo info11 = MapperTwo(TempOffLineInfo);
int a = await _offLineInfoServices.AddAsync(info11);
log.Info(String.Format("订单号{0} 订单数量{1}", TempOffLineInfo.ProductOrderNo.Replace("0000", ""), TempOffLineInfo.OrderQty));
if (a > 0)
{
// 先查询分垛方向A或者B eg:000000009001000718=>9001000718
string direction = getDirectioneEvent?.Invoke(TempOffLineInfo.ProductCode.Replace("00000000", ""));
// DownLoadPassFlag(BackResult); //下发plc放行信号,分垛AB库
TempOffLineInfo.ReadFlag = 1; //放行成功
}
else
{
TempOffLineInfo.ReadFlag = 2; //保存条码失败
}
}
else
{
log.Info("条码验证失败");
TempOffLineInfo.ReadFlag = 3; // 条码验证失败
}
} }
else
{
BackResult = await HandleMaterialBarCode(code.Trim(), TempOffLineInfo2); //扫码器2
// 2.更新mes数据库
await updateMesData(TempOffLineInfo1);
}
if (BackResult == true)
{
log.Info(String.Format("订单号{0} 订单数量{1}", TempOffLineInfo1.ProductOrderNo, TempOffLineInfo1.OrderQty));
// 先查询分垛方向A或者B
string direction = getDirectioneEvent?.Invoke(TempOffLineInfo1.ProductCode);
DownLoadPassFlag(ScannerNo,direction); //下发plc放行信号,分垛AB库
}
}
/// <summary>
/// 条码验证成功后更新mes数据库 成品下线表,订单表等等
/// </summary>
/// <param name="BarCode"></param>
/// <returns></returns>
public async Task<bool> updateMesData(TempInfo TempOffLineInfo)
{
try
{
// TempOffLineInfo.ProductRefreshFlag = true;
OffLineInfo info11 = MapperTwo(TempOffLineInfo);
// 添加成品下线表
await _offLineInfoServices.AddAsync(info11);
// 添加订单表
////6.更新mes数据库完成数量和时间(BASE_ORDERINFO,PRODUCT_PLANINFO) 注意:查询的字段可能需要修改,确保数据一致
////6.1截取订单号去查询更新BASE_ORDERINFO,全放到service处理
//string orderCode = "11215484";
//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)
//{
// order.EndDate = DateTime.Now;
//}
//order.UpdatedTime = DateTime.Now;
//_baseOrderInfoServices.UpdateAsync(order);
////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)
//{
// productInfo.EndTime = DateTime.Now;
//}
//productInfo.UpdatedTime = DateTime.Now;
//await _productPlanInfoServices.UpdateAsync(productInfo);
return true;
}
catch (Exception)
{
log.Info("更新数据库记录失败");
return false;
}
}
// // 如果校验失败,下发报警 /// <summary>
// if ("N".Equals(result.Substring(0, 1))) /// 去条码系统查询校验并保存
//{ /// </summary>
// sendPlcError(); /// <param name="BarCode"></param>
// // 刷新页面提示信息 result.Substring(2) /// <returns></returns>
// return false; public async Task<bool> HandleMaterialBarCode(string BarCode,TempInfo TempOffLineInfo)
//}
//3.分垛A,B库逻辑(先左边读到的条码分A库右边读到的B库==>预留分库逻辑)
////4.下发plc信号
//bool flag = SendPlcPass();
//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();
// return;
//}
////6.更新mes数据库完成数量和时间(BASE_ORDERINFO,PRODUCT_PLANINFO) 注意:查询的字段可能需要修改,确保数据一致
////6.1截取订单号去查询更新BASE_ORDERINFO,全放到service处理
//string orderCode = "11215484";
//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)
//{
// order.EndDate = DateTime.Now;
//}
//order.UpdatedTime = DateTime.Now;
//_baseOrderInfoServices.UpdateAsync(order);
////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)
//{
// productInfo.EndTime = DateTime.Now;
//}
//productInfo.UpdatedTime = DateTime.Now;
//await _productPlanInfoServices.UpdateAsync(productInfo);
/// <summary>
/// 去条码系统查询校验并保存
/// </summary>
/// <param name="BarCode"></param>
/// <returns></returns>
public async Task<bool> HandleMaterialBarCode(string BarCode)
{ {
try try
{ {
@ -252,11 +240,11 @@ namespace Aucma.Core.ProductOffLine.Business
TempOffLineInfo.MsgInfo = "获取信息成功" + BarCode + " 返回值:" + FArrayList[0].ToUpper(); TempOffLineInfo.MsgInfo = "获取信息成功" + BarCode + " 返回值:" + FArrayList[0].ToUpper();
TempOffLineInfo.ProductFactoryCode = FArrayList[1]; TempOffLineInfo.ProductFactoryCode = FArrayList[1];
TempOffLineInfo.ProductSNCode = FArrayList[2]; TempOffLineInfo.ProductSNCode = FArrayList[2];
TempOffLineInfo.ProductOrderNo = DBToString(FArrayList[3]); TempOffLineInfo.ProductOrderNo = DBToString(FArrayList[3]).Replace("0000", "");
TempOffLineInfo.ProductSaleNo = DBToString(FArrayList[4]); TempOffLineInfo.ProductSaleNo = DBToString(FArrayList[4]);
TempOffLineInfo.ProductSaleLineNo = DBToString(FArrayList[5]); TempOffLineInfo.ProductSaleLineNo = DBToString(FArrayList[5]);
TempOffLineInfo.ProductCheckInfo = DBToString(FArrayList[6]); //验证组合 TempOffLineInfo.ProductCheckInfo = DBToString(FArrayList[6]); //验证组合
TempOffLineInfo.ProductCode = DBToString(FArrayList[7]); TempOffLineInfo.ProductCode = DBToString(FArrayList[7]).Replace("00000000", "");
TempOffLineInfo.ProductName = DBToString(FArrayList[8]); //产品描述 TempOffLineInfo.ProductName = DBToString(FArrayList[8]); //产品描述
TempOffLineInfo.ProductType = FArrayList[9]; TempOffLineInfo.ProductType = FArrayList[9];
TempOffLineInfo.ProductModel = FArrayList[10]; //产品型号 TempOffLineInfo.ProductModel = FArrayList[10]; //产品型号
@ -270,18 +258,18 @@ namespace Aucma.Core.ProductOffLine.Business
#endregion #endregion
// 多码系统校验,是否需要待定,现场看情况 // 多码系统校验,是否需要待定,现场看情况
bool flag = TestBarCode(TempOffLineInfo); // bool flag = TestBarCode(TempOffLineInfo);
if (!flag) // if (!flag)
{ // {
return false; // return false;
} // }
log.Info(TempOffLineInfo.ProductSNCode + ", 多码验证通过!"); log.Info(TempOffLineInfo.ProductSNCode + ", 多码验证通过!");
} }
else else
{ {
log.Info(BarCode + "失败返回验证信息:" + FArrayList[1]); log.Info(BarCode + "失败返回验证信息:" + FArrayList[1]);
#region 实体赋值 #region 实体赋值
TempOffLineInfo.ProductDataFlag = true; // TempOffLineInfo.ProductDataFlag = true;
TempOffLineInfo.MsgAlarmFlag = true; TempOffLineInfo.MsgAlarmFlag = true;
TempOffLineInfo.MsgInfo = "获取信息失败. " + BarCode + " 返回值:" + FArrayList[0].ToString(); TempOffLineInfo.MsgInfo = "获取信息失败. " + BarCode + " 返回值:" + FArrayList[0].ToString();
TempOffLineInfo.ProductOrderNo = ""; TempOffLineInfo.ProductOrderNo = "";
@ -339,7 +327,7 @@ namespace Aucma.Core.ProductOffLine.Business
{ {
log.Info(BarCode + "条码重复,本地已存在"); log.Info(BarCode + "条码重复,本地已存在");
TempOffLineInfo.MsgInfo = TempOffLineInfo.MsgInfo + ",上传条码失败" + strSave + "上传日期:" + DBToString(offLineInfo.ProductScanTime); TempOffLineInfo.MsgInfo = TempOffLineInfo.MsgInfo + ",上传条码失败" + strSave + "上传日期:" + DBToString(offLineInfo.ProductScanTime);
// chkout:条码重复是否允许放行
if (TempOffLineInfo.ChkOut == true) if (TempOffLineInfo.ChkOut == true)
{ {
return true; return true;
@ -380,21 +368,18 @@ namespace Aucma.Core.ProductOffLine.Business
{ {
TempOffLineInfo.ProductRefreshFlag = true; TempOffLineInfo.ProductRefreshFlag = true;
} }
} }
#region plc交互 #region plc交互
private SemaphoreSlim semaphore = new SemaphoreSlim(0);
/// <summary> /// <summary>
/// 下发plc放行信号,根据接收到的scannerNo不同两条道的plc信号地址也不同 /// 下发plc放行信号,传进来扫码器编号分垛方向A或者B,返回plc反馈结果
/// </summary> /// </summary>
/// <param name="materialType"></param> /// <param name="materialType"></param>
private bool SendPlcPass(int scannerNo) private bool DownLoadPassFlag(int scannerNo,string strDirection)
{ {
// 入库方向A,B
int direction = strDirection == "A" ? 1 : 2;
bool result = false; bool result = false;
try try
{ {
@ -402,26 +387,59 @@ namespace Aucma.Core.ProductOffLine.Business
if (obj != null) if (obj != null)
{ {
if (obj.plc.IsConnected) if (obj.plc.IsConnected)
{ {
if (scannerNo == 1) if(scannerNo == 1) // 扫码器1对应的货道地址
{ {
// 写入入库方向两条道plc地址不同 // 写入入库方向两条道plc地址不同
obj.plc.WriteInt32("D100", scannerNo); obj.plc.WriteInt32("D100", direction);
// 往plc写入放行信号 // 往plc写入放行信号
obj.plc.WriteInt32("D102", 1); obj.plc.WriteInt32("D102", 1);
} }
else else
{ {
// 写入入库方向两条道plc地址不同 // 写入入库方向两条道plc地址不同
obj.plc.WriteInt32("D200", scannerNo); obj.plc.WriteInt32("D200", direction);
// 往plc写入放行信号 // 往plc写入放行信号
obj.plc.WriteInt32("D202", 1); obj.plc.WriteInt32("D202", 1);
} }
DateTime targetTime = DateTime.Now.AddSeconds(8);
// 等待plc反馈信号 // 等待plc反馈信号
waitPlcSignal(scannerNo); while (true)
// semaphore.Wait(); {
result = true; if(DateTime.Now > targetTime) // plc超最大时限无反馈
{
log.Info("等待plc放行反馈信号超时");
result = false;
break;
}
if (scannerNo == 1)
{
// 读取plc反馈信号
if (obj.plc.ReadInt32("D102") == 2)
{
Console.WriteLine("收到plc放行成功");
// 清空数据
obj.plc.WriteInt32("D100", 0);
obj.plc.WriteInt32("D102", 0);
result = true;
break;
}
}
else
{
// 读取plc反馈信号
if (obj.plc.ReadInt32("D202") == 2)
{
Console.WriteLine("收到plc放行成功");
// 清空数据
obj.plc.WriteInt32("D200", 0);
obj.plc.WriteInt32("D202", 0);
result = true;
break;
}
}
Thread.Sleep(500);
}
} }
else else
{ {
@ -439,61 +457,6 @@ namespace Aucma.Core.ProductOffLine.Business
} }
return result; return result;
} }
/// <summary>
/// 读取plc放行反馈
/// </summary>
/// <param name="materialType"></param>
private void waitPlcSignal(int scannerNo)
{
try
{
bool isFlag = true;
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("成品下线Plc"));
if (obj != null && obj.plc.IsConnected)
{
do
{
if (scannerNo == 1)
{
// 读取plc反馈信号
if (obj.plc.ReadInt32("D102") == 2)
{
Console.WriteLine("收到plc放行成功");
// 清空数据
obj.plc.WriteInt32("D100", 0);
obj.plc.WriteInt32("D102", 0);
isFlag = false;
}
}
else
{
// 读取plc反馈信号
if (obj.plc.ReadInt32("D202") == 2)
{
Console.WriteLine("收到plc放行成功");
// 清空数据
obj.plc.WriteInt32("D200", 0);
obj.plc.WriteInt32("D202", 0);
isFlag = false;
}
}
Thread.Sleep(1000);
} while (isFlag);
// 释放信号量
//semaphore.Release();
}
else
{
log.Info("成品下线plc连接失败");
}
}
catch (Exception ex)
{
log.Error("读取plc放行反馈方法waitPlcSignal()出现异常,ex:" + ex);
}
}
/// <summary> /// <summary>
/// 下发plc报警信号 /// 下发plc报警信号
@ -531,7 +494,7 @@ namespace Aucma.Core.ProductOffLine.Business
#region 工具方法 #region 工具方法
/// <summary> /// <summary>
/// /// 转换成字符串
/// </summary> /// </summary>
/// <param name="refData"></param> /// <param name="refData"></param>
/// <returns></returns> /// <returns></returns>
@ -544,7 +507,7 @@ namespace Aucma.Core.ProductOffLine.Business
} }
/// <summary> /// <summary>
/// 多码系统校验 /// 多码系统校验,暂未确定使用
/// </summary> /// </summary>
/// <param name="TempOffLineInfo"></param> /// <param name="TempOffLineInfo"></param>
/// <returns></returns> /// <returns></returns>
@ -646,15 +609,14 @@ namespace Aucma.Core.ProductOffLine.Business
return true; return true;
} }
/// <summary>
/// <summary> /// 将 TempInfo转换为OffLineInfo对象
/// 传入类型B的对象b将b与a相同名称的值进行赋值给创建的a中
/// </summary> /// </summary>
/// <typeparam name="A">类型A</typeparam> /// <typeparam name="A">类型A</typeparam>
/// <typeparam name="B">类型B</typeparam> /// <typeparam name="B">类型B</typeparam>
/// <param name="b">类型为B的参数b</param> /// <param name="b">类型为B的参数b</param>
/// <returns>拷贝b中相同属性的值的a</returns> /// <returns>拷贝b中相同属性的值的a</returns>
public OffLineInfo MapperTwo(TempInfo b) public OffLineInfo MapperTwo(TempInfo b)
{ {
OffLineInfo a = new OffLineInfo(); OffLineInfo a = new OffLineInfo();
try try
@ -684,6 +646,9 @@ namespace Aucma.Core.ProductOffLine.Business
} }
return a; return a;
} }
#endregion #endregion
} }
} }

@ -13,59 +13,120 @@ namespace Aucma.Core.ProductOffLine.Models
/// </summary> /// </summary>
public class TempInfo public class TempInfo
{ {
public int No { get; set; } //序号 /// <summary>
/// 序号
public string ProductFactoryCode { get; set; } //计划工厂 /// </summary>
public int No { get; set; }
public string ProductSNCode { get; set; } //公司条码 /// <summary>
/// //计划工厂
public string ProductOrderNo { get; set; }//工单号 /// </summary>
public string ProductFactoryCode { get; set; }
public string ProductSaleNo { get; set; } //销售订单号 /// <summary>
/// //公司条码
public string ProductSaleLineNo { get; set; } //销售行号 /// </summary>
public string ProductSNCode { get; set; }
public string ProductCode { get; set; }//物料编码 /// <summary>
/// //工单号
public string ProductModel { get; set; }//产品型号 /// </summary>
public string ProductOrderNo { get; set; }
public string ProductName { get; set; }//物料描述 /// <summary>
/// //销售订单号
public string ProductType { get; set; }//产品类型 /// </summary>
public string ProductSaleNo { get; set; }
public string ProductCheckInfo { get; set; }//验证组合 /// <summary>
/// //销售行号
public string ProductRemark { get; set; } //标签特征 /// </summary>
public string ProductSaleLineNo { get; set; }
public string ProductBarNo { get; set; }//产品条码编码 /// <summary>
/// //物料编码
public string ProductMasterModel { get; set; }//主型号 /// </summary>
public string ProductCode { get; set; }
public string ProductVersion { get; set; }//版本号 /// <summary>
/// //产品型号
public string ProductUseInfo { get; set; }//用途位 /// </summary>
public string ProductModel { get; set; }
/// <summary>
public string ProductCirculate { get; set; }//流通特性 /// //物料描述
/// </summary>
public string ProductCreateDate { get; set; }//生成日期 public string ProductName { get; set; }
/// <summary>
public DateTime ProductScanTime { get; set; } //扫描时间 /// //产品类型
/// </summary>
public string ProductType { get; set; }
/// <summary>
/// //验证组合
/// </summary>
public string ProductCheckInfo { get; set; }
/// <summary>
/// //标签特征
/// </summary>
public string ProductRemark { get; set; }
/// <summary>
/// //产品条码编码
/// </summary>
public string ProductBarNo { get; set; }
/// <summary>
/// //主型号
/// </summary>
public string ProductMasterModel { get; set; }
/// /// <summary>
/// //版本号
/// </summary>
public string ProductVersion { get; set; }
/// <summary>
/// //用途位
/// </summary>
public string ProductUseInfo { get; set; }
/// <summary>
/// //流通特性
/// </summary>
public string ProductCirculate { get; set; }
/// <summary>
/// //生成日期
/// </summary>
public string ProductCreateDate { get; set; }
/// <summary>
/// //扫描时间
/// </summary>
public DateTime ProductScanTime { get; set; }
/// <summary>
/// 刷新标志定时器检测true刷新
/// </summary>
public bool ProductRefreshFlag { get; set; } public bool ProductRefreshFlag { get; set; }
/// <summary>
/// 朗读标志1放行扫码成功2保存条码失败3条码验证失败
/// </summary>
public int ReadFlag { get; set; } public int ReadFlag { get; set; }
/// <summary>
/// 刷新页面信息标志
/// </summary>
public bool ProductDataFlag { get; set; } public bool ProductDataFlag { get; set; }
// 界面提示信息 /// <summary>
/// 界面提示信息
/// </summary>
public string MsgInfo { get; set; } public string MsgInfo { get; set; }
/// <summary>
/// 是否报警信息
/// </summary>
public bool MsgAlarmFlag { get; set; } public bool MsgAlarmFlag { get; set; }
/// <summary>
/// 订单计划数
/// </summary>
public int OrderQty { get; set; } public int OrderQty { get; set; }
/// <summary>
/// 已生产数量
/// </summary>
public int ActQty { get; set; } public int ActQty { get; set; }
public string oneCode { get; set; } public string oneCode { get; set; }
public string serialNumber { get; set; } public string serialNumber { get; set; }
public string rfid { get; set; } public string rfid { get; set; }
public string sim { get; set; } public string sim { get; set; }
public string number1 { get; set; } public string number1 { get; set; }
/// <summary>
/// 扫码重复是否允许放行,界面加选择栏
/// </summary>
public bool ChkOut { get; set; } public bool ChkOut { get; set; }
} }
} }

@ -45,78 +45,22 @@ namespace Aucma.Core.ProductOffLine.ViewModels
public partial class IndexPageViewModel : ObservableObject public partial class IndexPageViewModel : ObservableObject
{ {
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel)); private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel));
// 成品下线操作mes数据 // 成品下线操作mes数据
private readonly IOffLineInfoServices? _offLineInfoServices = App.ServiceProvider.GetService<IOffLineInfoServices>(); private readonly IOffLineInfoServices? _offLineInfoServices = App.ServiceProvider.GetService<IOffLineInfoServices>();
System.Timers.Timer timer = new System.Timers.Timer(1000);
private OffLineBusiness offLineBusiness = OffLineBusiness.Instance; private OffLineBusiness offLineBusiness = OffLineBusiness.Instance;
int a = 0; int a = 0;
public IndexPageViewModel() public IndexPageViewModel()
{ {
offLineBusiness.test(); offLineBusiness.test();
_offLineInfoServices = App.ServiceProvider.GetService<IOffLineInfoServices>(); _offLineInfoServices = App.ServiceProvider.GetService<IOffLineInfoServices>();
MvCodeHelper.ReceiveCodeEvent += ReceiveCode;
// test33(); // test33();
ReceiveCode("12345", 1);
StartPlcTimer();
InitEveryDayMethod(); InitEveryDayMethod();
}
/// <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 扫描信息 #region 扫描信息
#region 物料条码 #region 物料条码
@ -333,155 +277,8 @@ namespace Aucma.Core.ProductOffLine.ViewModels
} }
#endregion #endregion
/// <summary>
/// 扫描的条码处理
/// </summary>
/// <param name="code"></param>
/// <param name="direction">扫码器方向</param>
private async void ReceiveCode(string code, int scannerNo)
{
}
#region plc交互
private SemaphoreSlim semaphore = new SemaphoreSlim(0);
/// <summary>
/// 下发plc放行信号,根据接收到的scannerNo不同两条道的plc信号地址也不同
/// </summary>
/// <param name="materialType"></param>
private bool SendPlcPass(int scannerNo)
{
bool result = false;
try
{
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("成品下线Plc"));
if (obj != null)
{
if (obj.plc.IsConnected)
{
if (scannerNo == 1)
{
// 写入入库方向两条道plc地址不同
obj.plc.WriteInt32("D100", scannerNo);
// 往plc写入放行信号
obj.plc.WriteInt32("D102", 1);
}
else
{
// 写入入库方向两条道plc地址不同
obj.plc.WriteInt32("D200", scannerNo);
// 往plc写入放行信号
obj.plc.WriteInt32("D202", 1);
}
// 等待plc反馈信号
waitPlcSignal(scannerNo);
// semaphore.Wait();
result = true;
}
else
{
log.Info("成品下线plc连接失败请检查plc连接");
}
}
else
{
log.Info("获取plc连接对象信息为空");
}
}
catch (Exception ex)
{
log.Error("下发plc放行信号方法SendPlcPass()出现异常,ex:" + ex);
}
return result;
}
/// <summary>
/// 读取plc放行反馈
/// </summary>
/// <param name="materialType"></param>
private void waitPlcSignal(int scannerNo)
{
try
{
bool isFlag = true;
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("成品下线Plc"));
if (obj != null && obj.plc.IsConnected)
{
do
{
if (scannerNo == 1)
{
// 读取plc反馈信号
if (obj.plc.ReadInt32("D102") == 2)
{
Console.WriteLine("收到plc放行成功");
// 清空数据
obj.plc.WriteInt32("D100", 0);
obj.plc.WriteInt32("D102", 0);
isFlag = false;
}
}
else
{
// 读取plc反馈信号
if (obj.plc.ReadInt32("D202") == 2)
{
Console.WriteLine("收到plc放行成功");
// 清空数据
obj.plc.WriteInt32("D200", 0);
obj.plc.WriteInt32("D202", 0);
isFlag = false;
}
}
Thread.Sleep(1000);
} while (isFlag);
// 释放信号量
//semaphore.Release();
}
else
{
log.Info("成品下线plc连接失败");
}
}
catch (Exception ex)
{
log.Error("读取plc放行反馈方法waitPlcSignal()出现异常,ex:" + ex);
}
}
/// <summary>
/// 下发plc报警信号
/// </summary>
private void sendPlcError()
{
try
{
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("成品下线Plc"));
if (obj != null)
{
if (obj.plc.IsConnected)
{
// 下发报警信号
obj.plc.WriteInt32("D104", 1);
}
else
{
log.Info("成品下线plc连接失败请检查plc连接");
}
}
else
{
log.Info("获取plc连接对象信息为空");
}
}
catch (Exception ex)
{
log.Error("下发plc放报警信号方法sendPlcError()出现异常,ex:" + ex);
}
}
#endregion
} }
} }

@ -300,8 +300,8 @@
<Border Grid.Row="2"> <Border Grid.Row="2">
<DataGrid Grid.Row="0" ItemsSource="{Binding ListItems}" ColumnHeaderHeight="35" Height="{Binding Path=ActualHeight, ElementName=ScanPanel}" <DataGrid Grid.Row="0" ItemsSource="{Binding ListItems}" ColumnHeaderHeight="35" Height="{Binding Path=ActualHeight, ElementName=ScanPanel}"
RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0" RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto" GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Auto" BorderThickness="0" CanUserAddRows="False" SelectionMode="Single" IsReadOnly="True" ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderThickness="0" CanUserAddRows="False" SelectionMode="Single" IsReadOnly="True"
Foreground="White" > Foreground="White" >
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn Binding="{Binding No}" Header="序号" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/> <DataGridTextColumn Binding="{Binding No}" Header="序号" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>

@ -6,7 +6,7 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d" mc:Ignorable="d"
Title="SCADA" Height="1080" Width="1920" Icon="/Assets/images/Icon.png" Title="SCADA" Height="1080" Width="1920" Icon="/Assets/images/Icon.png"
WindowState="Maximized" WindowStyle="SingleBorderWindow" ResizeMode="CanResize" Topmost="True"> WindowState="Maximized" WindowStyle="SingleBorderWindow" ResizeMode="CanResize">
<Window.Background> <Window.Background>
<ImageBrush ImageSource="/Assets/images/background.jpg" /> <ImageBrush ImageSource="/Assets/images/background.jpg" />
</Window.Background> </Window.Background>

@ -187,7 +187,7 @@ namespace Aucma.Core.Scanner
} }
#endregion #endregion
#region 开启扫描 #region 开启扫描 取消使用
public static void StartGrab1() public static void StartGrab1()
{ {
try try
@ -321,8 +321,7 @@ namespace Aucma.Core.Scanner
if (!string.IsNullOrEmpty(strCode)) if (!string.IsNullOrEmpty(strCode))
{ {
// 获取到条码处理业务 // 获取到条码处理业务
Console.WriteLine(strCode,hashmap.Value);
Console.WriteLine(strCode);
} }
} }

Loading…
Cancel
Save