apiclient 调用mes接口测试
This commit is contained in:
1 parent
f3110791a7
commit
1606c5fce9
1 file changed
+186
-74
@@ -15,13 +15,15 @@ using WindowsFormsApp1.db;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using HslCommunication.BasicFramework;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace WindowsFormsApp1.server
|
namespace WindowsFormsApp1.server
|
||||||
{
|
{
|
||||||
public class ApiClient
|
public class ApiClient
|
||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
private readonly Dictionary<string,string> apiUrlDict;
|
private readonly Dictionary<string, string> apiUrlDict;
|
||||||
|
|
||||||
public ApiClient()
|
public ApiClient()
|
||||||
{
|
{
|
||||||
@@ -31,7 +33,7 @@ namespace WindowsFormsApp1.server
|
|||||||
apiUrlDict = apiList.ToDictionary(x => x.code, x => x.url);
|
apiUrlDict = apiList.ToDictionary(x => x.code, x => x.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult SN_CheckIN(string url,plcdata PlcData, otherdata OtherData)
|
public ApiFormResult SN_CheckIN(string url, plcdata PlcData, otherdata OtherData)
|
||||||
{
|
{
|
||||||
// 组装 request json
|
// 组装 request json
|
||||||
var request = new
|
var request = new
|
||||||
@@ -70,13 +72,15 @@ namespace WindowsFormsApp1.server
|
|||||||
// 访问动态对象的属性
|
// 访问动态对象的属性
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
|
LogExecute.logNet.WriteDebug($"SN_CheckIN 接口请求成功\n请求:{jsonPayload}\n 返回: {res}");
|
||||||
|
|
||||||
// 成功!
|
// 成功!
|
||||||
if (!string.IsNullOrEmpty(res.RESULT))
|
if (!string.IsNullOrEmpty(res.RESULT.Value))
|
||||||
{
|
{
|
||||||
// 回写对应PLC
|
// 回写对应PLC
|
||||||
|
PlcData.Write_Status = PLC_Status.SN_CheckIN;
|
||||||
return res.RESULT == "pass" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG, PlcData, DateTime.Now)
|
return res.RESULT.Value == "PASS" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG.Value, PlcData, DateTime.Now)
|
||||||
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG, PlcData, DateTime.Now);
|
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG.Value, PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +93,7 @@ namespace WindowsFormsApp1.server
|
|||||||
{
|
{
|
||||||
throw new Exception(ex.Message);
|
throw new Exception(ex.Message);
|
||||||
}
|
}
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult Carrier_Check(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult Carrier_Check(string url, plcdata PlcData, otherdata OtherData)
|
||||||
@@ -130,13 +134,15 @@ namespace WindowsFormsApp1.server
|
|||||||
// 访问动态对象的属性
|
// 访问动态对象的属性
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
|
LogExecute.logNet.WriteDebug($"Carrier_Check 接口请求成功\n请求:{jsonPayload}\n 返回: {res}");
|
||||||
|
|
||||||
// 成功!
|
// 成功!
|
||||||
if (!string.IsNullOrEmpty(res.RESULT))
|
if (!string.IsNullOrEmpty(res.RESULT.Value))
|
||||||
{
|
{
|
||||||
// 回写对应PLC
|
// 回写对应PLC
|
||||||
|
PlcData.Write_Status = PLC_Status.Carrier_Check;
|
||||||
return res.RESULT == "pass" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG, PlcData, DateTime.Now)
|
return res.RESULT.Value == "PASS" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG.Value, PlcData, DateTime.Now)
|
||||||
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG, PlcData, DateTime.Now);
|
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG.Value, PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,7 +155,7 @@ namespace WindowsFormsApp1.server
|
|||||||
{
|
{
|
||||||
throw new Exception(ex.Message);
|
throw new Exception(ex.Message);
|
||||||
}
|
}
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult SN_FeedingCheck(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult SN_FeedingCheck(string url, plcdata PlcData, otherdata OtherData)
|
||||||
@@ -157,14 +163,14 @@ namespace WindowsFormsApp1.server
|
|||||||
// 组装 request json
|
// 组装 request json
|
||||||
var request = new
|
var request = new
|
||||||
{
|
{
|
||||||
EventID = "Carrier_Check",
|
EventID = "SN_FeedingCheck",
|
||||||
Line = "Testline",
|
Line = "Testline",
|
||||||
StationID = "TestStation",
|
StationID = "TestStation",
|
||||||
MachineID = "TestMachine",
|
MachineID = "TestMachine",
|
||||||
OPID = "OPID",
|
OPID = "OPID",
|
||||||
Token = "",
|
Token = "",
|
||||||
FixSN = "",
|
FixSN = "",
|
||||||
SN = PlcData.Read_MaterialCode0,
|
SN = OtherData.JS_SN,//扫码
|
||||||
SendTime = DateTime.Now
|
SendTime = DateTime.Now
|
||||||
};
|
};
|
||||||
// 使用 Newtonsoft.Json 进行序列化
|
// 使用 Newtonsoft.Json 进行序列化
|
||||||
@@ -189,13 +195,15 @@ namespace WindowsFormsApp1.server
|
|||||||
// 访问动态对象的属性
|
// 访问动态对象的属性
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
|
LogExecute.logNet.WriteDebug($"SN_FeedingCheck 接口请求成功\n请求:{jsonPayload}\n 返回: {res}");
|
||||||
|
|
||||||
// 成功!
|
// 成功!
|
||||||
if (!string.IsNullOrEmpty(res.RESULT))
|
if (!string.IsNullOrEmpty(res.RESULT.Value))
|
||||||
{
|
{
|
||||||
// 回写对应PLC
|
// 回写对应PLC
|
||||||
|
PlcData.Write_Status = PLC_Status.SN_FeedingCheck;
|
||||||
return res.RESULT == "pass" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG, PlcData, DateTime.Now)
|
return res.RESULT.Value == "PASS" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG.Value, PlcData, DateTime.Now)
|
||||||
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG, PlcData, DateTime.Now);
|
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG.Value, PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,12 +216,12 @@ namespace WindowsFormsApp1.server
|
|||||||
{
|
{
|
||||||
throw new Exception(ex.Message);
|
throw new Exception(ex.Message);
|
||||||
}
|
}
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult Link_Comp(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult Link_Comp(string url, plcdata PlcData, otherdata OtherData)
|
||||||
{
|
{
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult SN_Release(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult SN_Release(string url, plcdata PlcData, otherdata OtherData)
|
||||||
@@ -221,7 +229,7 @@ namespace WindowsFormsApp1.server
|
|||||||
// 组装 request json
|
// 组装 request json
|
||||||
var request = new
|
var request = new
|
||||||
{
|
{
|
||||||
EventID = "Carrier_Check",
|
EventID = "SN_Release",
|
||||||
Line = "Testline",
|
Line = "Testline",
|
||||||
StationID = "TestStation",
|
StationID = "TestStation",
|
||||||
MachineID = "TestMachine",
|
MachineID = "TestMachine",
|
||||||
@@ -254,13 +262,16 @@ namespace WindowsFormsApp1.server
|
|||||||
// 访问动态对象的属性
|
// 访问动态对象的属性
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
|
LogExecute.logNet.WriteDebug($"SN_Release 接口请求成功\n请求:{jsonPayload}\n 返回: {res}");
|
||||||
|
|
||||||
// 成功!
|
// 成功!
|
||||||
if (!string.IsNullOrEmpty(res.RESULT))
|
if (!string.IsNullOrEmpty(res.RESULT.Value))
|
||||||
{
|
{
|
||||||
// 回写对应PLC
|
// 回写对应PLC
|
||||||
PlcData.Write_stSN = res.MSG;
|
PlcData.Write_Status = PLC_Status.SN_Release;
|
||||||
return res.RESULT == "pass" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG, PlcData, DateTime.Now)
|
PlcData.Write_stSN = res.MSG.Value;
|
||||||
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG, PlcData, DateTime.Now);
|
return res.RESULT.Value == "PASS" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG.Value, PlcData, DateTime.Now)
|
||||||
|
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG.Value, PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,7 +284,7 @@ namespace WindowsFormsApp1.server
|
|||||||
{
|
{
|
||||||
throw new Exception(ex.Message);
|
throw new Exception(ex.Message);
|
||||||
}
|
}
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult Glue_CheckOut(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult Glue_CheckOut(string url, plcdata PlcData, otherdata OtherData)
|
||||||
@@ -313,13 +324,14 @@ namespace WindowsFormsApp1.server
|
|||||||
// 访问动态对象的属性
|
// 访问动态对象的属性
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
|
LogExecute.logNet.WriteDebug($"Glue_CheckOut 接口请求成功\n请求:{jsonPayload}\n 返回: {res}");
|
||||||
// 成功!
|
// 成功!
|
||||||
if (!string.IsNullOrEmpty(res.RESULT))
|
if (!string.IsNullOrEmpty(res.RESULT.Value))
|
||||||
{
|
{
|
||||||
// 回写对应PLC
|
// 回写对应PLC
|
||||||
|
PlcData.Write_Status = PLC_Status.Glue_CheckOut;
|
||||||
return res.RESULT == "pass" ? ApiFormResult.Sucess(mesresult.PASS, true, res.MSG, PlcData, DateTime.Now)
|
return res.RESULT.Value == "PASS" ? ApiFormResult.Sucess(mesresult.PASS, true, res.MSG.Value, PlcData, DateTime.Now)
|
||||||
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG, PlcData, DateTime.Now);
|
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG.Value, PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,22 +344,12 @@ namespace WindowsFormsApp1.server
|
|||||||
{
|
{
|
||||||
throw new Exception(ex.Message);
|
throw new Exception(ex.Message);
|
||||||
}
|
}
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
|
||||||
|
|
||||||
public ApiFormResult Get_Para(string url, plcdata PlcData, otherdata OtherData)
|
|
||||||
{
|
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApiFormResult DispatchPara(string url, plcdata PlcData, otherdata OtherData)
|
|
||||||
{
|
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult Data_Collection(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult Data_Collection(string url, plcdata PlcData, otherdata OtherData)
|
||||||
{
|
{
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult Status(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult Status(string url, plcdata PlcData, otherdata OtherData)
|
||||||
@@ -355,7 +357,7 @@ namespace WindowsFormsApp1.server
|
|||||||
// 组装 request json
|
// 组装 request json
|
||||||
var request = new
|
var request = new
|
||||||
{
|
{
|
||||||
EventID = "Carrier_Check",
|
EventID = "Status",
|
||||||
Line = "Testline",
|
Line = "Testline",
|
||||||
StationID = "TestStation",
|
StationID = "TestStation",
|
||||||
MachineID = "TestMachine",
|
MachineID = "TestMachine",
|
||||||
@@ -385,13 +387,15 @@ namespace WindowsFormsApp1.server
|
|||||||
// 访问动态对象的属性
|
// 访问动态对象的属性
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
|
LogExecute.logNet.WriteDebug($"Status 接口请求成功\n请求:{jsonPayload}\n 返回: {res}");
|
||||||
|
|
||||||
// 成功!
|
// 成功!
|
||||||
if (!string.IsNullOrEmpty(res.RESULT))
|
if (!string.IsNullOrEmpty(res.RESULT.Value))
|
||||||
{
|
{
|
||||||
// 回写对应PLC
|
// 回写对应PLC
|
||||||
|
PlcData.Write_Status = PLC_Status.Status;
|
||||||
return res.RESULT == "pass" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG, PlcData, DateTime.Now)
|
return res.RESULT.Value == "PASS" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG.Value, PlcData, DateTime.Now)
|
||||||
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG, PlcData, DateTime.Now);
|
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG.Value, PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -404,7 +408,7 @@ namespace WindowsFormsApp1.server
|
|||||||
{
|
{
|
||||||
throw new Exception(ex.Message);
|
throw new Exception(ex.Message);
|
||||||
}
|
}
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult Alarm(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult Alarm(string url, plcdata PlcData, otherdata OtherData)
|
||||||
@@ -412,7 +416,7 @@ namespace WindowsFormsApp1.server
|
|||||||
// 组装 request json
|
// 组装 request json
|
||||||
var request = new
|
var request = new
|
||||||
{
|
{
|
||||||
EventID = "Carrier_Check",
|
EventID = "Alarm",
|
||||||
Line = "Testline",
|
Line = "Testline",
|
||||||
StationID = "TestStation",
|
StationID = "TestStation",
|
||||||
MachineID = "TestMachine",
|
MachineID = "TestMachine",
|
||||||
@@ -443,13 +447,15 @@ namespace WindowsFormsApp1.server
|
|||||||
// 访问动态对象的属性
|
// 访问动态对象的属性
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
|
LogExecute.logNet.WriteDebug($"Alarm 接口请求成功\n请求:{jsonPayload}\n 返回: {res}");
|
||||||
|
|
||||||
// 成功!
|
// 成功!
|
||||||
if (!string.IsNullOrEmpty(res.RESULT))
|
if (!string.IsNullOrEmpty(res.RESULT.Value))
|
||||||
{
|
{
|
||||||
// 回写对应PLC
|
// 回写对应PLC
|
||||||
|
PlcData.Write_Status = PLC_Status.Alarm;
|
||||||
return res.RESULT == "pass" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG, PlcData, DateTime.Now)
|
return res.RESULT.Value == "PASS" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG.Value, PlcData, DateTime.Now)
|
||||||
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG, PlcData, DateTime.Now);
|
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG.Value, PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -462,22 +468,78 @@ namespace WindowsFormsApp1.server
|
|||||||
{
|
{
|
||||||
throw new Exception(ex.Message);
|
throw new Exception(ex.Message);
|
||||||
}
|
}
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
|
||||||
|
|
||||||
public ApiFormResult OEEDataCollection(string url, plcdata PlcData, otherdata OtherData)
|
|
||||||
{
|
|
||||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData,DateTime.Now);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult SN_FileUpload(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult SN_FileUpload(string url, plcdata PlcData, otherdata OtherData)
|
||||||
{
|
{
|
||||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData,DateTime.Now);
|
// 组装 request json
|
||||||
}
|
var request = new
|
||||||
|
{
|
||||||
|
Line = "Testline",
|
||||||
|
StationID = "TestStation",
|
||||||
|
MachineID = "TestMachine",
|
||||||
|
OPID = "OPID",
|
||||||
|
SNList = new List<dynamic>()
|
||||||
|
{
|
||||||
|
new
|
||||||
|
{
|
||||||
|
SN = OtherData.JS_SN,
|
||||||
|
FileInfo = new List<dynamic>()
|
||||||
|
{
|
||||||
|
new{
|
||||||
|
FileName = OtherData.FileUploadAddress,
|
||||||
|
FilePath = OtherData.FileUploadAddress
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
SendTime = DateTime.Now
|
||||||
|
};
|
||||||
|
// 使用 Newtonsoft.Json 进行序列化
|
||||||
|
string jsonPayload = JsonConvert.SerializeObject(request);
|
||||||
|
|
||||||
public ApiFormResult Test(string url, plcdata PlcData, otherdata OtherData)
|
// 创建 StringContent 对象,将 JSON 字符串作为请求体,指定编码和媒体类型
|
||||||
{
|
var httpContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
||||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData,DateTime.Now);
|
|
||||||
|
// 调用接口
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = _httpClient.PostAsync(url, httpContent).Result;
|
||||||
|
// 检查响应状态码
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
// 读取响应内容
|
||||||
|
string responseContent = response.Content.ReadAsStringAsync().Result;
|
||||||
|
|
||||||
|
// 使用 Newtonsoft.Json 将响应内容反序列化为动态对象
|
||||||
|
dynamic res = JsonConvert.DeserializeObject(responseContent);
|
||||||
|
|
||||||
|
// 访问动态对象的属性
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
LogExecute.logNet.WriteDebug($"SN_FileUpload 接口请求成功\n请求:{jsonPayload}\n 返回: {res}");
|
||||||
|
|
||||||
|
// 成功!
|
||||||
|
if (!string.IsNullOrEmpty(res.ErrorMessage.Value))
|
||||||
|
{
|
||||||
|
// 回写对应PLC
|
||||||
|
PlcData.Write_Status = PLC_Status.SN_FileUpload;
|
||||||
|
return res.IsSuccess.Value == true ? ApiFormResult.Sucess(mesresult.PASS, true, res.ErrorMessage.Value, PlcData, DateTime.Now)
|
||||||
|
: ApiFormResult.Sucess(mesresult.FAIL, false, res.ErrorMessage.Value, PlcData, DateTime.Now);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"请求失败,状态码:{response.StatusCode}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception(ex.Message);
|
||||||
|
}
|
||||||
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult CodeSoftPrint(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult CodeSoftPrint(string url, plcdata PlcData, otherdata OtherData)
|
||||||
@@ -485,7 +547,7 @@ namespace WindowsFormsApp1.server
|
|||||||
// 组装 request json
|
// 组装 request json
|
||||||
var request = new
|
var request = new
|
||||||
{
|
{
|
||||||
Line = "Testline",
|
Line = "CodeSoftPrint",
|
||||||
StationID = "TestStation",
|
StationID = "TestStation",
|
||||||
MachineID = "TestMachine",
|
MachineID = "TestMachine",
|
||||||
SN = PlcData.Read_MaterialCode0
|
SN = PlcData.Read_MaterialCode0
|
||||||
@@ -512,13 +574,15 @@ namespace WindowsFormsApp1.server
|
|||||||
// 访问动态对象的属性
|
// 访问动态对象的属性
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
|
LogExecute.logNet.WriteDebug($"SN_FileUpload 接口请求成功\n请求:{jsonPayload}\n 返回: {res}");
|
||||||
|
|
||||||
// 成功!
|
// 成功!
|
||||||
if (!string.IsNullOrEmpty(res.ErrorMessage))
|
if (!string.IsNullOrEmpty(res.ErrorMessage.Value))
|
||||||
{
|
{
|
||||||
// 回写对应PLC
|
// 回写对应PLC
|
||||||
// res.ErrorMessage.Contains("OK")
|
PlcData.Write_Status = PLC_Status.CodeSoftPrint;
|
||||||
return res.IsSuccess == true ? ApiFormResult.Sucess(mesresult.PASS, true, res.ErrorMessage, PlcData, DateTime.Now)
|
return res.IsSuccess.Value == true ? ApiFormResult.Sucess(mesresult.PASS, true, res.ErrorMessage.Value, PlcData, DateTime.Now)
|
||||||
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG, PlcData, DateTime.Now);
|
: ApiFormResult.Sucess(mesresult.FAIL, false, res.ErrorMessage.Value, PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -537,7 +601,7 @@ namespace WindowsFormsApp1.server
|
|||||||
public ApiFormResult SN_Checkout(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult SN_Checkout(string url, plcdata PlcData, otherdata OtherData)
|
||||||
{
|
{
|
||||||
var lineCode = Init.t_Line.linecode;
|
var lineCode = Init.t_Line.linecode;
|
||||||
switch(lineCode)
|
switch (lineCode)
|
||||||
{
|
{
|
||||||
case "OP1060": // 追溯码+载具,默认(todo)
|
case "OP1060": // 追溯码+载具,默认(todo)
|
||||||
case "OP1120":
|
case "OP1120":
|
||||||
@@ -586,16 +650,38 @@ namespace WindowsFormsApp1.server
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData,DateTime.Now);
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult Initialization(string url, plcdata PlcData, otherdata OtherData)
|
public ApiFormResult Initialization(string url, plcdata PlcData, otherdata OtherData)
|
||||||
{
|
{
|
||||||
PlcData.Write_Status = 3;
|
PlcData.Write_Status = 3;
|
||||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiFormResult CallFunctionByName(string functionName, plcdata plcdata,otherdata otherdata)
|
#region 暂时不用
|
||||||
|
public ApiFormResult Test(string url, plcdata PlcData, otherdata OtherData)
|
||||||
|
{
|
||||||
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiFormResult OEEDataCollection(string url, plcdata PlcData, otherdata OtherData)
|
||||||
|
{
|
||||||
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiFormResult Get_Para(string url, plcdata PlcData, otherdata OtherData)
|
||||||
|
{
|
||||||
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiFormResult DispatchPara(string url, plcdata PlcData, otherdata OtherData)
|
||||||
|
{
|
||||||
|
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||||
|
}
|
||||||
|
#endregion 暂时不用
|
||||||
|
|
||||||
|
public ApiFormResult CallFunctionByName(string functionName, plcdata plcdata, otherdata otherdata)
|
||||||
{
|
{
|
||||||
// 定义重试策略
|
// 定义重试策略
|
||||||
var retryPolicy = Policy
|
var retryPolicy = Policy
|
||||||
@@ -649,7 +735,7 @@ namespace WindowsFormsApp1.server
|
|||||||
{
|
{
|
||||||
// 如果所有调用都失败,打印失败日志
|
// 如果所有调用都失败,打印失败日志
|
||||||
LogExecute.logNet.WriteError("所有调用都失败了!");
|
LogExecute.logNet.WriteError("所有调用都失败了!");
|
||||||
return ApiFormResult.Error(mesresult.FAIL, false, "", null,DateTime.Now);
|
return ApiFormResult.Error(mesresult.FAIL, false, "", null, DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -672,5 +758,31 @@ namespace WindowsFormsApp1.server
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed class PLC_Status
|
||||||
|
{
|
||||||
|
public const int SN_CheckIN = 10;
|
||||||
|
public const int Carrier_Check = 20;
|
||||||
|
public const int SN_FeedingCheck = 30;
|
||||||
|
public const int Link_Comp = 40;
|
||||||
|
public const int SN_Release = 50;
|
||||||
|
public const int Glue_CheckOut = 60;
|
||||||
|
public const int Get_Para = 70;
|
||||||
|
public const int DispatchPara = 80;
|
||||||
|
public const int Data_Collection = 90;
|
||||||
|
public const int Status = 100;
|
||||||
|
public const int Alarm = 110;
|
||||||
|
public const int OEEDataCollection = 120;
|
||||||
|
public const int SN_FileUpload = 130;
|
||||||
|
public const int Test = 140;
|
||||||
|
public const int GetLaserpara = 150;
|
||||||
|
public const int Order_Get = 160;
|
||||||
|
public const int CodeSoftPrint = 170;
|
||||||
|
public const int SN_Checkout = 200;
|
||||||
|
public const int Initialization = 3;
|
||||||
|
|
||||||
|
public const int Fail = 1001;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user