7/14号测试

This commit is contained in:
820689062 2024-07-14 16:10:14 +08:00
parent 756d23229c
commit 9a89e11ef9
3 changed files with 410 additions and 361 deletions

View File

@ -141,13 +141,14 @@
InitMachine = new Button();
tabPage3 = new TabPage();
panel2 = new Panel();
button1 = new Button();
contextMenuStrip1 = new ContextMenuStrip(components);
WhiteBanCbx = new CheckBox();
label33 = new Label();
label28 = new Label();
openModelBtn = new Button();
modelChangeCbx = new TextBox();
label34 = new Label();
button4 = new Button();
OpenTwoDirBtn = new Button();
OpenDirBtn = new Button();
Cam2MatCbx = new TextBox();
@ -155,15 +156,7 @@
Cam1MatCbx = new TextBox();
label23 = new Label();
QueryoneBtn = new Button();
DetectBArMatbox = new TextBox();
label24 = new Label();
InsertBtn = new Button();
moveTwoZbox = new TextBox();
label25 = new Label();
moveTwoYbox = new TextBox();
label26 = new Label();
moveTwoXbox = new TextBox();
label27 = new Label();
moveZbox = new TextBox();
moveYbox = new TextBox();
label29 = new Label();
@ -182,7 +175,6 @@
timer5 = new System.Windows.Forms.Timer(components);
timer6 = new System.Windows.Forms.Timer(components);
richTextBox1 = new RichTextBox();
contextMenuStrip1 = new ContextMenuStrip(components);
backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
tabPage2.SuspendLayout();
panel1.SuspendLayout();
@ -1419,13 +1411,13 @@
//
// panel2
//
panel2.Controls.Add(button1);
panel2.Controls.Add(WhiteBanCbx);
panel2.Controls.Add(label33);
panel2.Controls.Add(label28);
panel2.Controls.Add(openModelBtn);
panel2.Controls.Add(modelChangeCbx);
panel2.Controls.Add(label34);
panel2.Controls.Add(button4);
panel2.Controls.Add(OpenTwoDirBtn);
panel2.Controls.Add(OpenDirBtn);
panel2.Controls.Add(Cam2MatCbx);
@ -1433,15 +1425,7 @@
panel2.Controls.Add(Cam1MatCbx);
panel2.Controls.Add(label23);
panel2.Controls.Add(QueryoneBtn);
panel2.Controls.Add(DetectBArMatbox);
panel2.Controls.Add(label24);
panel2.Controls.Add(InsertBtn);
panel2.Controls.Add(moveTwoZbox);
panel2.Controls.Add(label25);
panel2.Controls.Add(moveTwoYbox);
panel2.Controls.Add(label26);
panel2.Controls.Add(moveTwoXbox);
panel2.Controls.Add(label27);
panel2.Controls.Add(moveZbox);
panel2.Controls.Add(moveYbox);
panel2.Controls.Add(label29);
@ -1460,12 +1444,30 @@
panel2.TabIndex = 1;
panel2.Paint += panel2_Paint;
//
// button1
//
button1.ContextMenuStrip = contextMenuStrip1;
button1.Location = new Point(493, 46);
button1.Margin = new Padding(4, 2, 4, 2);
button1.Name = "button1";
button1.Size = new Size(96, 38);
button1.TabIndex = 41;
button1.Text = "获取";
button1.UseVisualStyleBackColor = true;
button1.Click += button1_Click_1;
//
// contextMenuStrip1
//
contextMenuStrip1.ImageScalingSize = new Size(24, 24);
contextMenuStrip1.Name = "contextMenuStrip1";
contextMenuStrip1.Size = new Size(61, 4);
//
// WhiteBanCbx
//
WhiteBanCbx.AutoSize = true;
WhiteBanCbx.Checked = true;
WhiteBanCbx.CheckState = CheckState.Checked;
WhiteBanCbx.Location = new Point(742, 231);
WhiteBanCbx.Location = new Point(867, 146);
WhiteBanCbx.Margin = new Padding(4, 2, 4, 2);
WhiteBanCbx.Name = "WhiteBanCbx";
WhiteBanCbx.Size = new Size(59, 29);
@ -1476,7 +1478,7 @@
// label33
//
label33.AutoSize = true;
label33.Location = new Point(471, 232);
label33.Location = new Point(596, 147);
label33.Margin = new Padding(4, 0, 4, 0);
label33.Name = "label33";
label33.Size = new Size(243, 25);
@ -1506,7 +1508,7 @@
//
// modelChangeCbx
//
modelChangeCbx.Location = new Point(1059, 14);
modelChangeCbx.Location = new Point(750, 14);
modelChangeCbx.Margin = new Padding(4, 2, 4, 2);
modelChangeCbx.Name = "modelChangeCbx";
modelChangeCbx.Size = new Size(241, 31);
@ -1516,27 +1518,16 @@
// label34
//
label34.AutoSize = true;
label34.Location = new Point(923, 19);
label34.Location = new Point(597, 14);
label34.Margin = new Padding(4, 0, 4, 0);
label34.Name = "label34";
label34.Size = new Size(138, 25);
label34.TabIndex = 33;
label34.Text = "面板语言选择";
//
// button4
//
button4.Location = new Point(896, 104);
button4.Margin = new Padding(4, 2, 4, 2);
button4.Name = "button4";
button4.Size = new Size(96, 34);
button4.TabIndex = 32;
button4.Text = "打开文件";
button4.UseVisualStyleBackColor = true;
button4.Click += button4_Click_1;
//
// OpenTwoDirBtn
//
OpenTwoDirBtn.Location = new Point(895, 184);
OpenTwoDirBtn.Location = new Point(1066, 105);
OpenTwoDirBtn.Margin = new Padding(4, 2, 4, 2);
OpenTwoDirBtn.Name = "OpenTwoDirBtn";
OpenTwoDirBtn.Size = new Size(96, 35);
@ -1547,7 +1538,7 @@
//
// OpenDirBtn
//
OpenDirBtn.Location = new Point(895, 142);
OpenDirBtn.Location = new Point(1066, 53);
OpenDirBtn.Margin = new Padding(4, 2, 4, 2);
OpenDirBtn.Name = "OpenDirBtn";
OpenDirBtn.Size = new Size(96, 34);
@ -1558,7 +1549,7 @@
//
// Cam2MatCbx
//
Cam2MatCbx.Location = new Point(608, 190);
Cam2MatCbx.Location = new Point(750, 111);
Cam2MatCbx.Margin = new Padding(4, 2, 4, 2);
Cam2MatCbx.Name = "Cam2MatCbx";
Cam2MatCbx.Size = new Size(279, 31);
@ -1568,7 +1559,7 @@
// label22
//
label22.AutoSize = true;
label22.Location = new Point(471, 190);
label22.Location = new Point(596, 105);
label22.Margin = new Padding(4, 0, 4, 0);
label22.Name = "label22";
label22.Size = new Size(138, 25);
@ -1577,7 +1568,7 @@
//
// Cam1MatCbx
//
Cam1MatCbx.Location = new Point(608, 142);
Cam1MatCbx.Location = new Point(750, 59);
Cam1MatCbx.Margin = new Padding(4, 2, 4, 2);
Cam1MatCbx.Name = "Cam1MatCbx";
Cam1MatCbx.Size = new Size(279, 31);
@ -1587,7 +1578,7 @@
// label23
//
label23.AutoSize = true;
label23.Location = new Point(472, 147);
label23.Location = new Point(597, 62);
label23.Margin = new Padding(4, 0, 4, 0);
label23.Name = "label23";
label23.Size = new Size(138, 25);
@ -1596,7 +1587,7 @@
//
// QueryoneBtn
//
QueryoneBtn.Location = new Point(1077, 209);
QueryoneBtn.Location = new Point(978, 204);
QueryoneBtn.Margin = new Padding(4, 2, 4, 2);
QueryoneBtn.Name = "QueryoneBtn";
QueryoneBtn.Size = new Size(148, 50);
@ -1605,96 +1596,20 @@
QueryoneBtn.UseVisualStyleBackColor = true;
QueryoneBtn.Click += QueryoneBtn_Click;
//
// DetectBArMatbox
//
DetectBArMatbox.Location = new Point(607, 104);
DetectBArMatbox.Margin = new Padding(4, 2, 4, 2);
DetectBArMatbox.Name = "DetectBArMatbox";
DetectBArMatbox.Size = new Size(280, 31);
DetectBArMatbox.TabIndex = 24;
DetectBArMatbox.Text = "D:\\Hisence\\类型\\Lp202452414231.jpg";
//
// label24
//
label24.AutoSize = true;
label24.Location = new Point(471, 110);
label24.Margin = new Padding(4, 0, 4, 0);
label24.Name = "label24";
label24.Size = new Size(96, 25);
label24.TabIndex = 23;
label24.Text = "条码录入";
//
// InsertBtn
//
InsertBtn.Location = new Point(1077, 87);
InsertBtn.Location = new Point(608, 204);
InsertBtn.Margin = new Padding(4, 2, 4, 2);
InsertBtn.Name = "InsertBtn";
InsertBtn.Size = new Size(148, 45);
InsertBtn.Size = new Size(156, 56);
InsertBtn.TabIndex = 22;
InsertBtn.Text = "插入";
InsertBtn.UseVisualStyleBackColor = true;
InsertBtn.Click += InsertBtn_Click;
//
// moveTwoZbox
//
moveTwoZbox.Location = new Point(607, 56);
moveTwoZbox.Margin = new Padding(4, 2, 4, 2);
moveTwoZbox.Name = "moveTwoZbox";
moveTwoZbox.Size = new Size(280, 31);
moveTwoZbox.TabIndex = 21;
moveTwoZbox.Text = "0";
//
// label25
//
label25.AutoSize = true;
label25.Location = new Point(471, 62);
label25.Margin = new Padding(4, 0, 4, 0);
label25.Name = "label25";
label25.Size = new Size(151, 25);
label25.TabIndex = 20;
label25.Text = "第二次拍照Z轴";
//
// moveTwoYbox
//
moveTwoYbox.Location = new Point(607, 11);
moveTwoYbox.Margin = new Padding(4, 2, 4, 2);
moveTwoYbox.Name = "moveTwoYbox";
moveTwoYbox.Size = new Size(280, 31);
moveTwoYbox.TabIndex = 19;
moveTwoYbox.Text = "0";
//
// label26
//
label26.AutoSize = true;
label26.Location = new Point(471, 17);
label26.Margin = new Padding(4, 0, 4, 0);
label26.Name = "label26";
label26.Size = new Size(153, 25);
label26.TabIndex = 18;
label26.Text = "第二次拍照Y轴";
//
// moveTwoXbox
//
moveTwoXbox.Location = new Point(143, 229);
moveTwoXbox.Margin = new Padding(4, 2, 4, 2);
moveTwoXbox.Name = "moveTwoXbox";
moveTwoXbox.Size = new Size(287, 31);
moveTwoXbox.TabIndex = 17;
moveTwoXbox.Text = "54964";
//
// label27
//
label27.AutoSize = true;
label27.Location = new Point(21, 233);
label27.Margin = new Padding(4, 0, 4, 0);
label27.Name = "label27";
label27.Size = new Size(152, 25);
label27.TabIndex = 16;
label27.Text = "第二次拍照X轴";
//
// moveZbox
//
moveZbox.Location = new Point(143, 182);
moveZbox.Location = new Point(183, 184);
moveZbox.Margin = new Padding(4, 2, 4, 2);
moveZbox.Name = "moveZbox";
moveZbox.Size = new Size(287, 31);
@ -1703,7 +1618,7 @@
//
// moveYbox
//
moveYbox.Location = new Point(143, 137);
moveYbox.Location = new Point(183, 141);
moveYbox.Margin = new Padding(4, 2, 4, 2);
moveYbox.Name = "moveYbox";
moveYbox.Size = new Size(287, 31);
@ -1722,7 +1637,7 @@
//
// moveXbox
//
moveXbox.Location = new Point(143, 98);
moveXbox.Location = new Point(182, 101);
moveXbox.Margin = new Padding(4, 2, 4, 2);
moveXbox.Name = "moveXbox";
moveXbox.Size = new Size(287, 31);
@ -1741,7 +1656,7 @@
//
// OcrBarBox
//
OcrBarBox.Location = new Point(143, 50);
OcrBarBox.Location = new Point(183, 56);
OcrBarBox.Margin = new Padding(4, 2, 4, 2);
OcrBarBox.Name = "OcrBarBox";
OcrBarBox.Size = new Size(287, 31);
@ -1751,16 +1666,16 @@
// label31
//
label31.AutoSize = true;
label31.Location = new Point(18, 56);
label31.Location = new Point(23, 59);
label31.Margin = new Padding(4, 0, 4, 0);
label31.Name = "label31";
label31.Size = new Size(54, 25);
label31.Size = new Size(41, 25);
label31.TabIndex = 4;
label31.Text = "条码";
label31.Text = "SN";
//
// TypeBox
//
TypeBox.Location = new Point(143, 11);
TypeBox.Location = new Point(183, 14);
TypeBox.Margin = new Padding(4, 2, 4, 2);
TypeBox.Name = "TypeBox";
TypeBox.Size = new Size(287, 31);
@ -1769,7 +1684,7 @@
//
// queryALLBtn
//
queryALLBtn.Location = new Point(1077, 147);
queryALLBtn.Location = new Point(798, 204);
queryALLBtn.Margin = new Padding(4, 2, 4, 2);
queryALLBtn.Name = "queryALLBtn";
queryALLBtn.Size = new Size(148, 56);
@ -1809,12 +1724,6 @@
richTextBox1.TabIndex = 1;
richTextBox1.Text = "";
//
// contextMenuStrip1
//
contextMenuStrip1.ImageScalingSize = new Size(24, 24);
contextMenuStrip1.Name = "contextMenuStrip1";
contextMenuStrip1.Size = new Size(61, 4);
//
// MainForm
//
AutoScaleDimensions = new SizeF(12F, 25F);
@ -1977,7 +1886,6 @@
private Label label21;
private TabPage tabPage3;
private Panel panel2;
private Button button4;
private Button OpenTwoDirBtn;
private Button OpenDirBtn;
private TextBox Cam2MatCbx;
@ -1985,15 +1893,7 @@
private TextBox Cam1MatCbx;
private Label label23;
private Button QueryoneBtn;
private TextBox DetectBArMatbox;
private Label label24;
private Button InsertBtn;
private TextBox moveTwoZbox;
private Label label25;
private TextBox moveTwoYbox;
private Label label26;
private TextBox moveTwoXbox;
private Label label27;
private TextBox moveZbox;
private Label label28;
private TextBox moveYbox;
@ -2038,5 +1938,6 @@
private XKRS.UI.Canvas canvas1;
private XKRS.UI.Canvas canvas6;
private XKRS.UI.Canvas canvas2;
private Button button1;
}
}

