|
|
@@ -10,7 +10,6 @@ using System.Threading.Tasks;
|
|
|
using TeamAAS_VP.Enums;
|
|
|
using TeamAAS_VP.Events;
|
|
|
using TeamAAS_VP.Interfaces;
|
|
|
-using TeamAAS_VP.Models;
|
|
|
|
|
|
namespace TeamAAS_VP.Services
|
|
|
{
|
|
|
@@ -87,7 +86,7 @@ namespace TeamAAS_VP.Services
|
|
|
device = _configService.GetDeviceInfo();
|
|
|
if (device == null || !device.EnableMES)
|
|
|
{
|
|
|
- return (true, "MES功能未启用!");
|
|
|
+ return (false, "MES功能未启用!");
|
|
|
}
|
|
|
if (string.IsNullOrWhiteSpace(device.MesUrl))
|
|
|
return (false, "Missing MES station URL");
|
|
|
@@ -100,21 +99,20 @@ namespace TeamAAS_VP.Services
|
|
|
}
|
|
|
|
|
|
string url = "";
|
|
|
-
|
|
|
if (deviceNo == 0)//组装站
|
|
|
{
|
|
|
if (device.F == "PTL")
|
|
|
{
|
|
|
- url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&comp={device.comp}:{comp}&p=unit_process_check,message,model,sn,wo";
|
|
|
+ url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&comp={device.comp}:{comp}&p=message,sn,wo,model_num,color";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=unit_process_check,message,model,sn,wo";
|
|
|
+ url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=message,sn,wo,model_num,color";
|
|
|
}
|
|
|
}
|
|
|
else//保压站
|
|
|
{
|
|
|
- url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=unit_process_check,message,model,sn,wo";
|
|
|
+ url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=message,sn,wo,model_num,color";
|
|
|
}
|
|
|
|
|
|
LogHelper.WriteLogMes($"【询问URL】{url}");
|
|
|
@@ -197,7 +195,7 @@ namespace TeamAAS_VP.Services
|
|
|
device = _configService.GetDeviceInfo();
|
|
|
if (device == null || !device.EnableMES)
|
|
|
{
|
|
|
- return (true, "MES功能未启用!");
|
|
|
+ return (false, "MES功能未启用!");
|
|
|
}
|
|
|
if (string.IsNullOrWhiteSpace(device.MesUrl))
|
|
|
return (false, "Missing MES station URL");
|
|
|
@@ -242,6 +240,93 @@ namespace TeamAAS_VP.Services
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 向配置中指定的 MES 站点 URL 发起 GET 请求(用于零件使用查询)。
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="partSN">要查询的序列号(SN)。</param>
|
|
|
+ /// <param name="cancellationToken">可选的取消令牌,用于请求超时或取消。</param>
|
|
|
+ /// <returns>
|
|
|
+ /// 返回元组 (IsSuccess, Response):
|
|
|
+ /// - IsSuccess: 请求是否视为成功(即 MES 返回了预期的 "SFC_OK" 且包含 "unit_process_check=OK")。
|
|
|
+ /// - Response: 原始响应文本或错误信息说明(如 "MES功能未启用!"、"Missing MES station URL"、"Canceled" 等)。
|
|
|
+ /// </returns>
|
|
|
+ /// <remarks>
|
|
|
+ /// 行为说明:
|
|
|
+ /// - 从配置获取设备信息,若 MES 未启用则直接返回 IsSuccess=true 且 Response 为提示文本(不视为错误)。
|
|
|
+ /// - 若未配置 MES URL 则返回 IsSuccess=false 与错误文本。
|
|
|
+ /// - 使用配置的 URL(通过 <see cref="string.Format"/> 填充 sn)发起 GET 请求,最多重试 10 次。
|
|
|
+ /// - 只有当响应包含 "SFC_OK" 且包含 "unit_process_check=OK" 时视为成功并立即返回。
|
|
|
+ /// - 捕获 <see cref="OperationCanceledException"/> 返回 "Canceled",捕获其它异常则返回异常消息。
|
|
|
+ /// - 若实例已被释放则抛出 <see cref="ObjectDisposedException"/>。
|
|
|
+ /// </remarks>
|
|
|
+ public async Task<(bool IsSuccess, string Response)> StationGetEx2Async(int deviceNo, string partSN, string comp, CancellationToken cancellationToken = default)
|
|
|
+ {
|
|
|
+ // 如果已经释放,则抛出异常,防止在已释放资源上继续操作。
|
|
|
+ if (_disposed) throw new ObjectDisposedException(nameof(MesService));
|
|
|
+
|
|
|
+ var device = _configService.GetDeviceInfo(deviceNo);
|
|
|
+ if (device == null)
|
|
|
+ device = _configService.GetDeviceInfo();
|
|
|
+ if (device == null || !device.EnableMES)
|
|
|
+ {
|
|
|
+ return (false, "MES功能未启用!");
|
|
|
+ }
|
|
|
+ if (string.IsNullOrWhiteSpace(device.MesUrl))
|
|
|
+ return (false, "Missing MES station URL");
|
|
|
+
|
|
|
+ string url = "";
|
|
|
+ url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={partSN}&p=sn,message";
|
|
|
+
|
|
|
+ LogHelper.WriteLogMes($"【询问URL】{url}");
|
|
|
+ SendTaskMessage($"【询问URL】{url}", MessageLevel.Info);
|
|
|
+ (bool IsSuccess, string Response) result = (false, string.Empty);
|
|
|
+
|
|
|
+ for (int i = 0; i < 3; i++)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var rsp = await _httpClient.GetAsync(url))
|
|
|
+ {
|
|
|
+ var text = await rsp.Content.ReadAsStringAsync();
|
|
|
+ LogHelper.WriteLogMes($"【HTTP接收】{text}");
|
|
|
+ SendTaskMessage($"【HTTP接收】{text}", MessageLevel.Info);
|
|
|
+
|
|
|
+ // "SFC_OK" 代表和 MES 连接成功
|
|
|
+ if (text.Contains("SFC_OK"))
|
|
|
+ {
|
|
|
+ string[] item = text.Split('\n');
|
|
|
+ string snItem = item.FirstOrDefault(f => f.Contains("sn="));
|
|
|
+ if (snItem != null)
|
|
|
+ {
|
|
|
+ if (snItem.Replace("sn=", "").Length == 0)//如果零件没做过
|
|
|
+ {
|
|
|
+ return (true, text);
|
|
|
+ }
|
|
|
+ else//如果零件已做过
|
|
|
+ {
|
|
|
+ string ProductMainSN_Temp = snItem.Replace("sn=", "").Trim();
|
|
|
+ SendTaskMessage($"零件已绑定sn:{ProductMainSN_Temp}", MessageLevel.Error);
|
|
|
+ return (false, text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result = (false, text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (OperationCanceledException)
|
|
|
+ {
|
|
|
+ result = (false, "Canceled");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ result = (false, ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public async Task<(bool IsSuccess, string Response)> StationGetExAsync(int deviceNo, string sn, string comp, double timeoutInSeconds)
|
|
|
{
|
|
|
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutInSeconds)))
|
|
|
@@ -250,6 +335,14 @@ namespace TeamAAS_VP.Services
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public async Task<(bool IsSuccess, string Response)> StationGetEx2Async(int deviceNo, string partSN, string comp, double timeoutInSeconds)
|
|
|
+ {
|
|
|
+ using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutInSeconds)))
|
|
|
+ {
|
|
|
+ return await StationGetEx2Async(deviceNo, partSN, comp, cts.Token);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 向配置中指定的 MES 提交 URL 发起 GET 请求(用于提交测试结果/记录)。
|
|
|
/// </summary>
|
|
|
@@ -317,26 +410,15 @@ namespace TeamAAS_VP.Services
|
|
|
|
|
|
string url = sb.ToString();
|
|
|
|
|
|
- //if (deviceNo == 0)//组装站
|
|
|
+ //if (device.F == "PTL")
|
|
|
//{
|
|
|
- // if (device.F == "PTL")
|
|
|
- // {
|
|
|
- // url = $"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={station[deviceNo]}&fixtureid={fixtureId[deviceNo]}&sn={sn}&f=PTL&comp={device.comp}:{comp}" +
|
|
|
- // $"&gap={gap}&assy_pressure={assypress}" +
|
|
|
- // $"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // url = $"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={station[deviceNo]}&fixtureid={fixtureId[deviceNo]}&sn={sn}&f=PQC" +
|
|
|
- // $"&gap={gap}&assy_pressure={assypress}" +
|
|
|
- // $"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
|
|
|
- // }
|
|
|
+ // url = $"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&f=PTL&comp={device.comp}:{comp}" +
|
|
|
+ // $"&cc={cc}&laser_height={height}&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
- // url = $"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={station[deviceNo]}&fixtureid={fixtureId[deviceNo]}&sn={sn}&f=PQC" +
|
|
|
- // $"&pressure={press}&pressure_time={presstime}" +
|
|
|
- // $"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
|
|
|
+ // url = $"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&f=PQC" +
|
|
|
+ // $"&cc={cc}&laser_height={height}&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
|
|
|
//}
|
|
|
|
|
|
LogHelper.WriteLogMes($"【上传URL】{url}");
|
|
|
@@ -377,6 +459,76 @@ namespace TeamAAS_VP.Services
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ public async Task<(bool IsSuccess, string Response)> StationGetBindingAsync(string sn, string bindingData, uint bindingModel, double timeoutInSeconds)
|
|
|
+ {
|
|
|
+ using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutInSeconds)))
|
|
|
+ {
|
|
|
+ return await StationGetBindingAsync(sn, bindingData, bindingModel, cts.Token);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 绑定交互
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sn"></param>
|
|
|
+ /// <param name="bindingData"></param>
|
|
|
+ /// <param name="bindingModel"> 0=查询,1=绑定,2=解绑</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="ObjectDisposedException"></exception>
|
|
|
+ public async Task<(bool IsSuccess, string Response)> StationGetBindingAsync(string sn, string bindingData, uint bindingModel, CancellationToken cancellationToken = default)
|
|
|
+ {
|
|
|
+ // 如果已经释放,则抛出异常,防止在已释放资源上继续操作。
|
|
|
+ if (_disposed) throw new ObjectDisposedException(nameof(MesService));
|
|
|
+
|
|
|
+ var device = _configService.GetDeviceInfo();
|
|
|
+ if (device == null || !device.EnableMES)
|
|
|
+ {
|
|
|
+ return (false, "MES功能未启用!");
|
|
|
+ }
|
|
|
+ if (string.IsNullOrWhiteSpace(device.MesUrl))
|
|
|
+ return (false, "Missing MES station URL");
|
|
|
+
|
|
|
+ string url = "";
|
|
|
+ url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=message,sn,wo";
|
|
|
+
|
|
|
+ LogHelper.WriteLogMes($"【询问URL】{url}");
|
|
|
+ SendTaskMessage($"【询问URL】{url}", MessageLevel.Info);
|
|
|
+ (bool IsSuccess, string Response) result = (false, string.Empty);
|
|
|
+
|
|
|
+ for (int i = 0; i < 3; i++)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var rsp = await _httpClient.GetAsync(url))
|
|
|
+ {
|
|
|
+ var text = await rsp.Content.ReadAsStringAsync();
|
|
|
+ LogHelper.WriteLogMes($"【HTTP接收】{text}");
|
|
|
+ SendTaskMessage($"【HTTP接收】{text}", MessageLevel.Info);
|
|
|
+
|
|
|
+ // "SFC_OK" 代表和 MES 连接成功
|
|
|
+ if (text.Contains("SFC_OK"))
|
|
|
+ {
|
|
|
+ if (text.Contains("message=OK"))
|
|
|
+ {
|
|
|
+ return (true, text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result = (false, text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (OperationCanceledException)
|
|
|
+ {
|
|
|
+ result = (false, "Canceled");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ result = (false, ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 向 MES 提交请求的超时重载,使用超时(秒)作为便捷参数。
|
|
|
/// </summary>
|
|
|
@@ -410,17 +562,17 @@ namespace TeamAAS_VP.Services
|
|
|
device = _configService.GetDeviceInfo();
|
|
|
if (device == null || !device.EnableMES)
|
|
|
{
|
|
|
- return (true, DateTime.UtcNow);
|
|
|
+ return (true, DateTime.Now);
|
|
|
}
|
|
|
if (string.IsNullOrWhiteSpace(device.MesUrl))
|
|
|
- return (false, DateTime.UtcNow);
|
|
|
+ return (false, DateTime.Now);
|
|
|
|
|
|
string url = "";
|
|
|
url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=mes_server_time";
|
|
|
|
|
|
LogHelper.WriteLogMes($"【询问URL】{url}");
|
|
|
SendTaskMessage($"【询问URL】{url}", MessageLevel.Info);
|
|
|
- (bool IsSuccess, DateTime Now) result = (false, DateTime.UtcNow);
|
|
|
+ (bool IsSuccess, DateTime Now) result = (false, DateTime.Now);
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
{
|
|
|
@@ -449,16 +601,16 @@ namespace TeamAAS_VP.Services
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- result = (false, DateTime.UtcNow);
|
|
|
+ result = (false, DateTime.Now);
|
|
|
}
|
|
|
}
|
|
|
catch (OperationCanceledException)
|
|
|
{
|
|
|
- result = (false, DateTime.UtcNow);
|
|
|
+ result = (false, DateTime.Now);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- result = (false, DateTime.UtcNow);
|
|
|
+ result = (false, DateTime.Now);
|
|
|
}
|
|
|
}
|
|
|
return result;
|