From bdbc8b1459c415f24c3a5da0d27a05e034f7ba08 Mon Sep 17 00:00:00 2001
From: kingno <30263@KINGNO>
Date: 星期六, 19 七月 2025 17:02:46 +0800
Subject: [PATCH] mes优化
---
src/Bro.M141.Process/MyMQTT.cs | 16 +
src/Bro.M141.Process/UI/UIPrinter.cs | 2
src/Bro.M141.Process/M141Process_Mysql.cs | 21 +--
src/Bro.M135.DBManager/Models/P_PRODUCT.cs | 2
src/Bro.M141.Process/M141Process.cs | 166 +++++++++++++++++++++--
src/Bro.M141.Process/M141Process_ImageCheck.cs | 196 ++++++++++++++--------------
6 files changed, 273 insertions(+), 130 deletions(-)
diff --git a/src/Bro.M135.DBManager/Models/P_PRODUCT.cs b/src/Bro.M135.DBManager/Models/P_PRODUCT.cs
index 659c26e..d9736a3 100644
--- a/src/Bro.M135.DBManager/Models/P_PRODUCT.cs
+++ b/src/Bro.M135.DBManager/Models/P_PRODUCT.cs
@@ -14,6 +14,8 @@
public string BasketCode { get; set; } = "NOREAD";
+ public string Zword { get; set; } = "NOREAD";
+
public string Result { get; set; } = "";
[NotMapped]
diff --git a/src/Bro.M141.Process/M141Process.cs b/src/Bro.M141.Process/M141Process.cs
index 21f4dc8..8a3bd16 100644
--- a/src/Bro.M141.Process/M141Process.cs
+++ b/src/Bro.M141.Process/M141Process.cs
@@ -98,9 +98,6 @@
-
-
-
public override void Open()
{
base.Open();
@@ -1064,10 +1061,12 @@
if (M141Config.Isreadbasketcode)
{
p.BasketCode = M141Config.basketcode;
+ p.Zword = M141Config.zwoid;
}
else
{
- p.BasketCode = mysqlhelper.Getbasketcode(p.SEQUENCE, out string sntem);
+ p.BasketCode = mysqlhelper.Getbasketcode(p.SEQUENCE, out string sntem, out string zword);
+ p.Zword = zword;
p.SN = sntem;
p.PID = $"{sntem}_{i}";
if ("NoRead".Equals(p.BasketCode))
@@ -1231,17 +1230,7 @@
}
}
});
- //ReplyPlcData(positionSet, plcresult);
- if (positionSet.IsLastPosition)
- {
- if (_ct != null)
- {
- UpdateCT(null, (float)((DateTime.Now - _ct.Value).TotalSeconds));
- }
- _ct = DateTime.Now;
- }
- //ReplyPlcData(positionName, config.TriggerValue);
cameraIds.ForEach(c =>
{
@@ -1252,6 +1241,154 @@
LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鐩告満{camera.Name}娓呯悊缂撳瓨");
}
});
+
+ //ReplyPlcData(positionSet, plcresult);
+ if (positionSet.IsLastPosition)
+ {
+ if (_ct != null)
+ {
+ UpdateCT(null, (float)((DateTime.Now - _ct.Value).TotalSeconds));
+ }
+ _ct = DateTime.Now;
+
+ if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1))
+ {
+ if (M141Config.numpro >= 50)
+ {
+ M141Config.numpro = 0;
+ }
+
+ if (pList[0].Result == "OK")
+ {
+ M141Config.numpro++;
+ }
+
+ //mqtt.demes(productList[0], M141Config.zwoid);
+ string Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(pList[0], M141Config.numpro)).Result;
+ if (Msgreceice == null)
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES寮傚父 杩斿洖鏁版嵁涓簄ull");
+ }
+ else
+ {
+ try
+ {
+ var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(Msgreceice);
+
+ if (obj.zstatus == "200")
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES鎴愬姛 {Msgreceice}");
+ }
+ else
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES澶辫触 {Msgreceice}");
+ }
+ }
+ catch
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES寮傚父 {Msgreceice}");
+ }
+ }
+
+
+
+ int numplca = Convert.ToInt32(pList[0].SEQUENCE.Split('_')[0]);
+
+
+ lock (plcnumlock)
+ {
+ if (PlcNumForAll == -1)
+ {
+ PlcNumForAll = numplca;
+ }
+ int differ = numplca - PlcNumForAll;
+ if (differ > 1)
+ {
+ for (int i = PlcNumForAll + 1; i < numplca; i++)
+ {
+ try
+ {
+ var plist = mysqlhelper.GetProductList(i + "_1");
+ ProductModel newp = new ProductModel();
+ newp.SEQUENCE = plist[0].SEQUENCE;
+ newp.PID = plist[0].PID;
+ newp.BasketCode = plist[0].BasketCode;
+ newp.Zword = plist[0].Zword;
+ newp.Result = "NG";
+ newp.SN = plist[0].SN;
+ var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.numpro)).Result;
+
+ }
+ catch
+ {
+
+ }
+ }
+ }
+ else if (differ == -29998 && differ == 1 && differ == 0)
+ {
+
+
+ }
+ else
+ {
+ for (int i = PlcNumForAll + 1; i <= 29999; i++)
+ {
+ try
+ {
+ var plist = mysqlhelper.GetProductList(i + "_1");
+ ProductModel newp = new ProductModel();
+ newp.SEQUENCE = plist[0].SEQUENCE;
+ newp.PID = plist[0].PID;
+ newp.Zword = plist[0].Zword;
+ newp.BasketCode = plist[0].BasketCode;
+ newp.Result = "NG";
+ newp.SN = plist[0].SN;
+ var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.numpro)).Result;
+
+ }
+ catch
+ {
+
+ }
+ }
+
+
+
+ for (int i = 1; i < numplca; i++)
+ {
+ try
+ {
+ var plist = mysqlhelper.GetProductList(i + "_1");
+ ProductModel newp = new ProductModel();
+ newp.SEQUENCE = plist[0].SEQUENCE;
+ newp.PID = plist[0].PID;
+ newp.BasketCode = plist[0].BasketCode;
+ newp.Zword = plist[0].Zword;
+ newp.Result = "NG";
+ newp.SN = plist[0].SN;
+ var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.numpro)).Result;
+
+ }
+ catch
+ {
+
+ }
+ }
+ }
+
+
+
+ PlcNumForAll = numplca;
+ }
+
+ }
+
+ }
+
+ //ReplyPlcData(positionName, config.TriggerValue);
+
+
return pList;
@@ -1287,6 +1424,7 @@
newp.SEQUENCE = p.SEQUENCE;
newp.PID = p.PID;
newp.BasketCode = p.BasketCode;
+ newp.Zword = p.Zword;
newp.Result = p.Result;
newp.SN = p.SN;
diff --git a/src/Bro.M141.Process/M141Process_ImageCheck.cs b/src/Bro.M141.Process/M141Process_ImageCheck.cs
index 6eb5b46..8f18247 100644
--- a/src/Bro.M141.Process/M141Process_ImageCheck.cs
+++ b/src/Bro.M141.Process/M141Process_ImageCheck.cs
@@ -502,122 +502,122 @@
Plc1.WriteSingleAddress(1516, 1, out _);
- if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1))
- {
- if (M141Config.numpro >= 50)
- {
- M141Config.numpro = 0;
- }
+ //if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1))
+ //{
+ // if (M141Config.numpro >= 50)
+ // {
+ // M141Config.numpro = 0;
+ // }
- if (productList[0].Result == "OK")
- {
- M141Config.numpro++;
- }
+ // if (productList[0].Result == "OK")
+ // {
+ // M141Config.numpro++;
+ // }
- //mqtt.demes(productList[0], M141Config.zwoid);
- string Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(productList[0], M141Config.zwoid, M141Config.numpro)).Result;
- if (Msgreceice == null)
- {
- LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES寮傚父 杩斿洖鏁版嵁涓簄ull");
- }
- else
- {
- try
- {
- var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(Msgreceice);
+ // //mqtt.demes(productList[0], M141Config.zwoid);
+ // string Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(productList[0], M141Config.zwoid, M141Config.numpro)).Result;
+ // if (Msgreceice == null)
+ // {
+ // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES寮傚父 杩斿洖鏁版嵁涓簄ull");
+ // }
+ // else
+ // {
+ // try
+ // {
+ // var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(Msgreceice);
- if (obj.zstatus == "200")
- {
- LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES鎴愬姛 {Msgreceice}");
- }
- else
- {
- LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES澶辫触 {Msgreceice}");
- }
- }
- catch
- {
- LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES寮傚父 {Msgreceice}");
- }
- }
+ // if (obj.zstatus == "200")
+ // {
+ // LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES鎴愬姛 {Msgreceice}");
+ // }
+ // else
+ // {
+ // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES澶辫触 {Msgreceice}");
+ // }
+ // }
+ // catch
+ // {
+ // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES寮傚父 {Msgreceice}");
+ // }
+ // }
- lock (plcnumlock)
- {
- int differ = numplca - PlcNumForAll;
- if (differ > 1)
- {
- for (int i = PlcNumForAll + 1; i < numplca; i++)
- {
- try
- {
- var plist = mysqlhelper.GetProductList(i + "_1");
- ProductModel newp = new ProductModel();
- newp.SEQUENCE = plist[0].SEQUENCE;
- newp.PID = plist[0].PID;
- newp.BasketCode = plist[0].BasketCode;
- newp.Result = "NG";
- newp.SN = plist[0].SN;
- var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
+ // lock (plcnumlock)
+ // {
+ // int differ = numplca - PlcNumForAll;
+ // if (differ > 1)
+ // {
+ // for (int i = PlcNumForAll + 1; i < numplca; i++)
+ // {
+ // try
+ // {
+ // var plist = mysqlhelper.GetProductList(i + "_1");
+ // ProductModel newp = new ProductModel();
+ // newp.SEQUENCE = plist[0].SEQUENCE;
+ // newp.PID = plist[0].PID;
+ // newp.BasketCode = plist[0].BasketCode;
+ // newp.Result = "NG";
+ // newp.SN = plist[0].SN;
+ // var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
- }
- catch
- {
+ // }
+ // catch
+ // {
- }
- }
- }
- else if (differ != -29998)
- {
- for (int i = PlcNumForAll + 1; i <= 29999; i++)
- {
- try
- {
- var plist = mysqlhelper.GetProductList(i + "_1");
- ProductModel newp = new ProductModel();
- newp.SEQUENCE = plist[0].SEQUENCE;
- newp.PID = plist[0].PID;
- newp.BasketCode = plist[0].BasketCode;
- newp.Result = "NG";
- newp.SN = plist[0].SN;
- var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
+ // }
+ // }
+ // }
+ // else if (differ != -29998)
+ // {
+ // for (int i = PlcNumForAll + 1; i <= 29999; i++)
+ // {
+ // try
+ // {
+ // var plist = mysqlhelper.GetProductList(i + "_1");
+ // ProductModel newp = new ProductModel();
+ // newp.SEQUENCE = plist[0].SEQUENCE;
+ // newp.PID = plist[0].PID;
+ // newp.BasketCode = plist[0].BasketCode;
+ // newp.Result = "NG";
+ // newp.SN = plist[0].SN;
+ // var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
- }
- catch
- {
+ // }
+ // catch
+ // {
- }
- }
+ // }
+ // }
- for (int i = 1; i < numplca; i++)
- {
- try
- {
- var plist = mysqlhelper.GetProductList(i + "_1");
- ProductModel newp = new ProductModel();
- newp.SEQUENCE = plist[0].SEQUENCE;
- newp.PID = plist[0].PID;
- newp.BasketCode = plist[0].BasketCode;
- newp.Result = "NG";
- newp.SN = plist[0].SN;
- var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
+ // for (int i = 1; i < numplca; i++)
+ // {
+ // try
+ // {
+ // var plist = mysqlhelper.GetProductList(i + "_1");
+ // ProductModel newp = new ProductModel();
+ // newp.SEQUENCE = plist[0].SEQUENCE;
+ // newp.PID = plist[0].PID;
+ // newp.BasketCode = plist[0].BasketCode;
+ // newp.Result = "NG";
+ // newp.SN = plist[0].SN;
+ // var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
- }
- catch
- {
+ // }
+ // catch
+ // {
- }
- }
+ // }
+ // }
- }
- PlcNumForAll = numplca;
- }
+ // }
+ // PlcNumForAll = numplca;
+ // }
- }
+ //}
return msg;
}
diff --git a/src/Bro.M141.Process/M141Process_Mysql.cs b/src/Bro.M141.Process/M141Process_Mysql.cs
index bb67d25..ae1408c 100644
--- a/src/Bro.M141.Process/M141Process_Mysql.cs
+++ b/src/Bro.M141.Process/M141Process_Mysql.cs
@@ -23,10 +23,8 @@
{
public class M141Process_Mysql
{
-
string connStrAll = "server=localhost;port=3306;user id=root;password=123456;database=BroDB;charset=utf8";
string connStrLocal = "server=localhost;port=3306;user id=root;password=123456;database=BroDB;charset=utf8";
-
#region 鍩虹鎿嶄綔
public void IniDBIP(string IP)
@@ -107,7 +105,6 @@
}
#endregion
-
public void NewProduct(ProductModel pro)
@@ -290,7 +287,7 @@
Operatoremysql(str2, connStrAll);
}
- string mysqlstr = $"insert into forall (basketcode,device,plcnum,sn,data,time) values('{pro.BasketCode}','{devicestr}','{pro.SEQUENCE}','{pro.SN}','{JsonConvert.SerializeObject(pro, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All })}','{DateTime.Now.ToString("yyyyMMddHHmmss")}')";
+ string mysqlstr = $"insert into forall (basketcode,zword,device,plcnum,sn,data,time) values('{pro.BasketCode}','{pro.Zword}','{devicestr}','{pro.SEQUENCE}','{pro.SN}','{JsonConvert.SerializeObject(pro, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All })}','{DateTime.Now.ToString("yyyyMMddHHmmss")}')";
if (Operatoremysql(mysqlstr, connStrAll))
{
@@ -334,7 +331,6 @@
return null;
}
-
public List<Netdefectdetail> GetNetdefectdetails(string plcnum)
{
try
@@ -373,8 +369,8 @@
{
ProductModel p = null;
p = JsonConvert.DeserializeObject<ProductModel>(str, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All });
-
- return p.Result=="OK";
+
+ return p.Result == "OK";
}
}
catch (Exception e)
@@ -384,13 +380,13 @@
return false;
}
-
- public string Getbasketcode(string plcnum, out string sn)
+ public string Getbasketcode(string plcnum, out string sn, out string zword)
{
sn = "Noread";
+ zword = "Noread";
try
{
- string mysqlstr = $"select basketcode,sn from forall where plcnum='{plcnum}' && device='S2' order by id desc limit 1";
+ string mysqlstr = $"select basketcode,sn,zword from forall where plcnum='{plcnum}' && device='S2' order by id desc limit 1";
var dt = selectdt(mysqlstr, connStrAll);
if (dt == null || dt.Rows.Count == 0)
{
@@ -399,6 +395,7 @@
else
{
sn = dt.Rows[0][1].ToString();
+ zword = dt.Rows[0][2].ToString();
return dt.Rows[0][0].ToString();
}
}
@@ -408,7 +405,6 @@
}
return "NoRead";
}
-
public List<ProductModel> GetProductList(string plcnum)
{
@@ -442,8 +438,6 @@
return null;
}
-
-
public DataTable getBasketCode()
{
try
@@ -468,7 +462,6 @@
}
-
public void NewBasketcode(string code)
{
diff --git a/src/Bro.M141.Process/MyMQTT.cs b/src/Bro.M141.Process/MyMQTT.cs
index 78ce1c3..53a5f75 100644
--- a/src/Bro.M141.Process/MyMQTT.cs
+++ b/src/Bro.M141.Process/MyMQTT.cs
@@ -15,6 +15,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using ZXing;
namespace Bro.M141.Process
{
@@ -167,12 +168,21 @@
}
}
- public async Task<string> MESForProduceAsync(ProductModel pro, string zwoid, int znonum, string endtray = "N", string line = "NQ216", int timeoutMs = 3000)
+ public async Task<string> MESForProduceAsync(ProductModel pro, int znonum, string endtray = "N", string line = "NQ216", int timeoutMs = 3000)
{
var guid = Guid.NewGuid().ToString();
var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
_pendingTask2[guid] = tcs;
+ string zresult = "OK";
+ if (string.IsNullOrWhiteSpace(pro.Result))
+ {
+ zresult = "NG";
+ }
+ else if (!"OK".Equals(pro.Result))
+ {
+ zresult = "NG";
+ }
var msgObj = new AutoLineMacBarcodeQueue
{
@@ -180,10 +190,10 @@
zdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"),
zline = line,
zbarcode = pro.SN,
- zresult = string.IsNullOrWhiteSpace(pro.Result) ? "NG" : pro.Result,
+ zresult = zresult,
zreson = pro.Result == "OK" ? "" : "SZ2014",
zno = znonum.ToString(),
- zwoid = zwoid,
+ zwoid = pro.Zword,
endtray = endtray
};
diff --git a/src/Bro.M141.Process/UI/UIPrinter.cs b/src/Bro.M141.Process/UI/UIPrinter.cs
index 48040be..a9cf2d7 100644
--- a/src/Bro.M141.Process/UI/UIPrinter.cs
+++ b/src/Bro.M141.Process/UI/UIPrinter.cs
@@ -669,7 +669,7 @@
int pronum = 0;
private void button6_Click(object sender, EventArgs e)//sn,result,zword,zno,entray
{
- string Msg = Task.Run(() => Process141.mqtt.MESForProduceAsync(new ProductModel() { SN = textBox3.Text, Result = textBox4.Text }, textBox5.Text, Convert.ToInt32(textBox6.Text), textBox7.Text)).Result;
+ string Msg = Task.Run(() => Process141.mqtt.MESForProduceAsync(new ProductModel() { SN = textBox3.Text, Result = textBox4.Text ,Zword= textBox5.Text }, Convert.ToInt32(textBox6.Text), textBox7.Text)).Result;
if (Msg == null)
{
CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 鐗╂枡 杩斿洖鏁版嵁涓� null");
--
Gitblit v1.8.0