串口读取数据修改
apiclient现场测试
This commit is contained in:
1 parent
6c7278ed45
commit
2bd24f5316
3 files changed
+176
-107
No files matched your search
@@ -43,7 +43,7 @@ namespace WindowsFormsApp1.server
|
||||
_line = "Testline";
|
||||
_stationID = "TestStation";
|
||||
_machineID = "TestMachine";
|
||||
_opID = "OPID";
|
||||
_opID = "";
|
||||
}
|
||||
|
||||
// 通用API调用方法,减少代码重复
|
||||
@@ -58,6 +58,16 @@ namespace WindowsFormsApp1.server
|
||||
// 调用接口
|
||||
try
|
||||
{
|
||||
// 测试
|
||||
LogExecute.logNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}");
|
||||
|
||||
// 回写对应PLC
|
||||
if (statusCode > 0)
|
||||
PlcData.Write_Status = (short)statusCode;
|
||||
if (eventName == "SN_Release")
|
||||
PlcData.Write_stSN = "testsn";
|
||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||
/*
|
||||
var response = _httpClient.PostAsync(url, httpContent).Result;
|
||||
// 检查响应状态码
|
||||
if (response.IsSuccessStatusCode)
|
||||
@@ -71,18 +81,24 @@ namespace WindowsFormsApp1.server
|
||||
// 访问动态对象的属性
|
||||
if (res != null)
|
||||
{
|
||||
LogExecute.logNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {res}");
|
||||
LogExecute.logNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
|
||||
|
||||
// 成功!
|
||||
if (res.RESULT != null && !string.IsNullOrEmpty(res.RESULT.Value))
|
||||
if (res.Result != null && !string.IsNullOrEmpty(res.Result.Value))
|
||||
{
|
||||
// 回写对应PLC
|
||||
if (statusCode > 0)
|
||||
PlcData.Write_Status = (short)statusCode;
|
||||
var result = res.Result.Value == "PASS";
|
||||
|
||||
return res.RESULT.Value == "PASS"
|
||||
if (result)
|
||||
{
|
||||
// 回写对应PLC
|
||||
if (statusCode > 0)
|
||||
PlcData.Write_Status = (short)statusCode;
|
||||
if(eventName == "SN_Release")
|
||||
PlcData.Write_stSN = res.SN.Value;
|
||||
}
|
||||
return result
|
||||
? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG.Value, PlcData, DateTime.Now)
|
||||
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG.Value, PlcData, DateTime.Now);
|
||||
: ApiFormResult.Sucess(mesresult.FAIL, true, res.MSG.Value, PlcData, DateTime.Now);
|
||||
}
|
||||
else if (res.IsSuccess != null) // 打印 mes不返回result
|
||||
{
|
||||
@@ -99,13 +115,14 @@ namespace WindowsFormsApp1.server
|
||||
{
|
||||
throw new Exception($"请求失败,状态码:{response.StatusCode}");
|
||||
}
|
||||
*/
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogExecute.logNet.WriteError($"{eventName} 接口请求失败: {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_CheckIN(string url, plcdata PlcData, otherdata OtherData)
|
||||
@@ -120,9 +137,9 @@ namespace WindowsFormsApp1.server
|
||||
OPID = _opID,
|
||||
Token = "",
|
||||
FixSN = "",
|
||||
SN = PlcData.Read_MaterialCode0,
|
||||
CarrierID = PlcData.Read_MaterialCode1,
|
||||
SendTime = DateTime.Now
|
||||
SN = PlcData.Read_MaterialCode1,
|
||||
CarrierID = "",
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "SN_CheckIN", PlcData, PLC_Status.SN_CheckIN);
|
||||
@@ -141,7 +158,7 @@ namespace WindowsFormsApp1.server
|
||||
Token = "",
|
||||
FixSN = "",
|
||||
CarrierID = PlcData.Read_MaterialCode1,
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "Carrier_Check", PlcData, PLC_Status.Carrier_Check);
|
||||
@@ -160,7 +177,7 @@ namespace WindowsFormsApp1.server
|
||||
Token = "",
|
||||
FixSN = "",
|
||||
SN = OtherData.JS_SN,//扫码
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "SN_FeedingCheck", PlcData, PLC_Status.SN_FeedingCheck);
|
||||
@@ -179,7 +196,7 @@ namespace WindowsFormsApp1.server
|
||||
Token = "",
|
||||
FixSN = "",
|
||||
SN = OtherData.JS_SN,
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "Link_Comp", PlcData, PLC_Status.Link_Comp);
|
||||
@@ -197,47 +214,12 @@ namespace WindowsFormsApp1.server
|
||||
OPID = _opID,
|
||||
Token = "",
|
||||
FixSN = "",
|
||||
SN = OtherData.JS_SN,
|
||||
SN = Init.ScanString,
|
||||
CarrierID = "",
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
// 特殊处理:需要设置Write_stSN
|
||||
string jsonPayload = JsonConvert.SerializeObject(request);
|
||||
var httpContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
||||
|
||||
try
|
||||
{
|
||||
var response = _httpClient.PostAsync(url, httpContent).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
dynamic res = JsonConvert.DeserializeObject(responseContent);
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
LogExecute.logNet.WriteDebug($"SN_Release 接口请求成功\n请求:{jsonPayload}\n 返回: {res}");
|
||||
|
||||
if (!string.IsNullOrEmpty(res.RESULT.Value))
|
||||
{
|
||||
PlcData.Write_Status = PLC_Status.SN_Release;
|
||||
PlcData.Write_stSN = res.MSG.Value; // 特殊处理
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"请求失败,状态码:{response.StatusCode}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogExecute.logNet.WriteError($"SN_Release 接口请求失败: {ex.Message}");
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||
return CallApi(url, request, "SN_Release", PlcData, PLC_Status.SN_Release);
|
||||
}
|
||||
|
||||
public ApiFormResult Glue_CheckOut(string url, plcdata PlcData, otherdata OtherData)
|
||||
@@ -253,7 +235,7 @@ namespace WindowsFormsApp1.server
|
||||
Token = "",//判断站,胶水不用传
|
||||
FixSN = "",//判断站,胶水不用传
|
||||
SN = PlcData.Read_MaterialCode0,
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "Glue_CheckOut", PlcData, PLC_Status.Glue_CheckOut);
|
||||
@@ -270,7 +252,7 @@ namespace WindowsFormsApp1.server
|
||||
MachineID = _machineID,
|
||||
OPID = _opID,
|
||||
SN = OtherData.JS_SN,
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "Data_Collection", PlcData, PLC_Status.Data_Collection);
|
||||
@@ -287,10 +269,9 @@ namespace WindowsFormsApp1.server
|
||||
MachineID = _machineID,
|
||||
OPID = _opID,
|
||||
STATUS = OtherData.Plc_Status,
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
// 注意:这个API不需要设置PlcData.Write_Status
|
||||
return CallApi(url, request, "Status", PlcData, 0);
|
||||
}
|
||||
|
||||
@@ -305,11 +286,11 @@ namespace WindowsFormsApp1.server
|
||||
MachineID = _machineID,
|
||||
OPID = _opID,
|
||||
AlarmID = OtherData.Plc_ErrorMsgs[0],
|
||||
SendTime = DateTime.Now,
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
|
||||
ResetTime = ""
|
||||
};
|
||||
|
||||
return CallApi(url, request, "Alarm", PlcData, PLC_Status.Alarm);
|
||||
return CallApi(url, request, "Alarm", PlcData, 0);
|
||||
}
|
||||
|
||||
public ApiFormResult SN_FileUpload(string url, plcdata PlcData, otherdata OtherData)
|
||||
@@ -336,7 +317,7 @@ namespace WindowsFormsApp1.server
|
||||
}
|
||||
}
|
||||
},
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "SN_FileUpload", PlcData, PLC_Status.SN_FileUpload);
|
||||
@@ -362,17 +343,48 @@ namespace WindowsFormsApp1.server
|
||||
var lineCode = Init.t_Line.linecode;
|
||||
|
||||
// 基础请求对象
|
||||
var request = new
|
||||
var request = new CheckOutObject()
|
||||
{
|
||||
EventID = "SN_Checkout",
|
||||
Line = _line,
|
||||
StationID = _stationID,
|
||||
MachineID = _machineID,
|
||||
OPID = _opID,
|
||||
SN = OtherData.JS_SN,
|
||||
SendTime = DateTime.Now
|
||||
SNInfo = new List<SNInfoItem>()
|
||||
{
|
||||
new SNInfoItem()
|
||||
{
|
||||
SN = PlcData.Read_MaterialCode0,
|
||||
Result = PlcData.Read_Result == 1 ? "PASS" : "FAIL",
|
||||
DC_INFO = new List<DCInfoItem>()
|
||||
{
|
||||
new DCInfoItem()
|
||||
{
|
||||
Item = PlcData.Read_MaterialCode2,
|
||||
Value = PlcData.Read_UploadData1.ToString(),
|
||||
Result = PlcData.Read_Result == 1 ? "PASS" : "FAIL"
|
||||
}
|
||||
},
|
||||
CompList = new List<CompListItem>()
|
||||
{
|
||||
new CompListItem()
|
||||
{
|
||||
CompID = "",
|
||||
Qty = "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Qty = "",
|
||||
CarrierID = PlcData.Read_MaterialCode1,
|
||||
Mold = "",
|
||||
Token = "",
|
||||
FixSN = "",
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
//LogExecute.logNet.WriteDebug($"checkout:{request}");
|
||||
|
||||
// 根据不同的lineCode可以在这里扩展request对象
|
||||
switch (lineCode)
|
||||
{
|
||||
@@ -386,6 +398,11 @@ namespace WindowsFormsApp1.server
|
||||
|
||||
case "OP1010":// 传气密
|
||||
case "OP1330":
|
||||
var dcInfo = new DCInfoItem();
|
||||
dcInfo.Item = PlcData.Read_MaterialCode2;
|
||||
dcInfo.Value = "气密测试值";
|
||||
dcInfo.Result = "PASS";
|
||||
//request.SNInfo
|
||||
break;
|
||||
|
||||
case "OP1050":// 胶水码
|
||||
@@ -426,17 +443,6 @@ namespace WindowsFormsApp1.server
|
||||
|
||||
public ApiFormResult Initialization(string url, plcdata PlcData, otherdata OtherData)
|
||||
{
|
||||
// 组装 request json
|
||||
var request = new
|
||||
{
|
||||
EventID = "Initialization",
|
||||
Line = _line,
|
||||
StationID = _stationID,
|
||||
MachineID = _machineID,
|
||||
OPID = _opID,
|
||||
SendTime = DateTime.Now
|
||||
};
|
||||
|
||||
// 直接设置状态码
|
||||
PlcData.Write_Status = PLC_Status.Initialization;
|
||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||
@@ -452,7 +458,7 @@ namespace WindowsFormsApp1.server
|
||||
StationID = _stationID,
|
||||
MachineID = _machineID,
|
||||
OPID = _opID,
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "Test", PlcData, PLC_Status.Test);
|
||||
@@ -467,7 +473,7 @@ namespace WindowsFormsApp1.server
|
||||
StationID = _stationID,
|
||||
MachineID = _machineID,
|
||||
OPID = _opID,
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "OEEDataCollection", PlcData, PLC_Status.OEEDataCollection);
|
||||
@@ -482,7 +488,7 @@ namespace WindowsFormsApp1.server
|
||||
StationID = _stationID,
|
||||
MachineID = _machineID,
|
||||
OPID = _opID,
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "Get_Para", PlcData, PLC_Status.Get_Para);
|
||||
@@ -497,7 +503,7 @@ namespace WindowsFormsApp1.server
|
||||
StationID = _stationID,
|
||||
MachineID = _machineID,
|
||||
OPID = _opID,
|
||||
SendTime = DateTime.Now
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "DispatchPara", PlcData, PLC_Status.DispatchPara);
|
||||
@@ -599,5 +605,47 @@ namespace WindowsFormsApp1.server
|
||||
|
||||
public const int Fail = 1001;
|
||||
}
|
||||
|
||||
//checkout class
|
||||
// 根对象类
|
||||
public class CheckOutObject
|
||||
{
|
||||
public List<SNInfoItem> SNInfo { get; set; }
|
||||
public string Qty { get; set; }
|
||||
public string Mold { get; set; }
|
||||
public string EventID { get; set; }
|
||||
public string Line { get; set; }
|
||||
public string StationID { get; set; }
|
||||
public string MachineID { get; set; }
|
||||
public string CarrierID { get; set; }
|
||||
public string OPID { get; set; }
|
||||
public string SendTime { get; set; }
|
||||
public string Token { get; set; }
|
||||
public string FixSN { get; set; }
|
||||
}
|
||||
|
||||
// SNInfo 列表中的每个元素类
|
||||
public class SNInfoItem
|
||||
{
|
||||
public string SN { get; set; }
|
||||
public string Result { get; set; }
|
||||
public List<DCInfoItem> DC_INFO { get; set; }
|
||||
public List<CompListItem> CompList { get; set; }
|
||||
}
|
||||
|
||||
// DC_INFO 列表中的每个元素类
|
||||
public class DCInfoItem
|
||||
{
|
||||
public string Item { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string Result { get; set; }
|
||||
}
|
||||
|
||||
// CompList 列表中的每个元素类
|
||||
public class CompListItem
|
||||
{
|
||||
public string CompID { get; set; }
|
||||
public string Qty { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user