change - 添加mes接口

master
wenjy 9 months ago
parent 006ee68fcb
commit c537b9d41d

@ -426,7 +426,7 @@ namespace ZJ_BYD
/// <param name="stationCode"></param> /// <param name="stationCode"></param>
/// <param name="barCode"></param> /// <param name="barCode"></param>
/// <returns></returns> /// <returns></returns>
public static (bool ok, string msg) SaveDb(string stationCode, string barCode) public static (bool ok, string msg, T_Result _Result) SaveDb(string stationCode, string barCode)
{ {
if (Program.type == null) if (Program.type == null)
{ {
@ -479,7 +479,7 @@ namespace ZJ_BYD
keyValItem.Val = EnumHelper.GetEnumDescription(enumVal); keyValItem.Val = EnumHelper.GetEnumDescription(enumVal);
if (keyValItem.Val != "OK" && keyValItem.Val != "NG") if (keyValItem.Val != "OK" && keyValItem.Val != "NG")
{ {
return (false, $"一体机数据上传反馈:{keyValItem.KeyDesc}异常={keyValItem.Val}存库NG!"); return (false, $"一体机数据上传反馈:{keyValItem.KeyDesc}异常={keyValItem.Val}存库NG!", null);
} }
} }
prop.SetValue(result, Convert.ChangeType(keyValItem.Val, prop.PropertyType)); prop.SetValue(result, Convert.ChangeType(keyValItem.Val, prop.PropertyType));
@ -488,18 +488,18 @@ namespace ZJ_BYD
#endregion #endregion
var t_Result = result as T_Result; var t_Result = result as T_Result;
t_Result.LineCode = Program.CurrentLineCode; t_Result.LineCode = Program.CurrentLineCode.Replace("\x00", "");
t_Result.StationCode = stationCode; t_Result.StationCode = stationCode;
//主条码 //主条码
var M28 = list.FirstOrDefault(m => m.Key == "M28"); var M28 = list.FirstOrDefault(m => m.Key == "M28");
//重新读取PLc中的主条码 2023-9-20新增逻辑 //重新读取PLc中的主条码 2023-9-20新增逻辑
var readM28 = PlcHelper.GetPlcVal(M28.DataType, M28.Address); var readM28 = PlcHelper.GetPlcVal(M28.DataType, M28.Address,M28.Length);
if (readM28.ok) if (readM28.ok)
{ {
M28.Val = readM28.val.Replace("\r", ""); M28.Val = readM28.val.Replace("\r", "");
LogHelper.WriteLog($"存本地数据库时,获取到的壳体码={M28.Val}"); LogHelper.WriteLog($"存本地数据库时,获取到的壳体码={M28.Val}");
} }
t_Result.ProductSfcCode = M28.Val.Replace("\r", ""); t_Result.ProductSfcCode = M28.Val.Replace("\r", "").Replace("\x00", "");
//产品总状态 //产品总状态
var M5 = list.FirstOrDefault(m => m.Key == "M5"); var M5 = list.FirstOrDefault(m => m.Key == "M5");
if (M5 != null && (M5.Val == "undefined" || M5.Val == "UNDEFINED" || M5.Val == "0.000")) if (M5 != null && (M5.Val == "undefined" || M5.Val == "UNDEFINED" || M5.Val == "0.000"))
@ -518,7 +518,7 @@ namespace ZJ_BYD
M5.Val = EnumHelper.GetEnumDescription(enumVal); M5.Val = EnumHelper.GetEnumDescription(enumVal);
if (M5.Val != "OK" && M5.Val != "NG") if (M5.Val != "OK" && M5.Val != "NG")
{ {
return (false, $"一体机数据上传反馈:产品状态异常={M5.Val}存库NG!"); return (false, $"一体机数据上传反馈:产品状态异常={M5.Val}存库NG!", t_Result);
} }
} }
else else
@ -535,7 +535,7 @@ namespace ZJ_BYD
t_Result.Category = station.Category; t_Result.Category = station.Category;
} }
t_Result.TestFileName = Program.testfilename; t_Result.TestFileName = Program.testfilename;
t_Result.BarCode = barCode; t_Result.BarCode = barCode.Replace("\x00", "");
t_Result.ProgramVersion = Program.programversion; t_Result.ProgramVersion = Program.programversion;
t_Result.LoginUser = CurrentUser.UserName; t_Result.LoginUser = CurrentUser.UserName;
t_Result.SysMode = Program.SysMode; t_Result.SysMode = Program.SysMode;
@ -549,7 +549,7 @@ namespace ZJ_BYD
{ {
if (!string.IsNullOrWhiteSpace(subs[i].Val)) if (!string.IsNullOrWhiteSpace(subs[i].Val))
{ {
strSubCode += $"{subs[i].Val},"; strSubCode += $"{subs[i].Val.Replace("\x00", "")},";
} }
} }
t_Result.BulkParts = strSubCode.TrimEnd(','); t_Result.BulkParts = strSubCode.TrimEnd(',');
@ -564,22 +564,22 @@ namespace ZJ_BYD
if (addResult <= 0) if (addResult <= 0)
{ {
LogHelper.WriteLog($"{stationCode}工位,新增结果失败:{JsonConvert.SerializeObject(t_Result)}"); LogHelper.WriteLog($"{stationCode}工位,新增结果失败:{JsonConvert.SerializeObject(t_Result)}");
return (false, "一体机数据上传反馈存库NG!"); return (false, "一体机数据上传反馈存库NG!", t_Result);
} }
else else
{ {
return (true, $"一体机数据上传反馈存库OK!,产品总状态:{t_Result.TotalStatus}"); return (true, $"一体机数据上传反馈存库OK!,产品总状态:{t_Result.TotalStatus}", t_Result);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
LogHelper.WriteLog($"一体机数据上传反馈:{stationCode}工位存库发生异常:{ex.Message}!"); LogHelper.WriteLog($"一体机数据上传反馈:{stationCode}工位存库发生异常:{ex.Message}!");
return (false, "一体机数据上传反馈存库NG!"); return (false, "一体机数据上传反馈存库NG!",null);
} }
} }
else else
{ {
return (false, "一体机数据上传反馈存库NG!"); return (false, "一体机数据上传反馈存库NG!", null);
} }
} }

