1.添加马头螺丝扭力角度的上传,后期使用定时器定时上传数据
2.抽真空 plc 触发90
3.螺丝开盖按钮添加 从 keyvalue获取值,对比扫码得到的值更新other4
This commit is contained in:
zhougf committed 2025-04-12 14:55:51 +08:00
1 parent 69c851c09e
commit 1a9f2a5bca
8 files changed
+301 -105

No files matched your search

+183 -104
View File
@@ -20,6 +20,7 @@ using System.IO;
using static WindowsFormsApp1.server.ApiClient;
using System.Security.Policy;
using System.Diagnostics;
using System.Windows.Forms;
namespace WindowsFormsApp1.server
{
@@ -94,7 +95,6 @@ namespace WindowsFormsApp1.server
headers.Add("泄漏量");
break;
case "potting":
case "thermapaste":
headers.Add("胶重");
break;
case "vacuum":
@@ -109,6 +109,9 @@ namespace WindowsFormsApp1.server
headers.Add("固化温度");
headers.Add("固化时间");
break;
case "leakage":
headers.Add("泄漏量");
break;
}
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(station))
{
@@ -116,7 +119,7 @@ namespace WindowsFormsApp1.server
headers.Add("扭矩");
}
if ("Assy2,Assy3,AOI,Assy5,Sealant,CCD,PrintLabel".ToLower().Contains(station))
if ("Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5".ToLower().Contains(station))
{
headers.Add("CCD");
}
@@ -154,7 +157,7 @@ namespace WindowsFormsApp1.server
var response = _httpClient.PostAsync(url, httpContent).Result;
// 检查响应状态码
if (response.IsSuccessStatusCode)
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
// 读取响应内容
string responseContent = response.Content.ReadAsStringAsync().Result;
@@ -484,9 +487,9 @@ namespace WindowsFormsApp1.server
StationID = _stationID,
MachineID = _machineID,
OPID = _opID,
SN = OtherData.JS_SN ?? PlcData.Write_stSN ?? "test",
CarrierID = PlcData.Read_MaterialCode1,
DC_INFO = new List<DCInfoItem>(),
SN = PlcData.Write_stSN ?? OtherData.material?.sn,
CarrierID = PlcData.Read_MaterialCode1 ?? OtherData.material?.CarrierID,
DC_INFO = new List<DataDCInfoItem>(),
CompList = new List<CompListItem>(),
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
};
@@ -496,21 +499,91 @@ namespace WindowsFormsApp1.server
Qty = "1"
});
var station = Init.t_Line.lineremark2.ToLower();
var statusCode = 0;
if (station == "vacuum")
{
// 抽真空
var num = 1;
foreach (var val in OtherData.FinalPressureCurve.Where(x => x > 0))
{
request.DC_INFO.Add(new DCInfoItem
request.DC_INFO.Add(new DataDCInfoItem
{
Item = "Chamber_Pressure",
Item = $"Chamber_Pressure_{num}",
Value = val.ToString()
});
num++;
}
statusCode = PLC_Status.Data_Collection;
}
else if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(station))
{
// 扭力 读马头服务器
var geturl = $"http://10.50.12.41/getdata/v2/tighteningresults?startTime={OtherData.material.date}&endTime={DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")}&vin={OtherData.material.sn}&controllerName={Init.t_Line.lineremark3}@{Init.t_Line.linecode}&includeCurve=true&includeSteps=false";
//var geturl = "http://10.50.12.41/getdata/v2/tighteningresults?startTime=2025-04-11&endTime=2025-04-12&vin=ok&controllerName=OP1260%4010.50.247.110&includeCurve=true&includeSteps=false";
var res = _httpClient.GetAsync(geturl).Result;
if (res.StatusCode == System.Net.HttpStatusCode.OK)
{
//var getresult = JsonConvert.DeserializeObject(res.Content.ReadAsStringAsync().Result);
// 扭力 读马头服务器 todo
try
{
// 反序列化 JSON 数据
var rootObjects = JsonConvert.DeserializeObject<List<MTObject>>(res.Content.ReadAsStringAsync().Result);
var modelnum = 1;
// 遍历每个 RootObject
foreach (var rootObject in rootObjects)
{
if (rootObject.model != null && rootObject.model.results != null)
{
// 遍历每个 Result
foreach (var result in rootObject.model.results)
{
if (result.curves != null)
{
// 遍历每个 Curve
foreach (var curve in result.curves)
{
if (curve.data != null && curve.data.points != null)
{
// 遍历每个 Point
foreach (var point in curve.data.points)
{
request.DC_INFO.Add(new DataDCInfoItem
{
Item = $"Torque{modelnum}_{point.pointIndex}",
Value = point.torque.ToString("F4")
});
request.DC_INFO.Add(new DataDCInfoItem
{
Item = $"Angle{modelnum}_{point.pointIndex}",
Value = point.angle.ToString("F4")
});
}
}
}
}
}
}
modelnum++;
}
}
catch (Exception ex)
{
Console.WriteLine($"发生错误: {ex.Message}");
}
}
}
// 扭力 读马头服务器 todo
return CallApi(url, request, "Data_Collection", PlcData, PLC_Status.Data_Collection);
return CallApi(url, request, "Data_Collection", PlcData, statusCode);
//if(result.Success && result.Mesresult == mesresult.PASS)
//{
// OtherData.material.datacollectionUploaded = 2;
// var dbhelper = new SQLiteHelper<t_materialupload>();
// dbhelper.Update(OtherData.material);
//}
}
public ApiFormResult Status(string url, plcdata PlcData, otherdata OtherData)
@@ -557,7 +630,7 @@ namespace WindowsFormsApp1.server
/// <returns></returns>
public ApiFormResult SN_FileUpload(string url, plcdata PlcData, otherdata OtherData)
{
// 准备文件 视频/图片
// 准备文件 视频/图片 目的路径拼接
var month = DateTime.Now.ToString("yyyyMM");
var day = DateTime.Now.ToString("dd");
var monthDay = DateTime.Now.ToString("MMdd");
@@ -578,7 +651,7 @@ namespace WindowsFormsApp1.server
List<string> fileList = new List<string>();
//从数据库读 未上传的,从定时器中传出来
string snNumber = OtherData.SN;
string snNumber = OtherData.material.sn;
if (string.IsNullOrEmpty(snNumber))
{
@@ -591,22 +664,24 @@ namespace WindowsFormsApp1.server
Directory.CreateDirectory(targetFolder);
}
foreach (string sourceFolder1 in sourceFolders)
foreach (string folder in sourceFolders)
{
if (string.IsNullOrEmpty(sourceFolder1))
if (string.IsNullOrEmpty(folder))
{
continue;
}
//判断此sn需要传哪些数据 图片 或视频 todo
string sourceFolder = sourceFolders[0];
if (sourceFolder == sourceFolder1)
if (sourceFolder == folder)
{
// 图片
// 组装路径 可能需要从数据库读 result和sn和日期
sourceFolder = Path.Combine(sourceFolder, DateTime.Now.ToString("yyyyMMdd"), "DCDC", result);
sourceFolder = Path.Combine(sourceFolder, OtherData.material.date, "DCDC", result);
}
else
{
// 视频
sourceFolder = Path.Combine(sourceFolder, DateTime.Now.ToString("yyyy-MM-dd"));
}
if (Directory.Exists(sourceFolder.Trim()))
{
@@ -624,8 +699,6 @@ namespace WindowsFormsApp1.server
extensionstr = Path.GetExtension(file);
fileName = $"{month}{day}_{_stationID}_{result}_{snNumber}_{monthDay}_{time}_{_machineID}_01_Detection_{num}{extensionstr}";
filePath = Path.Combine(sourceFolder, fileName1);
//string targetPath = Path.Combine(targetFolder, fileName);
//File.Copy(file, targetPath, true);
CopyFileToDirectory(filePath, targetFolder, fileName);
fileList.Add(fileName);
num++;
@@ -640,6 +713,7 @@ namespace WindowsFormsApp1.server
if (fileList.Count == 0)
{
//标记sn的回传状态,以免下次定时器还能查到这种
LogExecute.logNet.WriteDebug($"在所有源文件夹中未找到包含SN号 {snNumber} 的文件");
return ApiFormResult.Error(mesresult.FAIL, false, "", PlcData, DateTime.Now);
}
@@ -673,76 +747,6 @@ namespace WindowsFormsApp1.server
LogExecute.logNet.WriteError($"文件上传处理失败: {ex.Message}");
return ApiFormResult.Error(mesresult.FAIL, false, ex.Message, PlcData, DateTime.Now);
}
/*
// 查找源文件 可能会有多张照片或视频
var filelist = Directory.GetFiles(sourceDirectory);
var copyedFileList = new List<string>();
string sourceFile = "";
var num = 1;
foreach (var file in filelist)
{
// 分别处理每张图片
var sourceName = Path.GetFileNameWithoutExtension(file);
if (sourceName.Contains(PlcData.Read_MaterialCode0))
{
sourceFile = Path.Combine(sourceDirectory, sourceName);
var extensionstr = Path.GetExtension(file);
fileName = $"{month}{day}_{_stationID}_{result}_{PlcData.Read_MaterialCode0}_{monthDay}_{time}_{_machineID}_01_Original{num}.{extensionstr}";
//执行复制
var copyResult = CopyFileToDirectory(sourceFile, targetDirectory, fileName);
if (copyResult)
{
copyedFileList.Add(fileName);
num++;
}
}
}
// 执行复制
try
{
CopyFileToDirectory(sourceFile, targetDirectory, fileName);
}
catch (Exception ex)
{
return ApiFormResult.Error(mesresult.FAIL, false, ex.Message, PlcData, DateTime.Now);
}
// 组装 request json
var request = new
{
Line = _line,
StationID = _stationID,
MachineID = _machineID,
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.ToString("yyyy/MM/dd HH:mm:ss")
};
// 多个视频或图片
// 动态添加 FileInfo
return CallApi(url, request, "SN_FileUpload", PlcData, PLC_Status.SN_FileUpload);
*/
}
/// <summary>
@@ -769,7 +773,6 @@ namespace WindowsFormsApp1.server
public ApiFormResult SN_Checkout(string url, plcdata PlcData, otherdata OtherData)
{
// 根据不同的lineCode构建不同的请求
var lineCode = Init.t_Line.linecode;
var stationid = Init.t_Line.lineremark2;
var result = PlcData.Read_Result == 1 ? "PASS" : "FAIL";
@@ -806,7 +809,7 @@ namespace WindowsFormsApp1.server
request.FixSN = OtherData.plcid.ToString();
}
// 根据不同的lineCode可以在这里扩展request对象
// 根据不同的station可以在这里扩展request对象
var dcInfo = new DCInfoItem();
var sninfo = request.SNInfo[0];
var compListItem = new CompListItem();
@@ -828,20 +831,23 @@ namespace WindowsFormsApp1.server
});
CsvLogger.Log($"{PlcData.Write_stSN},{Init.airtight.Airtight_Value},{Init.airtight.Leak_Value}");
}
if ("Leakage".Contains(stationid))
{
sninfo.DC_INFO.Add(new DCInfoItem
{
Item = OutItem.泄漏量,
Value = Init.airtight.Leak_Value ?? "0",
Result = result
});
CsvLogger.Log($"{PlcData.Write_stSN},{Init.airtight.Leak_Value}");
}
//扭力,角度
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".Contains(stationid))
{
var count = OtherData.FinalAngleValue.Count(x => x > 0);
for (int i = 0; i < count; i++)
{
if ("Assy2,Assy3".Contains(stationid))
{
CsvLogger.Log($"{PlcData.Write_stSN},{OtherData.FinalAngleValue[i]},{OtherData.FinalTorqueValue[i]},{logresult}");
}
else
{
CsvLogger.Log($"{PlcData.Write_stSN},{OtherData.FinalAngleValue[i]},{OtherData.FinalTorqueValue[i]}");
}
CsvLogger.Log($"{PlcData.Write_stSN},{OtherData.FinalAngleValue[i]},{OtherData.FinalTorqueValue[i]}");
}
var AngleCount = 1;
@@ -868,22 +874,43 @@ namespace WindowsFormsApp1.server
sninfo.DC_INFO.Add(dcInfo);
TorqueCount++;
}
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
if (material == null)
{
material = new t_materialupload
{
sn = PlcData.Write_stSN,
CarrierID = PlcData.Write_stSN,
datacollectionUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyy-MM-dd")
};
materialuploadHelper.Insert(material);
}
else
{
material.datacollectionUploaded = 1;
materialuploadHelper.Update(material);
}
}
//CCD
if ("Assy2,Assy3,AOI,Assy5,Sealant,CCD,PrintLabel".Contains(stationid))
if ("Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5".Contains(stationid))
{
dcInfo = new DCInfoItem();
dcInfo.Item = stationid == "CCD" ? "CCD" : $"{Init.t_Line.lineremark2}_CCD";
dcInfo.Value = logresult;
dcInfo.Result = result;
sninfo.DC_INFO.Add(dcInfo);
if (!"Assy2,Assy3,Sealant".Contains(stationid))
if (!"Sealant".Contains(stationid))
{
CsvLogger.Log($"{PlcData.Write_stSN},{logresult}");
}
//LogExecute.SNlogNet.WriteDebug($"追溯码:{PlcData.Read_MaterialCode0},检测结果:{logresult}");
}
//抽真空 压力
if ("Vacuum".Contains(stationid))
{
@@ -906,6 +933,7 @@ namespace WindowsFormsApp1.server
str += $",{dcInfo.Value},";
CsvLogger.Log(str);
}
//固化 时间
if ("Curing".Contains(stationid))
{
@@ -914,7 +942,7 @@ namespace WindowsFormsApp1.server
if (material.Success)
{
// 计算加热时间
var time = ((TimeSpan)(material.Data.checkin2 - material.Data.checkout1)).TotalMinutes;
var time = ((TimeSpan)((material.Data.checkin2 ?? new DateTime()) - (material.Data.checkout1 ?? new DateTime()))).TotalMinutes;
var jrTime = Convert.ToInt32(time).ToString();
sninfo.DC_INFO.Add(new DCInfoItem
{
@@ -939,7 +967,7 @@ namespace WindowsFormsApp1.server
}
//胶重
if ("Potting,ThermalPaste".Contains(stationid))
if ("Potting".Contains(stationid))
{
dcInfo = new DCInfoItem();
dcInfo.Item = $"{stationid}_Weight";
@@ -1026,7 +1054,7 @@ namespace WindowsFormsApp1.server
sn = PlcData.Write_stSN,
vedioUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyyMMdd")
date = DateTime.Now.ToString("yyyy-MM-dd")
};
materialuploadHelper.Insert(material);
}
@@ -1247,6 +1275,12 @@ namespace WindowsFormsApp1.server
public List<CompListItem> CompList { get; set; }
}
public class DataDCInfoItem
{
public string Item { get; set; }
public string Value { get; set; }
}
// DC_INFO 列表中的每个元素类
public class DCInfoItem
{
@@ -1265,6 +1299,51 @@ namespace WindowsFormsApp1.server
}
#endregion checkout class
#region 马头扭力角度数据 类
// 最外层数组元素的类
public class MTObject
{
public Model model { get; set; }
}
// model 类
public class Model
{
public List<Result> results { get; set; }
}
// result 类
public class Result
{
public List<Curve> curves { get; set; }
}
// curve 类
public class Curve
{
public CurveData data { get; set; }
}
// curveData 类
public class CurveData
{
public List<Point> points { get; set; }
}
// point 类
public class Point
{
public int pointIndex { get; set; }
//[Math.Round(double,4)]
public double torque { get; set; }
public double angle { get; set; }
}
#endregion 马头扭力角度数据 类
// 文件copy方法
public bool CopyFileToDirectory(string sourceFilePath, string targetDirectory, string fileName)
{