重新修改
This commit is contained in:
parent
feeda6a550
commit
791bfb85d2
1185
HisenceYoloDetection/MainForm.Designer.cs
generated
1185
HisenceYoloDetection/MainForm.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -283,16 +283,75 @@ namespace HisenceYoloDetection
|
||||
return content;
|
||||
}
|
||||
|
||||
#region Post请求
|
||||
/// <summary>
|
||||
/// http Post请求
|
||||
/// </summary>
|
||||
/// <param name="parameterData">参数</param>
|
||||
/// <param name="serviceUrl">访问地址</param>
|
||||
/// <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/x-www-form-urlencoded", string accept = "application/json")
|
||||
public static string PostData(string url, string postData)
|
||||
{
|
||||
byte[] data = Encoding.UTF8.GetBytes(postData);
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.Method = "POST";
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
request.ContentLength = data.Length;
|
||||
|
||||
using (Stream stream = request.GetRequestStream())
|
||||
{
|
||||
stream.Write(data, 0, data.Length);
|
||||
}
|
||||
|
||||
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
|
||||
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
static string FindStringAfterColon(string response, string targetString)
|
||||
{
|
||||
int targetIndex = response.IndexOf(targetString);
|
||||
if (targetIndex == -1)
|
||||
{
|
||||
Console.WriteLine($"未找到字符串: {targetString}");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 查找目标字符串后的冒号和引号
|
||||
int colonIndex = response.IndexOf(':', targetIndex);
|
||||
if (colonIndex == -1 || colonIndex <= targetIndex)
|
||||
{
|
||||
Console.WriteLine("在目标字符串后未找到冒号");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 查找引号开始的位置
|
||||
int startQuoteIndex = response.IndexOf('"', colonIndex + 1);
|
||||
if (startQuoteIndex == -1)
|
||||
{
|
||||
Console.WriteLine("未找到引号");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 查找闭合引号的位置
|
||||
int endQuoteIndex = response.IndexOf('"', startQuoteIndex + 1);
|
||||
if (endQuoteIndex == -1)
|
||||
{
|
||||
Console.WriteLine("未找到闭合的引号");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 提取并返回引号内的字符串
|
||||
return response.Substring(startQuoteIndex + 1, endQuoteIndex - startQuoteIndex - 1);
|
||||
}
|
||||
|
||||
|
||||
#region Post请求
|
||||
/// <summary>
|
||||
/// http Post请求
|
||||
/// </summary>
|
||||
/// <param name="parameterData">参数</param>
|
||||
/// <param name="serviceUrl">访问地址</param>
|
||||
/// <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/x-www-form-urlencoded", string accept = "application/json")
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -347,59 +406,46 @@ namespace HisenceYoloDetection
|
||||
public void GetTypeFromPost()
|
||||
{
|
||||
string url = "http://172.16.139.146/FCCBOMWebService/FCCBomService.asmx/GetFCCBomInfoPDJson";
|
||||
string jsonData = @"
|
||||
{
|
||||
""StartTime"": ""2024-07-15"",
|
||||
""EndTime"": ""2024-07-15"",
|
||||
""LineBody"": ""BZ-PC""
|
||||
}";
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
string today = dt.ToString("yyyy-MM-dd");
|
||||
|
||||
string startTime = today;
|
||||
string endTime = today;
|
||||
string lineBody = "BZ-PC";
|
||||
string materialDescript = "皂盒";
|
||||
string postData = "inputvalue=" + Uri.EscapeDataString(jsonData);
|
||||
|
||||
JObject patientInfo = new JObject
|
||||
try
|
||||
{
|
||||
["StartTime"] = startTime,
|
||||
["EndTime"] = endTime,
|
||||
["LineBody"] = lineBody,
|
||||
["MaterialDescripts"] = new JArray { materialDescript }
|
||||
};
|
||||
string response = PostData(url, postData);
|
||||
|
||||
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(0, m_sKEYENCEBar.Length - 7); // 目标 FinalDefID
|
||||
string productType = FindStringAfterColon(response, finalDefIdToFind);
|
||||
if (productType != null)
|
||||
{
|
||||
Console.WriteLine($"{finalDefIdToFind}: {productType}");
|
||||
|
||||
// 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);
|
||||
Console.WriteLine($"FinalDefID {finalDefIdToFind} not found in response.");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("请求失败:未返回数据");
|
||||
Console.WriteLine("Error occurred:");
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 主窗口
|
||||
@ -411,59 +457,49 @@ namespace HisenceYoloDetection
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
string url = "http://172.16.139.146/FCCBOMWebService/FCCBomService.asmx/GetFCCBomInfoPDJson";
|
||||
// string url = "http://172.16.139.146/FCCBOMWebService/FCCBomService.asmx/GetFCCBomInfoPDJson";
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
string today = dt.ToString("yyyy-MM-dd");
|
||||
// string jsonData = @"
|
||||
//{
|
||||
// ""StartTime"": ""2024-07-15"",
|
||||
// ""EndTime"": ""2024-07-15"",
|
||||
// ""LineBody"": ""BZ-PC""
|
||||
// }";
|
||||
|
||||
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 postData = "inputvalue=" + Uri.EscapeDataString(jsonData);
|
||||
|
||||
// try
|
||||
// {
|
||||
// string response = PostData(url, postData);
|
||||
|
||||
|
||||
|
||||
// // 解析并处理响应
|
||||
// string finalDefIdToFind = m_sKEYENCEBar.Substring(0, m_sKEYENCEBar.Length - 7);
|
||||
// string productType = FindStringAfterColon(response, finalDefIdToFind);
|
||||
// if (productType != null)
|
||||
// {
|
||||
// Console.WriteLine($"{finalDefIdToFind}: {productType}");
|
||||
|
||||
// // 将结果写入文件
|
||||
|
||||
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Console.WriteLine($"FinalDefID {finalDefIdToFind} not found in response.");
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine("Error occurred:");
|
||||
// Console.WriteLine(ex.Message);
|
||||
// }
|
||||
|
||||
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);
|
||||
|
||||
@ -558,14 +594,10 @@ namespace HisenceYoloDetection
|
||||
|
||||
OnSpeedShow();//线程开启将速度显示在界面上
|
||||
OnPostionShow();//线程开启将位置显示在界面上
|
||||
<<<<<<< HEAD
|
||||
|
||||
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
|
||||
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);//绿灯
|
||||
=======
|
||||
melsecPLCTCPDriver.WriteInt("554", 1);//黄灯亮
|
||||
melsecPLCTCPDriver.WriteInt("552", 0);//其他灯处于灭状态
|
||||
melsecPLCTCPDriver.WriteInt("556", 0);
|
||||
>>>>>>> 756d23229c59669d628dd94efb8876679bfe21f7
|
||||
|
||||
//t = new System.Timers.Timer(10000);//实例化Timer类,设置间隔时间为10000毫秒;
|
||||
//t.Elapsed += new System.Timers.ElapsedEventHandler(Execute);//到达时间的时候执行事件;
|
||||
//t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
|
||||
@ -1964,31 +1996,23 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//红灯
|
||||
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
|
||||
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);//绿灯
|
||||
melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//报警
|
||||
|
||||
=======
|
||||
melsecPLCTCPDriver.WriteInt("552", 1);//红灯亮
|
||||
melsecPLCTCPDriver.WriteInt("554", 0);//其他灯灭
|
||||
melsecPLCTCPDriver.WriteInt("556", 0);
|
||||
melsecPLCTCPDriver.WriteInt("558", 1);//报警
|
||||
|
||||
|
||||
//加上人为判断是否是NG洗衣机
|
||||
DialogResult dr = MessageBox.Show("是否误检?", "是否误检", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
|
||||
if (dr == DialogResult.OK)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
|
||||
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
|
||||
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
|
||||
=======
|
||||
melsecPLCTCPDriver.WriteInt("552", 0);//红灯灭
|
||||
melsecPLCTCPDriver.WriteInt("554", 1);//黄灯亮
|
||||
melsecPLCTCPDriver.WriteInt("558", 0);//报警
|
||||
>>>>>>> 756d23229c59669d628dd94efb8876679bfe21f7
|
||||
|
||||
OKDsums++;
|
||||
WUsums++;
|
||||
this.Invoke(new Action(() =>
|
||||
@ -2003,15 +2027,11 @@ namespace HisenceYoloDetection
|
||||
else
|
||||
{
|
||||
NGDsums++;
|
||||
<<<<<<< HEAD
|
||||
|
||||
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
|
||||
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
|
||||
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
|
||||
=======
|
||||
melsecPLCTCPDriver.WriteInt("558", 0);//报警
|
||||
melsecPLCTCPDriver.WriteInt("552", 0);//红灯灭
|
||||
melsecPLCTCPDriver.WriteInt("554", 1);//黄灯亮
|
||||
>>>>>>> 756d23229c59669d628dd94efb8876679bfe21f7
|
||||
|
||||
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
@ -2321,18 +2341,14 @@ namespace HisenceYoloDetection
|
||||
Rect rect2 = new Rect(0, 0, 0, 0);
|
||||
|
||||
CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect2, rect2, false, "D://Hisence//Test1");
|
||||
<<<<<<< HEAD
|
||||
|
||||
*/
|
||||
|
||||
// OnGetBar();
|
||||
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
|
||||
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
|
||||
=======
|
||||
|
||||
*/
|
||||
// OnGetBar();
|
||||
melsecPLCTCPDriver.WriteInt("556", 1);//绿灯亮
|
||||
melsecPLCTCPDriver.WriteInt("554", 0);//黄灯灭
|
||||
|
||||
TriggerCameral2();//光电触发拍照 根据SN获取型号 从数据库中得到块值
|
||||
ReadyDetect();//相机拍照后检测线程
|
||||
ThreadPost();//相机拍照后获取当日的型号
|
||||
@ -2686,56 +2702,43 @@ namespace HisenceYoloDetection
|
||||
string productType = "N/A";
|
||||
string url = "http://172.16.139.146/FCCBOMWebService/FCCBomService.asmx/GetFCCBomInfoPDJson";
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
string today = dt.ToString("yyyy-MM-dd");
|
||||
string jsonData = @"
|
||||
{
|
||||
""StartTime"": ""2024-07-15"",
|
||||
""EndTime"": ""2024-07-15"",
|
||||
""LineBody"": ""BZ-PC""
|
||||
}";
|
||||
|
||||
string startTime = today;
|
||||
string endTime = today;
|
||||
string lineBody = "BZ-PC";
|
||||
string materialDescript = "皂盒";
|
||||
|
||||
JObject patientInfo = new JObject
|
||||
string postData = "inputvalue=" + Uri.EscapeDataString(jsonData);
|
||||
|
||||
try
|
||||
{
|
||||
["StartTime"] = startTime,
|
||||
["EndTime"] = endTime,
|
||||
["LineBody"] = lineBody,
|
||||
["MaterialDescripts"] = new JArray { materialDescript }
|
||||
};
|
||||
string response = PostData(url, postData);
|
||||
|
||||
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(0, m_sKEYENCEBar.Length - 7); // 目标 FinalDefID
|
||||
productType = FindStringAfterColon(response, finalDefIdToFind);
|
||||
if (productType != null)
|
||||
{
|
||||
Console.WriteLine($"{finalDefIdToFind}: {productType}");
|
||||
|
||||
// 将结果写入文件
|
||||
|
||||
|
||||
|
||||
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);
|
||||
Console.WriteLine($"FinalDefID {finalDefIdToFind} not found in response.");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("请求失败:未返回数据");
|
||||
Console.WriteLine("Error occurred:");
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
return productType;
|
||||
// sw.Stop();
|
||||
@ -3793,7 +3796,7 @@ namespace HisenceYoloDetection
|
||||
{
|
||||
if (!m_sKEYENCEBar.IsNullOrEmpty())
|
||||
{
|
||||
OcrBarBox.Text = m_sKEYENCEBar;
|
||||
OcrBarBox.Text = m_sKEYENCEBar.Substring(0, m_sKEYENCEBar.Length - 7);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user