修改Mes逻辑

This commit is contained in:
YZJ 2024-07-09 16:56:45 +08:00
parent 19da00146e
commit ca2403b323
4 changed files with 281 additions and 399 deletions

File diff suppressed because it is too large Load Diff

View File

@ -342,37 +342,37 @@ namespace HisenceYoloDetection
{ {
//报警地址 //报警地址
//string url = "https://inner-apisix.hisense.com/mes-plus/api/Fcc/GetWorkOrderBOMlnfo?user_key=k7gzo1fsfcami7n5hmpxtybyluf9xeue"; //string url = "https://inner-apisix.hisense.com/mes-plus/api/Fcc/GetWorkOrderBOMlnfo?user_key=k7gzo1fsfcami7n5hmpxtybyluf9xeue";
string url = "https://echo.hoppscotch.io"; ////string url = "https://echo.hoppscotch.io";
string PostUrl = url; //string PostUrl = url;
DateTime dt= DateTime.Now; //DateTime dt= DateTime.Now;
string starttime=string.Format("{0:yyyy_mm_dd}", dt); //17 17 2017 2017 //string starttime=string.Format("{0:yyyy_mm_dd}", dt); //17 17 2017 2017
string startTime = starttime; //string startTime = starttime;
string EndTime = starttime; //string EndTime = starttime;
string lineBody = "ZZ-P"; //string lineBody = "ZZ-P";
string MaterialDescripts = "制冷器"; //string MaterialDescripts = "制冷器";
string MaterialDescripts2 = "工艺管"; //string MaterialDescripts2 = "工艺管";
JObject patientinfo = new JObject(); //JObject patientinfo = new JObject();
JArray ids = new JArray(); //JArray ids = new JArray();
ids.Add(MaterialDescripts); //ids.Add(MaterialDescripts);
ids.Add(MaterialDescripts2); //ids.Add(MaterialDescripts2);
patientinfo["startTime"] = startTime; //patientinfo["startTime"] = startTime;
patientinfo["EndTime"] = EndTime; //patientinfo["EndTime"] = EndTime;
patientinfo["lineBody"] = lineBody; //patientinfo["lineBody"] = lineBody;
patientinfo["MaterialDescripts"] = ids; //patientinfo["MaterialDescripts"] = ids;
string sendData = JsonConvert.SerializeObject(patientinfo); //string sendData = JsonConvert.SerializeObject(patientinfo);
//eg: 发送Url需要的格式sendData={"ids":[123],"Name":小黑} ////eg: 发送Url需要的格式sendData={"ids":[123],"Name":小黑}
string resultData = Post(sendData, PostUrl); //string resultData = Post(sendData, PostUrl);
resultData = "{\r\n\t\"Result\": [],\r\n\t\"success\": false,\r\n\t\"ReturnMsg\": \"参数-starttime 不正确!\"\r\n}"; //resultData = "{\r\n\t\"Result\": [],\r\n\t\"success\": false,\r\n\t\"ReturnMsg\": \"参数-starttime 不正确!\"\r\n}";
JObject jo = (JObject)JsonConvert.DeserializeObject(resultData); //JObject jo = (JObject)JsonConvert.DeserializeObject(resultData);
string sucessIf = jo["success"].ToString(); //string sucessIf = jo["success"].ToString();
if(sucessIf.ToLower()=="true") //if(sucessIf.ToLower()=="true")
{ //{
string ProductType = jo["ProductType"].ToString(); // string ProductType = jo["ProductType"].ToString();
string FinalDefIo = jo["FinalDefIo"].ToString(); // string FinalDefIo = jo["FinalDefIo"].ToString();
//解析字段 // //解析字段
} //}
if (_runHandleBefore == null) if (_runHandleBefore == null)
{ {
_runHandleBefore = new AutoResetEvent(false); _runHandleBefore = new AutoResetEvent(false);
@ -1182,8 +1182,7 @@ namespace HisenceYoloDetection
{ {
_runHandleBefore.WaitOne(); _runHandleBefore.WaitOne();
//这里改成和海信的对接需求 //这里改成和海信的对接需求
#if false
// if(Oldm_sKEYENCEBar!= m_sKEYENCEBar)
{ {
// Oldm_sKEYENCEBar= m_sKEYENCEBar; // Oldm_sKEYENCEBar= m_sKEYENCEBar;
//获取请求 //获取请求
@ -1223,10 +1222,13 @@ namespace HisenceYoloDetection
//解析字段 //解析字段
} }
} }
//xKNow = GetModeFromBar("VWJ070633V0WW80F0120356");//从数据库中查询到这个条码的四轴的值 #endif
// if(Oldm_sKEYENCEBar!= m_sKEYENCEBar)
xKNow = GetModeFromBar("VWJ070541V0WW824F120223");//从数据库中查询到这个条码的四轴的值
if(xKNow==null) if (xKNow==null)
{ {
myLog("数据库没有条码匹配" + m_sKEYENCEBar, DateTime.Now); myLog("数据库没有条码匹配" + m_sKEYENCEBar, DateTime.Now);
break; break;
@ -1288,8 +1290,8 @@ namespace HisenceYoloDetection
// var resultMap = GetResultImage(resultMask, detectionResultShapes); // var resultMap = GetResultImage(resultMask, detectionResultShapes);
} }
#endregion #endregion
int YPos = 8715; int YPos = 14957;
int ZPos = 25000; int ZPos = 4382;
bool StopM = false;//第一次用信号挡 bool StopM = false;//第一次用信号挡
/// <summary> /// <summary>
/// 监听洗衣机544是否触发后面对射传感器 相机 /// 监听洗衣机544是否触发后面对射传感器 相机
@ -1337,6 +1339,77 @@ namespace HisenceYoloDetection
} }
if (iNum1 >= 2) if (iNum1 >= 2)
{ {
if (bBar)
{
_runHandleBefore.WaitOne();
//这里改成和海信的对接需求
#if false
{
// Oldm_sKEYENCEBar= m_sKEYENCEBar;
//获取请求
//报警地址
string url = "https://inner-apisix.hisense.com/mes-plus/api/Fcc/GetWorkOrderBOMlnfo?user_key=k7gzo1fsfcami7n5hmpxtybyluf9xeue";
// string url = "https://echo.hoppscotch.io";
string PostUrl = url;
DateTime dt = DateTime.Now;
string starttime = string.Format("{0:yyyy_mm_dd}", dt); //17 17 2017 2017
string startTime = starttime;
string EndTime = starttime;
string lineBody = "ZZ-P";//线体
string MaterialDescripts = "制冷器";
string MaterialDescripts2 = "工艺管";
JObject patientinfo = new JObject();
JArray ids = new JArray();
ids.Add(MaterialDescripts);
ids.Add(MaterialDescripts2);
patientinfo["startTime"] = startTime;
patientinfo["EndTime"] = EndTime;
patientinfo["lineBody"] = lineBody;
patientinfo["MaterialDescripts"] = ids;
string sendData = JsonConvert.SerializeObject(patientinfo);
//eg: 发送Url需要的格式sendData={"ids":[123],"Name":小黑}
string resultData = Post(sendData, PostUrl);
resultData = "{\r\n\t\"Result\": [],\r\n\t\"success\": false,\r\n\t\"ReturnMsg\": \"参数-starttime 不正确!\"\r\n}";
JObject jo = (JObject)JsonConvert.DeserializeObject(resultData);
string sucessIf = jo["success"].ToString();
if (sucessIf.ToLower() == "true")
{
string ProductType = jo["ProductType"].ToString();
string FinalDefIo = jo["FinalDefIo"].ToString();
//WEBAPI得到条码
xKNow = GetModeFromBar(ProductType);//从数据库中查询到这个条码的四轴的值
//解析字段
}
}
#endif
// if(Oldm_sKEYENCEBar!= m_sKEYENCEBar)
xKNow = GetModeFromBar("VWJ070541V0WW824F120223");//从数据库中查询到这个条码的四轴的值
if (xKNow == null)
{
myLog("数据库没有条码匹配" + m_sKEYENCEBar, DateTime.Now);
break;
}
//if(xKNow.OcrBar!= Old_xKNow.OcrBar)
//{
//}
if (Regex.IsMatch(xKNow.MoveX.ToString(), @"^[0-9]+$") && Regex.IsMatch(xKNow.MoveY.ToString(), @"^[0-9]+$") && Regex.IsMatch(xKNow.MoveZ.ToString(), @"^[0-9]+$"))
{
// Old_xKNow = xKNow;
myLog("型号匹配成功" + xKNow.OcrBar, DateTime.Now);
bBarTriger = true;
//MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);// PLC控制电机移动四轴
}
break;
}
Thread.Sleep(2);
bBar = false;
#if true #if true
if (bBarTriger)//证明读码器读到东西 if (bBarTriger)//证明读码器读到东西
@ -1381,15 +1454,15 @@ namespace HisenceYoloDetection
//Cam2.SnapshotCount = 0; //Cam2.SnapshotCount = 0;
//Cam2.Snapshot(); //Cam2.Snapshot();
myLog("第二次采集图像", DateTime.Now); //myLog("第二次采集图像", DateTime.Now);
//if (xKNow != null) //if (xKNow != null)
//{ //{
// MoveToP(xKNow.MoveTwoX, xKNow.MoveTwoY, xKNow.MoveTwoZ); // MoveToP(xKNow.MoveTwoX, xKNow.MoveTwoY, xKNow.MoveTwoZ);
//} //}
MoveToP(51043, YPos, ZPos + (int)(dismove)); // MoveToP(51043, YPos, ZPos + (int)(dismove));
Cam1.Snapshot(); //Cam1.Snapshot();
MoveToP(5815, YPos, ZPos); MoveToP(5815, YPos, ZPos);
melsecPLCTCPDriver.WriteInt("550", 0);//方行 melsecPLCTCPDriver.WriteInt("550", 0);//方行
//Thread.Sleep(300);//洗衣机可能过不去 //Thread.Sleep(300);//洗衣机可能过不去
@ -1541,7 +1614,7 @@ namespace HisenceYoloDetection
//Cam1ImgTwo = cameraMat; //Cam1ImgTwo = cameraMat;
IfCam1TwoTriger = true; IfCam1TwoTriger = true;
originMatShow2.Image = cameraMat.ToBitmap(); //originMatShow2.Image = cameraMat.ToBitmap();
_runHandleAfter.Set(); _runHandleAfter.Set();
} }
@ -1569,7 +1642,7 @@ namespace HisenceYoloDetection
Cam2ImgShowBar = cameraMat; Cam2ImgShowBar = cameraMat;
IfCam2Triger = true; IfCam2Triger = true;
originMat2Show.Image = cameraMat.ToBitmap(); //originMat2Show.Image = cameraMat.ToBitmap();
//_runHandleAfter.Set(); //_runHandleAfter.Set();
// CamShow2.ImaMAt = cameraMat; // CamShow2.ImaMAt = cameraMat;
cameraMat.ImWrite(fitImageFolder + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1.jpg"); cameraMat.ImWrite(fitImageFolder + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1.jpg");
@ -1709,26 +1782,26 @@ namespace HisenceYoloDetection
} }
//进行推理 ////进行推理
MLRequest req2 = new MLRequest(); //MLRequest req2 = new MLRequest();
req2.currentMat = Cam1ImgTwo; //req2.currentMat = Cam1ImgTwo;
req2.ResizeWidth = 640; //req2.ResizeWidth = 640;
req2.ResizeHeight = 640; //req2.ResizeHeight = 640;
req2.Score = 0.3f; //req2.Score = 0.3f;
req2.in_lable_path = LablePath;//标签路径 //req2.in_lable_path = LablePath;//标签路径
req2.confThreshold = 0.3f;//模型置信度 //req2.confThreshold = 0.3f;//模型置信度
req2.iouThreshold = 0.4f;//检测IOU //req2.iouThreshold = 0.4f;//检测IOU
req2.out_node_name = "output"; //req2.out_node_name = "output";
MLResult mL2 = simboObjectDetection.RunInferenceFixed(req2); //MLResult mL2 = simboObjectDetection.RunInferenceFixed(req2);
if (mL2.ResultMap != null) //if (mL2.ResultMap != null)
{ //{
mL2.ResultMap.Save("D://cam1//" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "2result.jpg"); // mL2.ResultMap.Save("D://cam1//" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "2result.jpg");
ResultMatShow2.Image = mL2.ResultMap; // ResultMatShow2.Image = mL2.ResultMap;
} //}
List<string> strMatListTwo = new List<string>(); List<string> strMatListTwo = new List<string>();
List<string> strMatFuzzyListTwo = new List<string>(); List<string> strMatFuzzyListTwo = new List<string>();
Mat mResultCut2 = req2.currentMat.Clone(); // Mat mResultCut2 = req2.currentMat.Clone();
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>(); Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>(); Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>();
#region #region
@ -1736,10 +1809,10 @@ namespace HisenceYoloDetection
string[] listLabels = xKNow.Detect.Split(","); string[] listLabels = xKNow.Detect.Split(",");
MLResult MLsum = mL; MLResult MLsum = mL;
for (int i = 0; i < mL2.ResultDetails.Count; i++) //for (int i = 0; i < mL2.ResultDetails.Count; i++)
{ //{
MLsum.ResultDetails.Add((DetectionResultDetail)mL2.ResultDetails[i]); // MLsum.ResultDetails.Add((DetectionResultDetail)mL2.ResultDetails[i]);
} //}
string[] RealLabels = new string[MLsum.ResultDetails.Count]; string[] RealLabels = new string[MLsum.ResultDetails.Count];
string detstr = ""; string detstr = "";
for (int i = 0; i < MLsum.ResultDetails.Count; i++) for (int i = 0; i < MLsum.ResultDetails.Count; i++)
@ -1770,7 +1843,7 @@ namespace HisenceYoloDetection
InsertSqlRunDataButton(ref keyValueResult, false, ref mResultCut, mL, mLButton, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel); InsertSqlRunDataButton(ref keyValueResult, false, ref mResultCut, mL, mLButton, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
InsertSqlRunData(ref keyValueResult2, false, ref mResultCut2, mL2, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel); // InsertSqlRunData(ref keyValueResult2, false, ref mResultCut2, mL2, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel);
sw.Stop(); sw.Stop();
myLog("插入面板时间" + sw.ElapsedMilliseconds, DateTime.Now); myLog("插入面板时间" + sw.ElapsedMilliseconds, DateTime.Now);
@ -2133,7 +2206,7 @@ namespace HisenceYoloDetection
CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect2, rect2, false, "D://Hisence//Test1"); CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect2, rect2, false, "D://Hisence//Test1");
*/ */
OnGetBar(); // OnGetBar();
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//黄灯 melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//黄灯
TriggerCameral2(); TriggerCameral2();
ReadyDetect(); ReadyDetect();
@ -2538,36 +2611,36 @@ namespace HisenceYoloDetection
MLRequest CamTwoI = new MLRequest(); //MLRequest CamTwoI = new MLRequest();
CamTwoI.currentMat = Cv2.ImRead(Cam1TwoPath); //CamTwoI.currentMat = Cv2.ImRead(Cam1TwoPath);
CamTwoI.ResizeWidth = 640; //CamTwoI.ResizeWidth = 640;
CamTwoI.ResizeHeight = 640; //CamTwoI.ResizeHeight = 640;
CamTwoI.Score = 0.3f; //CamTwoI.Score = 0.3f;
CamTwoI.in_lable_path = LablePath;//标签路径 //CamTwoI.in_lable_path = LablePath;//标签路径
CamTwoI.confThreshold = 0.3f;//模型置信度 //CamTwoI.confThreshold = 0.3f;//模型置信度
CamTwoI.iouThreshold = 0.4f;//检测IOU //CamTwoI.iouThreshold = 0.4f;//检测IOU
CamTwoI.out_node_name = "output"; //CamTwoI.out_node_name = "output";
MLResult mL4 = simboObjectDetection.RunInferenceFixed(CamTwoI); //MLResult mL4 = simboObjectDetection.RunInferenceFixed(CamTwoI);
//if (mL4.IsSuccess) ////if (mL4.IsSuccess)
//{ ////{
// DateTime dt = DateTime.Now; //// DateTime dt = DateTime.Now;
// mL4.ResultMap.Save("D:\\Hisence\\detImages\\" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "2result.jpg"); //// mL4.ResultMap.Save("D:\\Hisence\\detImages\\" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "2result.jpg");
//} ////}
List<string> strMatListTwo = new List<string>(); //List<string> strMatListTwo = new List<string>();
List<string> strMatFuzzyListTwo = new List<string>(); //List<string> strMatFuzzyListTwo = new List<string>();
Mat mResultCut2 = CamTwoI.currentMat.Clone(); //Mat mResultCut2 = CamTwoI.currentMat.Clone();
Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>(); //Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>();
InsertSqlRunData(ref keyValueResult2, true, ref mResultCut2, mL4, ref xK_HisenceSQLWord, ref xkWord, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel); //InsertSqlRunData(ref keyValueResult2, true, ref mResultCut2, mL4, ref xK_HisenceSQLWord, ref xkWord, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel);
InsertXKHisenceWordData(xkWord);//往关键字表中插入一条数据 InsertXKHisenceWordData(xkWord);//往关键字表中插入一条数据
//文本区域 //文本区域
List<string> bingji = strMatListOne.Union(strMatListTwo).ToList();//并(全)集 //List<string> bingji = strMatListOne.Union(strMatListTwo).ToList();//并(全)集
List<string> Fuzzybingji = strMatFuzzyListOne.Union(strMatFuzzyListTwo).ToList();//并(全)集 //List<string> Fuzzybingji = strMatFuzzyListOne.Union(strMatFuzzyListTwo).ToList();//并(全)集
string OcrTextone = bingji.Join("##"); string OcrTextone = strMatListOne.Join("##");
string OcrTextTwo = Fuzzybingji.Join("##"); string OcrTextTwo = strMatFuzzyListOne.Join("##");
//string OcrTextinsert = ""; //string OcrTextinsert = "";
//List<string> bingji = strMatListListOne.Union(strMatListListTwo).ToList();//并(全)集 //List<string> bingji = strMatListListOne.Union(strMatListListTwo).ToList();//并(全)集
@ -2580,10 +2653,10 @@ namespace HisenceYoloDetection
//找到识别区域 //找到识别区域
MLResult MLsum = mL3; MLResult MLsum = mL3;
for (int v = 0; v < mL4.ResultDetails.Count; v++) //for (int v = 0; v < mL4.ResultDetails.Count; v++)
{ //{
MLsum.ResultDetails.Add(mL4.ResultDetails[v]); // MLsum.ResultDetails.Add(mL4.ResultDetails[v]);
} //}
for (int v = 0; v < MLsum.ResultDetails.Count; v++) for (int v = 0; v < MLsum.ResultDetails.Count; v++)
{ {

View File

@ -142,7 +142,7 @@
<value>733, 17</value> <value>733, 17</value>
</metadata> </metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value> <value>29</value>
</metadata> </metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">

View File

@ -18,10 +18,10 @@ namespace HisenceYoloDetection
public void Strart() public void Strart()
{ {
client = new TcpClient(); client = new TcpClient();
// client.Host = "192.168.3.100"; client.Host = "192.168.3.100";
// client.Port= 9004; client.Port= 9004;
client.Host = "127.0.0.1"; //client.Host = "127.0.0.1";
client.Port = 9000; //client.Port = 9000;
client.Connect(); client.Connect();
client.OnDataReceived += Client_OnDataReceived; client.OnDataReceived += Client_OnDataReceived;