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

View File

@ -265,6 +265,7 @@
<Compile Include="mod\database\t_plcaddress.cs" />
<Compile Include="mod\database\t_plc.cs" />
<Compile Include="mod\database\t_serialport.cs" />
<Compile Include="mod\database\t_sn.cs" />
<Compile Include="mod\database\t_user.cs" />
<Compile Include="mod\enum\plc_emum.cs" />
<Compile Include="mod\server\otherdata.cs" />

View File

@ -109,6 +109,7 @@ namespace WindowsFormsApp1
this.底部注释4 = new System.Windows.Forms.Label();
this.底部注释5 = new System.Windows.Forms.Label();
this.btnToggleTestMode = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.tableLayoutPanel7 = new System.Windows.Forms.TableLayoutPanel();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.richTextBox2 = new System.Windows.Forms.RichTextBox();
@ -933,6 +934,7 @@ namespace WindowsFormsApp1
this.tableLayoutPanel8.Controls.Add(this.底部注释4, 3, 0);
this.tableLayoutPanel8.Controls.Add(this.底部注释5, 4, 0);
this.tableLayoutPanel8.Controls.Add(this.btnToggleTestMode, 9, 0);
this.tableLayoutPanel8.Controls.Add(this.button1, 8, 0);
this.tableLayoutPanel8.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel8.Location = new System.Drawing.Point(3, 1028);
this.tableLayoutPanel8.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
@ -1004,6 +1006,17 @@ namespace WindowsFormsApp1
this.btnToggleTestMode.UseVisualStyleBackColor = false;
this.btnToggleTestMode.Click += new System.EventHandler(this.BtnToggleTestMode_Click);
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Fill;
this.button1.Location = new System.Drawing.Point(1403, 3);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(169, 30);
this.button1.TabIndex = 6;
this.button1.Text = "螺丝开盖";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// tableLayoutPanel7
//
this.tableLayoutPanel7.ColumnCount = 2;
@ -1159,6 +1172,7 @@ namespace WindowsFormsApp1
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Button btnToggleTestMode;
private System.Windows.Forms.Button button1;
}
}

View File

@ -198,6 +198,30 @@ namespace WindowsFormsApp1
{
LOT号.Text = PlcData.Write_stSN;
Tray盘二维码.Text = PlcData.Read_MaterialCode1;
/*
//额外功能,将sn写入数据库中
var snHelper = new db.SQLiteHelper<t_sn>();
var snList = snHelper.QueryAll();
if(snList.Success && snList.Data.Count > 0)
{
var t_sn = new t_sn
{
id = 1,
sn = PlcData.Read_MaterialCode0
};
snHelper.Update(t_sn);
}
else
{
var t_sn = new t_sn
{
id = 1,
sn = PlcData.Read_MaterialCode0
};
snHelper.Insert(t_sn);
}
*/
}
if(Init.t_Lineplcs.Count == 1)
{
@ -719,7 +743,11 @@ namespace WindowsFormsApp1
{
ChangeBarcode();
MES_MsgfORM(nowinterface.code, result, result.Requesttime);
//出站清空sn
if(nowinterface.code == "SN_Checkout")
{
PlcData.Write_stSN = "";
}
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!writeresult.Success)
{
@ -863,6 +891,7 @@ namespace WindowsFormsApp1
Init.t_Pressurecurves = pressurecurve_result.Data;
Init.t_Interfaces = interface_result.Data;
Init.t_Keyvalues = key_sqlresult.Data;
Init.t_plcs = plc_result;
// 初始化PLC状态面板
InitializePlcStatusPanel();
@ -1742,6 +1771,59 @@ namespace WindowsFormsApp1
LogExecute.logNet.WriteError($"定时上报机台状态异常: {ex.Message}");
}
}
// 定时扫描 周期扫描未上传 图片,视频等 sn,然后调用上传文件接口 todo
#endregion 定时器
/// <summary>
/// 螺丝开盖
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
var plc = Init.t_plcs.FirstOrDefault();
plc.plchelp = new SiemensHelp(plc.plcip, plc.timeout);
SiemensHelp siemensHelp = plc.plchelp;
List<t_plcaddress> plcaddress = Init.t_Plcaddresses.FindAll(a => a.plcid == plc.id);
var openresult = siemensHelp.OpenConn();
plcdata PlcData = new plcdata();
var resdresult = siemensHelp.ReadAddress(plcaddress, PlcData);
if (!resdresult.Success)
{
LogExecute.logNet.WriteError($"{plc.plcname}:{plc.plcip}读取全部地址处理错误:处理停止");
}
//扫码
ScanForm scanForm = new ScanForm();
DialogResult scan_result = scanForm.ShowDialog();
if (scan_result == DialogResult.OK)
{
string returnValue = scanForm.ReturnValue;
var writeVal = Init.t_Keyvalues.First(x => x.key == returnValue)?.value;
if (string.IsNullOrEmpty(writeVal))
{
PlcData.Write_Other4 = short.Parse(writeVal);
var result = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!result.Success)
{
LogExecute.logNet.WriteError($"{plc.plcname}:{plc.plcip}写入螺丝开盖失败:处理停止");
}
else
{
LogExecute.logNet.WriteInfo($"{plc.plcname}:{plc.plcip}写入螺丝开盖成功,值:{writeVal}");
}
}
else
{
LogExecute.logNet.WriteError($"未找到螺丝开盖二维码!");
}
}
}
}
}

View File

@ -41,6 +41,7 @@ namespace WindowsFormsApp1
public static List<t_flow> t_Flows;
public static List<t_lineplc> t_Lineplcs;
public static List<t_plc> t_plcs;
public static List<t_interface> t_Interfaces;
public static List<t_plcaddress> t_Plcaddresses;

View File

@ -9,6 +9,7 @@ namespace WindowsFormsApp1.mod
[PrimaryKey, AutoIncrement]
public int id { get; set; }
public string sn { get; set; }
public string CarrierID { get; set; }
// plc反馈的结果,ok/ng
public string result { get; set; }
public int imageUploaded { get; set; }

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SQLite;
namespace WindowsFormsApp1.mod
{
[Table("sn")]
public class t_sn
{
public int id { get; set; }
public string sn { get; set; }
}
}

View File

@ -78,6 +78,8 @@ namespace WindowsFormsApp1.mod.server
public int opindex { get; set; }
public int plcid { get; set; }
public t_materialupload material { get; set; }
}

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)
{