@ -15,5 +15,10 @@
/// 姓名 /// 姓名
/// </summary> /// </summary>
public static string RealName { get; set; } public static string RealName { get; set; }
/// <summary>
/// 机型
/// </summary>
public static string MachineType { get;set; }
} }
} }

@ -54,7 +54,7 @@ namespace ZJ_BYD.Common
ResponseParam result = null; ResponseParam result = null;
try try
{ {
var jsonStr = JsonConvert.SerializeObject(submitWorkStationDataUrl); var jsonStr = JsonConvert.SerializeObject(workData);
var respStr = Post(submitWorkStationDataUrl, jsonStr); var respStr = Post(submitWorkStationDataUrl, jsonStr);

@ -14,7 +14,7 @@ namespace ZJ_BYD.Common
/// <param name="address"></param> /// <param name="address"></param>
/// <param name="length"></param> /// <param name="length"></param>
/// <returns></returns> /// <returns></returns>
public static (bool ok, string val) GetPlcVal(string dataType, string address, string length = "1") public static (bool ok, string val) GetPlcVal(string dataType, string address, string length = "40")
{ {
var strVal = string.Empty; var strVal = string.Empty;
try try
@ -118,6 +118,10 @@ namespace ZJ_BYD.Common
else else
{ {
strVal = operateFloatResult.Content; strVal = operateFloatResult.Content;
if (!string.IsNullOrEmpty(strVal))
{
strVal = strVal.Substring(2, strVal.Length - 2).Trim();
}
return (true, strVal); return (true, strVal);
} }
} }

@ -12,6 +12,7 @@ using ZJ_BYD.Common;
using ZJ_BYD.DB; using ZJ_BYD.DB;
using ZJ_BYD.Enums; using ZJ_BYD.Enums;
using ZJ_BYD.Model; using ZJ_BYD.Model;
using ZJ_BYD.Model.HttpApiParam;
using ZJ_BYD.Untils; using ZJ_BYD.Untils;
using ZJ_BYD.ViewModel; using ZJ_BYD.ViewModel;
@ -124,7 +125,7 @@ namespace ZJ_BYD
{ {
foreach (var plcPoint in _plcPoints) foreach (var plcPoint in _plcPoints)
{ {
var plcResult = PlcHelper.GetPlcVal(plcPoint.DataType, plcPoint.Address); var plcResult = PlcHelper.GetPlcVal(plcPoint.DataType, plcPoint.Address,plcPoint.Length);
if (plcResult.ok) if (plcResult.ok)
{ {
string strVal = plcResult.val; string strVal = plcResult.val;
@ -611,7 +612,7 @@ namespace ZJ_BYD
#region 本地存储 #region 本地存储
//存本地库 //存本地库
var (ok, msg) = CheckCode.SaveDb(_stationInfo.StationCode, BarCode); var (ok, msg,_result) = CheckCode.SaveDb(_stationInfo.StationCode, BarCode);
_logs.Add(new LogVm _logs.Add(new LogVm
{ {
StationCode = _stationInfo.StationCode, StationCode = _stationInfo.StationCode,
@ -628,6 +629,8 @@ namespace ZJ_BYD
#region 上传MES #region 上传MES
if (Program.SysMode)
{
var M14 = _plcPoints.FirstOrDefault(m => m.Key == "M14"); var M14 = _plcPoints.FirstOrDefault(m => m.Key == "M14");
var mskCode = Program.t_MaskCodes.First(m => m.StationCode == _stationInfo.StationCode && m.SortIndex == int.Parse(M14.Val)); var mskCode = Program.t_MaskCodes.First(m => m.StationCode == _stationInfo.StationCode && m.SortIndex == int.Parse(M14.Val));
if (mskCode != null) if (mskCode != null)
@ -635,6 +638,41 @@ namespace ZJ_BYD
var M5 = _plcPoints.FirstOrDefault(m => m.Key == "M5"); var M5 = _plcPoints.FirstOrDefault(m => m.Key == "M5");
var testList = Program.PointKeyValues var testList = Program.PointKeyValues
.Where(m => m.StationCode == _stationInfo.StationCode && m.IsTestItem).ToList(); .Where(m => m.StationCode == _stationInfo.StationCode && m.IsTestItem).ToList();
WorkData workData = new WorkData();
List<DParams> dParams = new List<DParams>();
if (testList != null)
{
foreach (var item in testList)
{
DParams param = new DParams();
param.n = item.KeyDesc;
param.ng = item.Result;
param.v = item.Val;
dParams.Add(param);
}
}
workData.dparams = dParams;
workData._operator = _result.LoginUser;
workData.snList = _result.BulkParts;
workData.qc = _result.TotalStatus == "OK" ? 0 : 1;
workData.productCode = _result.Category;
workData.workStationCode = _result.StationCode;
workData.rfId = _result.ProductSfcCode;
ResponseParam result = HttpUtilApi.submitWorkStationData(workData);
if (result.code != 200)
{
ok = false;
}
_logs.Add(new LogVm
{
StationCode = _stationInfo.StationCode,
HisLog = $"{DateTime.Now:HH:mm:ss}>>>>>{result.msg}{Environment.NewLine}"
});
}
} }
else else
{ {

@ -260,20 +260,20 @@ namespace ZJ_BYD
{ {
if (Program.siemensS7Net != null) if (Program.siemensS7Net != null)
{ {
foreach (var item in plcPoints) //foreach (var item in plcPoints)
{ //{
var result = Program.siemensS7Net.Write(item.Address, ushort.Parse("2")); // var result = Program.siemensS7Net.Write(item.Address, ushort.Parse("2"));
if (!result.IsSuccess) // if (!result.IsSuccess)
{ // {
result = Program.siemensS7Net.Write(item.Address, ushort.Parse("2")); // result = Program.siemensS7Net.Write(item.Address, ushort.Parse("2"));
if (!result.IsSuccess) // if (!result.IsSuccess)
{ // {
XtraMessageBox.Show($"离线模式登录时,[{item.StationCode}]工位用户验证结果写入失败,请重新登录!", "系统提示"); // XtraMessageBox.Show($"离线模式登录时,[{item.StationCode}]工位用户验证结果写入失败,请重新登录!", "系统提示");
Environment.Exit(0); // Environment.Exit(0);
} // }
} // }
Thread.Sleep(100); // Thread.Sleep(100);
} //}
} }
else else
{ {

@ -44,14 +44,14 @@ namespace ZJ_BYD
//gridFinished.DataSource = _bindingResultFinishedCodeVMs; //gridFinished.DataSource = _bindingResultFinishedCodeVMs;
_bindingResultFinishedCodeVMs.ListChanged += OnParamBindingListChanged; _bindingResultFinishedCodeVMs.ListChanged += OnParamBindingListChanged;
Task.Run(() => //Task.Run(() =>
{ //{
while (!cancellationTokenSource.IsCancellationRequested) // while (!cancellationTokenSource.IsCancellationRequested)
{ // {
MyMethod(); // MyMethod();
Thread.Sleep(3000); // Thread.Sleep(3000);
} // }
}, cancellationTokenSource.Token); //}, cancellationTokenSource.Token);
} }
System.Timers.Timer timer; System.Timers.Timer timer;
@ -738,14 +738,24 @@ namespace ZJ_BYD
{ {
BeginInvoke(new Action(() => BeginInvoke(new Action(() =>
{ {
machineTypeControl.Text = "当前机型:"+M14.Val; var station = Program.stationInfos.FirstOrDefault(m => m.StationCode == Program.ActiveStatinCode && m.MachineTypeIndex.ToString() == M14?.Val);
if(station != null)
{
machineTypeControl.Text = "当前机型:" + station.Category;
CurrentUser.MachineType = station.Category;
}
else
{
machineTypeControl.Text = "未获取到机型";
}
})); }));
} }
else else
{ {
BeginInvoke(new Action(() => BeginInvoke(new Action(() =>
{ {
machineTypeControl.Text = "未获取到机型索引"; machineTypeControl.Text = "未获取到机型";
})); }));
} }

Loading…
Cancel
Save