合并2
This commit is contained in:
parent
7b2c4fa68a
commit
b2ba8650d2
@ -139,16 +139,22 @@ namespace WindowsFormsApp1
|
||||
if (oldstatus != PlcData.Read_Status || (Plc_Time - oldPlcstatus_LastTime).TotalSeconds > 5)
|
||||
{
|
||||
//反馈状态
|
||||
Init.Plcstatus = PlcData.Read_Status;
|
||||
Init.Plcstatus_LastTime = DateTime.Now;
|
||||
otherdata.Plc_Status = PlcData.Read_Status;
|
||||
var statusresult = apiClient.CallFunctionByName("Status", PlcData, otherdata);
|
||||
if (statusresult.Success)
|
||||
{
|
||||
Init.Plcstatus = PlcData.Read_Status;
|
||||
Init.Plcstatus_LastTime = DateTime.Now;
|
||||
MES链接状态.Text = "MES链接状态:OK";
|
||||
MES链接状态.BackColor = SystemColors.Control;
|
||||
MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
|
||||
MES_MsgfORM("Status", statusresult.Mesresult, statusresult.Requesttime);
|
||||
if (statusresult.Mesresult != mesresult.PASS)
|
||||
{
|
||||
PlcData.Write_Status = 1001;
|
||||
siemensHelp.WriteAddress(plcaddress, PlcData);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -168,15 +174,21 @@ namespace WindowsFormsApp1
|
||||
///////////////////////////////测试用
|
||||
list.Add("M03CVSO-01");
|
||||
otherdata.Plc_ErrorMsgs = list;
|
||||
Init.Plcstatus = PlcData.Read_Status;
|
||||
Init.Plcstatus_LastTime = DateTime.Now;
|
||||
var statusresult = apiClient.CallFunctionByName("Alarm", PlcData, otherdata);
|
||||
if (statusresult.Success)
|
||||
{
|
||||
Init.Plcstatus = PlcData.Read_Status;
|
||||
Init.Plcstatus_LastTime = DateTime.Now;
|
||||
MES链接状态.Text = "MES链接状态:OK";
|
||||
MES链接状态.BackColor = SystemColors.Control;
|
||||
MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
|
||||
MES_MsgfORM("Alarm", statusresult.Mesresult, statusresult.Requesttime);
|
||||
if (statusresult.Mesresult != mesresult.PASS)
|
||||
{
|
||||
PlcData.Write_Status = 1001;
|
||||
siemensHelp.WriteAddress(plcaddress, PlcData);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -230,7 +242,7 @@ namespace WindowsFormsApp1
|
||||
if(nowinterface.code == "SN_CheckIN")
|
||||
{
|
||||
请扫描LOT号.Enabled = true;
|
||||
ScanPort.Read();
|
||||
//ScanPort.Read();
|
||||
|
||||
|
||||
}
|
||||
@ -243,7 +255,7 @@ namespace WindowsFormsApp1
|
||||
var result = apiClient.CallFunctionByName(nowinterface.code,PlcData, otherdata);
|
||||
if (result.Success)
|
||||
{
|
||||
var writeresult = siemensHelp.WriteAddress(Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id),PlcData);
|
||||
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
|
||||
if (!writeresult.Success)
|
||||
{
|
||||
PLC链接状态.Text = "PLC链接状态:NG";
|
||||
@ -256,6 +268,12 @@ namespace WindowsFormsApp1
|
||||
MES链接状态.Text = "MES链接状态:OK";
|
||||
MES链接状态.BackColor = SystemColors.Control;
|
||||
MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
|
||||
if (result.Mesresult != mesresult.PASS)
|
||||
{
|
||||
PlcData.Write_Status = 1001;
|
||||
siemensHelp.WriteAddress(plcaddress, PlcData);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@ -175,7 +175,6 @@
|
||||
this.portName.HeaderText = "COM口";
|
||||
this.portName.MinimumWidth = 9;
|
||||
this.portName.Name = "portName";
|
||||
this.portName.ReadOnly = true;
|
||||
//
|
||||
// baudRate
|
||||
//
|
||||
@ -217,6 +216,7 @@
|
||||
this.reamrk.HeaderText = "备注";
|
||||
this.reamrk.MinimumWidth = 9;
|
||||
this.reamrk.Name = "reamrk";
|
||||
this.reamrk.ReadOnly = true;
|
||||
//
|
||||
// SerialPort_Manage
|
||||
//
|
||||
|
||||
@ -14,7 +14,7 @@ namespace WindowsFormsApp1.mod.server
|
||||
public int Plc_Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PLC反馈的机台报警
|
||||
/// PLC反馈的机台报警(默认获取0位)
|
||||
/// </summary>
|
||||
public List<string> Plc_ErrorMsgs { get; set; }
|
||||
|
||||
@ -24,15 +24,20 @@ namespace WindowsFormsApp1.mod.server
|
||||
public string FileUploadAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 胶水码
|
||||
/// 前端返回的扫码
|
||||
/// </summary>
|
||||
public string JS_SN { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 螺丝枪扭力角度
|
||||
/// 螺丝枪扭力
|
||||
/// </summary>
|
||||
public List<float> FinalTorqueValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 螺丝枪角度
|
||||
/// </summary>
|
||||
public List<float> FinalAngleValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 螺丝枪扭力曲线
|
||||
/// </summary>
|
||||
|
||||
@ -218,7 +218,62 @@ namespace WindowsFormsApp1.server
|
||||
|
||||
public ApiFormResult SN_Release(string url, plcdata PlcData, otherdata OtherData)
|
||||
{
|
||||
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
|
||||
// 组装 request json
|
||||
var request = new
|
||||
{
|
||||
EventID = "Carrier_Check",
|
||||
Line = "Testline",
|
||||
StationID = "TestStation",
|
||||
MachineID = "TestMachine",
|
||||
OPID = "OPID",
|
||||
Token = "",
|
||||
FixSN = "",
|
||||
SN = OtherData.JS_SN,
|
||||
CarrierID = "",
|
||||
SendTime = DateTime.Now
|
||||
};
|
||||
// 使用 Newtonsoft.Json 进行序列化
|
||||
string jsonPayload = JsonConvert.SerializeObject(request);
|
||||
|
||||
// 创建 StringContent 对象,将 JSON 字符串作为请求体,指定编码和媒体类型
|
||||
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;
|
||||
|
||||
// 使用 Newtonsoft.Json 将响应内容反序列化为动态对象
|
||||
dynamic res = JsonConvert.DeserializeObject(responseContent);
|
||||
|
||||
// 访问动态对象的属性
|
||||
if (res != null)
|
||||
{
|
||||
// 成功!
|
||||
if (!string.IsNullOrEmpty(res.RESULT))
|
||||
{
|
||||
// 回写对应PLC
|
||||
PlcData.Write_stSN = res.MSG;
|
||||
return res.RESULT == "pass" ? ApiFormResult.Sucess(mesresult.PASS, false, res.MSG, PlcData, DateTime.Now)
|
||||
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG, 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 Glue_CheckOut(string url, plcdata PlcData, otherdata OtherData)
|
||||
@ -362,7 +417,7 @@ namespace WindowsFormsApp1.server
|
||||
StationID = "TestStation",
|
||||
MachineID = "TestMachine",
|
||||
OPID = "OPID",
|
||||
AlarmID = OtherData.Plc_ErrorMsgs,
|
||||
AlarmID = OtherData.Plc_ErrorMsgs[0],
|
||||
SendTime = DateTime.Now,
|
||||
ResetTime = ""
|
||||
};
|
||||
@ -425,8 +480,112 @@ namespace WindowsFormsApp1.server
|
||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData,DateTime.Now);
|
||||
}
|
||||
|
||||
public ApiFormResult CodeSoftPrint(string url, plcdata PlcData, otherdata OtherData)
|
||||
{
|
||||
// 组装 request json
|
||||
var request = new
|
||||
{
|
||||
Line = "Testline",
|
||||
StationID = "TestStation",
|
||||
MachineID = "TestMachine",
|
||||
SN = PlcData.Read_MaterialCode0
|
||||
};
|
||||
// 使用 Newtonsoft.Json 进行序列化
|
||||
string jsonPayload = JsonConvert.SerializeObject(request);
|
||||
|
||||
// 创建 StringContent 对象,将 JSON 字符串作为请求体,指定编码和媒体类型
|
||||
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;
|
||||
|
||||
// 使用 Newtonsoft.Json 将响应内容反序列化为动态对象
|
||||
dynamic res = JsonConvert.DeserializeObject(responseContent);
|
||||
|
||||
// 访问动态对象的属性
|
||||
if (res != null)
|
||||
{
|
||||
// 成功!
|
||||
if (!string.IsNullOrEmpty(res.ErrorMessage))
|
||||
{
|
||||
// 回写对应PLC
|
||||
// res.ErrorMessage.Contains("OK")
|
||||
return res.IsSuccess == true ? ApiFormResult.Sucess(mesresult.PASS, true, res.ErrorMessage, PlcData, DateTime.Now)
|
||||
: ApiFormResult.Sucess(mesresult.FAIL, false, res.MSG, 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 SN_Checkout(string url, plcdata PlcData, otherdata OtherData)
|
||||
{
|
||||
var lineCode = Init.t_Line.linecode;
|
||||
switch(lineCode)
|
||||
{
|
||||
case "OP1060": // 追溯码+载具,默认(todo)
|
||||
case "OP1120":
|
||||
case "OP1170":
|
||||
case "OP1190":
|
||||
case "OP1220":
|
||||
case "OP1250":
|
||||
break;
|
||||
|
||||
case "OP1010":// 传气密
|
||||
case "OP1330":
|
||||
break;
|
||||
|
||||
case "OP1050":// 胶水码
|
||||
case "OP1210":// 三防漆码
|
||||
break;
|
||||
|
||||
case "OP1070":// 传螺丝 角度,扭力,【扭力曲线(datacollection)】
|
||||
case "OP1080":
|
||||
case "OP1090":
|
||||
case "OP1100":
|
||||
case "OP1130":
|
||||
case "OP1260":
|
||||
break;
|
||||
|
||||
case "OP1140"://压力值,压力曲线
|
||||
break;
|
||||
|
||||
case "OP1160"://加热,冷却温度
|
||||
break;
|
||||
|
||||
case "OP1110"://CCD检测结果
|
||||
case "OP1200"://AOI检测结果
|
||||
case "OP1240"://CCD检测结果
|
||||
case "OP1340"://CCD检测结果
|
||||
break;
|
||||
|
||||
case "OP1360"://产品码
|
||||
break;
|
||||
|
||||
// case "OP1180"://助焊剂批次码
|
||||
// break;
|
||||
case "OP1230"://AOI检测结果,三防漆涂胶胶宽
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData,DateTime.Now);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user