View File

@ -6,6 +6,7 @@ using OpenCvSharp;
using OpenCvSharp.Dnn;
using OpenCvSharp.Extensions;
using OpenCvSharp.XFeatures2D;
using STTech.CodePlus.Threading;
using Sunny.UI;
using Sunny.UI.Win32;
using System;
@ -25,6 +26,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Xml.Serialization;
using XKRS.Device.SimboVision.SimboHelper;
using XKRS.UI;
using static HisenceYoloDetection.CheckDiffSciHelper;
@ -69,6 +71,7 @@ namespace HisenceYoloDetection
AutoResetEvent _runHandleBefore = new AutoResetEvent(false);
ManualResetEvent _runHandleAfter = new ManualResetEvent(false);
AutoResetEvent _runThreadFormtype = new AutoResetEvent(false);
bool PLC545 = false;
bool PLC548 = false;
@ -289,50 +292,115 @@ namespace HisenceYoloDetection
/// <param name="ContentType">默认 application/json , application/x-www-form-urlencoded,multipart/form-data,raw,binary </param>
/// <param name="Accept">默认application/json</param>
/// <returns></returns>
public string Post(string parameterData, string serviceUrl, string ContentType = "application/json", string Accept = "application/json")
public string Post(string parameterData, string serviceUrl, string contentType = "application/x-www-form-urlencoded", string accept = "application/json")
{
//先根据用户请求的uri构造请求地址
//string serviceUrl = string.Format("{0}/{1}", this.BaseUri, uri);
//创建Web访问对象
try
{
// 创建 Web 请求对象
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
//把用户传过来的数据转成“UTF-8”的字节流
byte[] buf = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(parameterData);
byte[] buf = Encoding.UTF8.GetBytes($"inputvalue={Uri.EscapeDataString(parameterData)}");
myRequest.Method = "POST";
//myRequest.Accept = "application/json";
//myRequest.ContentType = "application/json"; // //Content-Type: application/x-www-form-urlencoded
myRequest.AutomaticDecompression = DecompressionMethods.GZip;
myRequest.Accept = Accept;
//myRequest.ContentType = ContentType;
myRequest.ContentType = "application/json; charset=UTF-8";
myRequest.Accept = accept;
myRequest.ContentType = contentType;
myRequest.ContentLength = buf.Length;
myRequest.MaximumAutomaticRedirections = 1;
myRequest.AllowAutoRedirect = true;
//myRequest.Headers.Add("content-type", "application/json");
//myRequest.Headers.Add("accept-encoding", "gzip");
//myRequest.Headers.Add("accept-charset", "utf-8");
// 发送请求
Stream stream = myRequest.GetRequestStream();
using (Stream stream = myRequest.GetRequestStream())
{
stream.Write(buf, 0, buf.Length);
stream.Close();
//通过Web访问对象获取响应内容
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
//通过响应内容流创建StreamReader对象因为StreamReader更高级更快
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
//string returnXml = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
string returnData = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
reader.Close();
myResponse.Close();
return returnData;
}
#endregion
// 获取响应内容
using (HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse())
using (StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
catch (WebException ex)
{
if (ex.Response != null)
{
using (StreamReader reader = new StreamReader(ex.Response.GetResponseStream()))
{
string errorResponse = reader.ReadToEnd();
Console.WriteLine("WebException: " + errorResponse);
return errorResponse;
}
}
else
{
Console.WriteLine("WebException: " + ex.Message);
return null;
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
return null;
}
}
#endregion
Dictionary<string, string> DayTypeDics = new Dictionary<string, string>();//存放当日的SN和型号值
public void GetTypeFromPost()
{
string url = "http://172.16.139.146/FCCBOMWebService/FCCBomService.asmx/GetFCCBomInfoPDJson";
DateTime dt = DateTime.Now;
string today = dt.ToString("yyyy-MM-dd");
string startTime = today;
string endTime = today;
string lineBody = "BZ-PC";
string materialDescript = "皂盒";
JObject patientInfo = new JObject
{
["StartTime"] = startTime,
["EndTime"] = endTime,
["LineBody"] = lineBody,
["MaterialDescripts"] = new JArray { materialDescript }
};
string sendData = patientInfo.ToString();
string resultData = Post(sendData, url, "application/x-www-form-urlencoded", "application/json");
if (resultData != null)
{
JObject responseJson = JObject.Parse(resultData);
bool success = responseJson["success"] != null && (bool)responseJson["success"];
if (success)
{
// string FinalDefIDToFind = m_sKEYENCEBar.Substring(1, 18);// 目标 FinalDefID
JArray dataArray = responseJson["data"] as JArray;
if (dataArray != null)
{
foreach (JObject dataItem in dataArray)
{
string finalDefID = dataItem["FinalDefID"] != null ? dataItem["FinalDefID"].ToString() : "N/A";
string productType = dataItem["ProductType"] != null ? dataItem["ProductType"].ToString() : "N/A";
DayTypeDics.Add(finalDefID, productType);
}
}
}
else
{
string returnMsg = responseJson["ReturnMsg"] != null ? responseJson["ReturnMsg"].ToString() : "Unknown error";
Console.WriteLine("请求失败:" + returnMsg);
}
}
else
{
Console.WriteLine("请求失败:未返回数据");
}
}
/// <summary>
/// 主窗口
/// </summary>
@ -340,39 +408,65 @@ namespace HisenceYoloDetection
/// <param name="e"></param>
private void MainForm_Load(object sender, EventArgs e)
{
//报警地址
//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;
Stopwatch sw = new Stopwatch();
sw.Start();
//string starttime=string.Format("{0:yyyy_mm_dd}", dt); //17 17 2017 2017
string url = "http://172.16.139.146/FCCBOMWebService/FCCBomService.asmx/GetFCCBomInfoPDJson";
DateTime dt = DateTime.Now;
string today = dt.ToString("yyyy-MM-dd");
string startTime = today;
string endTime = today;
string lineBody = "BZ-PC";
string materialDescript = "皂盒";
JObject patientInfo = new JObject
{
["StartTime"] = startTime,
["EndTime"] = endTime,
["LineBody"] = lineBody,
["MaterialDescripts"] = new JArray { materialDescript }
};
string sendData = patientInfo.ToString();
string resultData = Post(sendData, url, "application/x-www-form-urlencoded", "application/json");
if (resultData != null)
{
JObject responseJson = JObject.Parse(resultData);
bool success = responseJson["success"] != null && (bool)responseJson["success"];
if (success)
{
string FinalDefIDToFind = m_sKEYENCEBar.Substring(1, 18);// 目标 FinalDefID
JArray dataArray = responseJson["data"] as JArray;
if (dataArray != null)
{
foreach (JObject dataItem in dataArray)
{
if (dataItem["FinalDefID"] != null && dataItem["FinalDefID"].ToString() == FinalDefIDToFind)
{
string productType = dataItem["ProductType"] != null ? dataItem["ProductType"].ToString() : "N/A";
Console.WriteLine($"FinalDefID: {FinalDefIDToFind}, ProductType: {productType}");
break;
}
}
}
}
else
{
string returnMsg = responseJson["ReturnMsg"] != null ? responseJson["ReturnMsg"].ToString() : "Unknown error";
Console.WriteLine("请求失败:" + returnMsg);
}
}
else
{
Console.WriteLine("请求失败:未返回数据");
}
sw.Stop();
Console.WriteLine("时间请求i" + sw.ElapsedMilliseconds);
//string startTime = starttime;
//string EndTime = starttime;
//string lineBody = "BZ-PC";
//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();
// //解析字段
//}
if (_runHandleBefore == null)
{
_runHandleBefore = new AutoResetEvent(false);
@ -451,6 +545,11 @@ namespace HisenceYoloDetection
myLogDelegateUI = new MyLogDelegateUI(initAll3);//绑定委托
Scanner.Strart();
Scanner.OnClientDataReceived -= OnDataReceived;
Scanner.OnClientDataReceived += OnDataReceived;
Scanner.btnSendMsg("LON\r");//发送开启指令
myLog("发送恩士扫码枪开启指令", DateTime.Now);
//初始化PLC
melsecPLCTCPDriver.Start();
@ -782,11 +881,7 @@ namespace HisenceYoloDetection
OKOrNGShow.Image = OKbitmap;
//初始化扫码枪
Scanner.Strart();
Scanner.OnClientDataReceived -= OnDataReceived;
Scanner.OnClientDataReceived += OnDataReceived;
Scanner.btnSendMsg("LON\r");//发送开启指令
myLog("发送恩士扫码枪开启指令", DateTime.Now);
//PLC使能开启
melsecPLCTCPDriver.WriteInt("581", 0);//定位松开
@ -1242,7 +1337,7 @@ namespace HisenceYoloDetection
{
// Old_xKNow = xKNow;
myLog("型号匹配成功" + xKNow.OcrBar, DateTime.Now);
bBarTriger = true;
//MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);// PLC控制电机移动四轴
}
@ -1306,6 +1401,7 @@ namespace HisenceYoloDetection
{
int iNum1 = 0;
int iNum0 = 0;
int iNum3 = 0;
Thread.CurrentThread.Priority = ThreadPriority.Highest;
while (true)
{
@ -1336,7 +1432,8 @@ namespace HisenceYoloDetection
else
{
iNum1 = 0;
melsecPLCTCPDriver.WriteInt("550", 1);//阻塞
iNum3++;//获取光电没达到洗衣机上的次数
}
if (iNum1 >= 2)
{
@ -1350,50 +1447,23 @@ namespace HisenceYoloDetection
{
_runHandleBefore.WaitOne();
//这里改成和海信的对接需求
string OcrBar = "";
string FinalDefIDToFind = m_sKEYENCEBar.Substring(1, 18);// 目标 FinalDefID
#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);//从数据库中查询到这个条码的四轴的值
//解析字段
}
}
OcrBar=FormBarType(FinalDefIDToFind)
#endif
// if(Oldm_sKEYENCEBar!= m_sKEYENCEBar)
xKNow = GetModeFromBar("VWJ070541V0WW824F120223");//从数据库中查询到这个条码的四轴的值
if (DayTypeDics.ContainsKey(FinalDefIDToFind))//当日的post请求有此类SN 得到此类型号
{
OcrBar = DayTypeDics[FinalDefIDToFind];
}
if (OcrBar.IsNullOrEmpty())
{
break;
}
xKNow = GetModeFromBar(OcrBar);//从数据库中查询到这个条码的四轴的值
if (xKNow == null)
@ -1401,25 +1471,21 @@ namespace HisenceYoloDetection
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);
//MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);// PLC控制电机移动四轴
}
// break;
}
Thread.Sleep(2);
bBar = false;
#if true
// if (bBarTriger)//证明读码器读到东西
{
@ -1476,7 +1542,7 @@ namespace HisenceYoloDetection
//模组复位
bTriger = true;//可以进行检测识别了
bBarTriger = false;//读码器可以不工作了
iNum0 = 0;
iNum1 = 0;
break;
@ -1543,6 +1609,10 @@ namespace HisenceYoloDetection
}
if(iNum3>=2)
{
melsecPLCTCPDriver.WriteInt("550", 1);//阻塞
}
}
@ -1605,6 +1675,7 @@ namespace HisenceYoloDetection
originMatShow.Image = cameraMat.ToBitmap();
//pictureBox1.Image = cameraMat.ToBitmap();
_runHandleAfter.Set();
_runThreadFormtype.Set();
}
//第二次拍照
@ -1656,6 +1727,7 @@ namespace HisenceYoloDetection
/// <summary>
/// 开始识别
/// </summary>
///
public void ReadyDetect()
{
_ = Task.Run((Action)(() =>
@ -1667,10 +1739,11 @@ namespace HisenceYoloDetection
{
//信号量阻塞 使其不在总数增加和闪烁
_runHandleAfter.WaitOne();
//相机2第一次拍照
//2第一次拍照
//if (IfCam2Triger)
{
IfCam2Triger = false;
// IfCam2Triger = false;
//OCR识别
//MLRequest req = new MLRequest();
//req.currentMat = Cam2ImgShowBar;
@ -1693,7 +1766,9 @@ namespace HisenceYoloDetection
string IOcrBAr = xKNow.OcrBar;
//xKNow = GetModeFromBar(IOcrBAr);//从数据库中查询到这个条码的四轴的值
//这里改成和海信的对接需求
IfCam1TwoTriger = false;
_runHandleAfter.Reset();
List<XK_HisenceWord> xkWordList = ManagerModelHelper.GetModeWordFromBar(IOcrBAr);
if (xkWordList.Count() == 1)
{
@ -1742,9 +1817,7 @@ namespace HisenceYoloDetection
//相机1第二次拍照
// if (IfCam1TwoTriger && bBarTriger)
{
IfCam1TwoTriger = false;
bBarTriger = false;//可能没什么用了
_runHandleAfter.Reset();
//初始化板
Defet_OnDetectionDone(whiteMat, 1);
Defet_OnDetectionDone(whiteMat, 2);
@ -1949,6 +2022,21 @@ namespace HisenceYoloDetection
}
/// <summary>
/// 发请求获取当日生产的型号
/// </summary>
public void ThreadPost()
{
Task.Run(() => {
while (true)
{
_runThreadFormtype.WaitOne();
GetTypeFromPost();
}
});
}
/// <summary>
/// 根据条码从数据库中获取型号
/// </summary>
/// <param name="SkBar"></param>
@ -2214,8 +2302,9 @@ namespace HisenceYoloDetection
// OnGetBar();
melsecPLCTCPDriver.WriteInt("556", 1);//绿灯亮
melsecPLCTCPDriver.WriteInt("554", 0);//黄灯灭
TriggerCameral2();
ReadyDetect();
TriggerCameral2();//光电触发拍照 根据SN获取型号 从数据库中得到块值
ReadyDetect();//相机拍照后检测线程
ThreadPost();//相机拍照后获取当日的型号
myLog("开启流程成功", DateTime.Now);
}
@ -2471,7 +2560,7 @@ namespace HisenceYoloDetection
//isFileHaveName = true;
//richTextBox1.Text = fileOpen.ReadFile();
//richTextBox1.AppendText("");
DetectBArMatbox.Text = fName;
//DetectBArMatbox.Text = fName;
BarPath = fName;
}
}
@ -2482,15 +2571,16 @@ namespace HisenceYoloDetection
try
{
string SNText = OcrBarBox.Text;
string type = TypeBox.Text;
string OcrBar = OcrBarBox.Text;
string moveX = moveXbox.Text;
string moveY = moveYbox.Text;
string moveZ = moveZbox.Text;
string Detect = DetectBArMatbox.Text;
string movetwoX = moveTwoXbox.Text;
string movetwoY = moveTwoYbox.Text;
string movetwoZ = moveTwoZbox.Text;
// string Detect = DetectBArMatbox.Text;
// string movetwoX = moveTwoXbox.Text;
// string movetwoY = moveTwoYbox.Text;
// string movetwoZ = moveTwoZbox.Text;
bool whiteBan = true;
if (WhiteBanCbx.CheckState == CheckState.Checked)//选中
{
@ -2521,31 +2611,31 @@ namespace HisenceYoloDetection
MessageBox.Show("第一次拍照移动的Z只能是数字");
return;
}
if (!Regex.IsMatch(movetwoX, @"^[0-9]+$"))
{
MessageBox.Show("第二次拍照移动的X只能是数字");
return;
}
if (!Regex.IsMatch(movetwoY, @"^[0-9]+$"))
{
MessageBox.Show("第二次拍照移动的Y只能是数字");
return;
}
if (!Regex.IsMatch(movetwoZ, @"^[0-9]+$"))
{
MessageBox.Show("第二次拍照移动的Z只能是数字");
return;
}
//if (!Regex.IsMatch(movetwoX, @"^[0-9]+$"))
//{
// MessageBox.Show("第二次拍照移动的X只能是数字");
// return;
//}
//if (!Regex.IsMatch(movetwoY, @"^[0-9]+$"))
//{
// MessageBox.Show("第二次拍照移动的Y只能是数字");
// return;
//}
//if (!Regex.IsMatch(movetwoZ, @"^[0-9]+$"))
//{
// MessageBox.Show("第二次拍照移动的Z只能是数字");
// return;
//}
if (Detect != "" && BarPath != "" && Cam1OnePath != "" && Cam1TwoPath != "" && ModelChangePath != "")
if (SNText != "" && BarPath != "" && Cam1OnePath != "" && Cam1TwoPath != "" && ModelChangePath != "")
{
int HmoveX = (int)Convert.ToInt64(moveX);
int HmoveY = (int)Convert.ToInt64(moveY);
int HmoveZ = (int)Convert.ToInt64(moveZ);
int HmovetwoX = (int)Convert.ToInt64(movetwoX);
int HmovetwoY = (int)Convert.ToInt64(movetwoY);
int HmovetwoZ = (int)Convert.ToInt64(movetwoZ);
InsertXK_Hisence(whiteBan, HmoveX, HmoveY, HmoveZ, HmovetwoX, HmovetwoY, HmovetwoZ);
//int HmovetwoX = (int)Convert.ToInt64(movetwoX);
//int HmovetwoY = (int)Convert.ToInt64(movetwoY);
//int HmovetwoZ = (int)Convert.ToInt64(movetwoZ);
InsertXK_Hisence(whiteBan, SNText, HmoveX, HmoveY, HmoveZ);
}
@ -2560,15 +2650,73 @@ namespace HisenceYoloDetection
MessageBox.Show(es.Message);
}
}
public void InsertXK_Hisence(bool ifwhiteBan, int MoveX, int MoveY, int MoveZ, int MoveTwoX, int MoveTwoY, int MoveTwoZ)
public string FormBarType(string SN)
{
PaddleOcrModel IpaddleOcrModel = new PaddleOcrModel();
IpaddleOcrModel.Load(ModelChangePath, "CPU");
string productType = "N/A";
string url = "http://172.16.139.146/FCCBOMWebService/FCCBomService.asmx/GetFCCBomInfoPDJson";
//用中文文模型来识别条码
MLRequest OcrBari = new MLRequest();
OcrBari.currentMat = Cv2.ImRead(BarPath);
string IOcrBAr = DetMachineBar(ref OcrBari);
DateTime dt = DateTime.Now;
string today = dt.ToString("yyyy-MM-dd");
string startTime = today;
string endTime = today;
string lineBody = "BZ-PC";
string materialDescript = "皂盒";
JObject patientInfo = new JObject
{
["StartTime"] = startTime,
["EndTime"] = endTime,
["LineBody"] = lineBody,
["MaterialDescripts"] = new JArray { materialDescript }
};
string sendData = patientInfo.ToString();
string resultData = Post(sendData, url, "application/x-www-form-urlencoded", "application/json");
if (resultData != null)
{
JObject responseJson = JObject.Parse(resultData);
bool success = responseJson["success"] != null && (bool)responseJson["success"];
if (success)
{
string FinalDefIDToFind = SN.Substring(1, 18);// 目标 FinalDefID
JArray dataArray = responseJson["data"] as JArray;
if (dataArray != null)
{
foreach (JObject dataItem in dataArray)
{
if (dataItem["FinalDefID"] != null && dataItem["FinalDefID"].ToString() == FinalDefIDToFind)
{
productType = dataItem["ProductType"] != null ? dataItem["ProductType"].ToString() : "N/A";
Console.WriteLine($"FinalDefID: {FinalDefIDToFind}, ProductType: {productType}");
break;
}
}
}
}
else
{
string returnMsg = responseJson["ReturnMsg"] != null ? responseJson["ReturnMsg"].ToString() : "Unknown error";
Console.WriteLine("请求失败:" + returnMsg);
}
}
else
{
Console.WriteLine("请求失败:未返回数据");
}
return productType;
// sw.Stop();
// Console.WriteLine("时间请求i" + sw.ElapsedMilliseconds);
}
public void InsertXK_Hisence(bool ifwhiteBan, string SNtext, int MoveX, int MoveY, int MoveZ)
{
// PaddleOcrModel IpaddleOcrModel = new PaddleOcrModel();
// IpaddleOcrModel.Load(ModelChangePath, "CPU");
string IOcrBAr = FormBarType(SNtext);
XK_HisenceWord xkWord = new XK_HisenceWord();
xkWord.OcrBar = IOcrBAr;
xkWord.TwoIFWhile = ifwhiteBan;
@ -2679,7 +2827,7 @@ namespace HisenceYoloDetection
}
DateTime dt2 = DateTime.Now;
XKHisence xK = new XKHisence("1", IOcrBAr, MoveX, MoveY, MoveZ, detstr, OcrTextone, MoveTwoX, MoveTwoY, MoveTwoZ, ModelChangePath, "", OcrTextTwo);
XKHisence xK = new XKHisence("1", IOcrBAr, MoveX, MoveY, MoveZ, detstr, OcrTextone, MoveX, MoveY, MoveZ, ModelChangePath, "", OcrTextTwo);
//string log="D:\\Hisence\\detImages\\" + dt2.Year.ToString() + dt2.Month.ToString() + dt2.Day.ToString() + dt2.Hour.ToString() + dt2.Minute.ToString() + dt2.Millisecond.ToString() + "2result.log";
// using (StreamWriter sw=new StreamWriter(log, true))
// {
@ -2922,21 +3070,8 @@ namespace HisenceYoloDetection
{
try
{
string type = TypeBox.Text;
string OcrBar = OcrBarBox.Text;
string moveX = moveXbox.Text;
string moveY = moveYbox.Text;
string moveZ = moveZbox.Text;
string Detect = DetectBArMatbox.Text;
string movetwoX = moveTwoXbox.Text;
string movetwoY = moveTwoYbox.Text;
string movetwoZ = moveTwoZbox.Text;
string sql = "select * from XK_Hisence where type='" + type + "' or OcrBar='" + OcrBar + "'";
DataSet dataSet = SQLiteHelper.Query(sql);
InsertDataDgv.DataSource = dataSet.Tables[0];
}
catch (Exception es)
{
@ -3605,10 +3740,23 @@ namespace HisenceYoloDetection
{
melsecPLCTCPDriver.WriteInt("550", 0);
}
/// <summary>
/// 软件关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
melsecPLCTCPDriver.WriteInt("550", 0);
}
private void button1_Click_1(object sender, EventArgs e)
{
if (!m_sKEYENCEBar.IsNullOrEmpty())
{
OcrBarBox.Text = m_sKEYENCEBar;
}
}
}
}

View File

@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>569, 17</value>
</metadata>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
@ -135,9 +138,6 @@
<metadata name="timer6.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>477, 17</value>
</metadata>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>569, 17</value>
</metadata>
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>733, 17</value>
</metadata>