Compare commits

..
4 Commits
Author SHA1 Message Date
gf zhou eb64a3fc2f 写入冷却加热时间
测试模式切换时对应的定时器也要开启关闭
读到3触发字,关闭扫码页面
2025-06-02 16:43:09 +08:00
gf zhou 817b66ad53 5.12 OEE相关日志放到右侧
螺丝添加NG的统计
2025-05-12 14:01:46 +08:00
zhougf e8001a81bb PLC时间对接
定时器测试
s7通讯加辅助方法
4.21 测试
2025-04-21 15:29:57 +08:00
gf zhou 76cd069435 4.18 checkin不管成功失败都写sn
加上needwork的判定
datacollection 判断dcinfo为空,不传mes,事件不显示在事件列表,只记录日志
状态上传定时器重新修改上传逻辑
文件上传定时器
2025-04-20 18:15:30 +08:00
10 changed files with 691 additions and 300 deletions

No files matched your search

+8 -1
View File
@@ -182,7 +182,9 @@
<Compile Include="form\OEEaddress_Manage.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="form\OEEaddress_Manage.Designer.cs" />
<Compile Include="form\OEEaddress_Manage.Designer.cs">
<DependentUpon>OEEaddress_Manage.cs</DependentUpon>
</Compile>
<Compile Include="form\ScanForm_DZ.cs">
<SubType>Form</SubType>
</Compile>
@@ -342,6 +344,11 @@
<EmbeddedResource Include="form\Angleaddress_Manage.resx">
<DependentUpon>Angleaddress_Manage.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="form\OEEaddress_Manage.resx">
<DependentUpon>OEEaddress_Manage.cs</DependentUpon>
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>OEEaddress_Manage1.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="form\ScanForm_DZ.resx">
<DependentUpon>ScanForm_DZ.cs</DependentUpon>
</EmbeddedResource>
+319 -155
View File
@@ -17,12 +17,14 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using HslCommunication.LogNet;
using Newtonsoft.Json.Linq;
using WindowsFormsApp1.db;
using WindowsFormsApp1.form;
using WindowsFormsApp1.mod;
using WindowsFormsApp1.mod.database;
using WindowsFormsApp1.mod.server;
using WindowsFormsApp1.server;
using static System.Collections.Specialized.BitVector32;
using static SQLite.SQLite3;
using static WindowsFormsApp1.server.ApiClient;
using Label = System.Windows.Forms.Label;
@@ -50,6 +52,9 @@ namespace WindowsFormsApp1
private System.Windows.Forms.Timer statusReportTimer = new System.Windows.Forms.Timer();
private System.Windows.Forms.Timer screwReportTimer = new System.Windows.Forms.Timer();
private System.Windows.Forms.Timer fileUploadTimer = new System.Windows.Forms.Timer();
private ApiClient statusApiClient = new ApiClient(); // 专用于状态上报的API客户端
private object curingLock = new object();
private Dictionary<int, int> OldPlcTrigger = new Dictionary<int, int>();
@@ -59,6 +64,8 @@ namespace WindowsFormsApp1
private List<Panel> eventPanels = new List<Panel>();
private Queue<EventInfo> eventHistory = new Queue<EventInfo>();
private const int MAX_EVENT_DISPLAY = 5;
private int beginScrewReportTimer = -100;
#endregion 内部变量
public MainForm()
@@ -121,11 +128,15 @@ namespace WindowsFormsApp1
开始处理_Click(this, EventArgs.Empty);
// 初始化状态上报定时器
statusReportTimer.Interval = int.Parse(Init.t_Keyvalues.First(x => x.key == "StatusTime").value) * 1000; // 15秒
//statusReportTimer.Interval = int.Parse(Init.t_Keyvalues.First(x => x.key == "StatusTime").value) * 1000; // 15秒
statusReportTimer.Interval = 1000 * 15;
statusReportTimer.Tick += StatusReportTimer_Tick;
screwReportTimer.Interval = 8000;
screwReportTimer.Interval = 1000 * 60 * 5;
screwReportTimer.Tick += ScrewReportTimer_Tick;
fileUploadTimer.Interval = 1000 * 60 * 2;
fileUploadTimer.Tick += FileUploadTimer_Tick;
}
public void build(t_plc Plc, CancellationToken token)
@@ -167,7 +178,7 @@ namespace WindowsFormsApp1
// 更新对应PLC的状态指示器为红色
UpdatePlcStatus(Plc.id, false);
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}建立S7连接失败");
//LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}建立S7连接失败");
continue;
}
@@ -188,18 +199,17 @@ namespace WindowsFormsApp1
continue;
}
/*
* //写入心跳 在主线程取消,单独开线程 写plc心跳
PlcData.Write_Heartbeat = PlcData.Write_Heartbeat == 0 ? (short)1 : (short)0;
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!haertresult.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入心跳错误:处理停止");
continue;
}*/
/*
* //写入心跳 在主线程取消,单独开线程 写plc心跳
PlcData.Write_Heartbeat = PlcData.Write_Heartbeat == 0 ? (short)1 : (short)0;
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!haertresult.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入心跳错误:处理停止");
continue;
}*/
if (Init.t_Lineplcs.Count >= 2 && Plc.id == Init.t_Lineplcs.First().plcid)
{
@@ -228,9 +238,9 @@ namespace WindowsFormsApp1
snHelper.Insert(t_sn);
}
*/
}
if(Init.t_Lineplcs.Count == 1)
if (Init.t_Lineplcs.Count == 1)
{
LOT号.Text = PlcData.Write_stSN;
Tray盘二维码.Text = PlcData.Read_MaterialCode1;
@@ -256,13 +266,15 @@ namespace WindowsFormsApp1
PlcData.Write_Other0 = 1;
}
var okNgresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!okNgresult.Success)
if (PlcData.Write_Other0 == 1)
{
LogExecute.logNet.WriteError($"{Plc.plcip}写入OK/NG:处理停止");
continue;
var okNgresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!okNgresult.Success)
{
LogExecute.logNet.WriteError($"{Plc.plcip}写入OK/NG:处理停止");
continue;
}
}
var imageFormIsOpened = false;
foreach (Form form in Application.OpenForms)
{
@@ -276,7 +288,8 @@ namespace WindowsFormsApp1
{
if (!imageFormIsOpened)
{
this.Invoke(new Action(() => {
this.Invoke(new Action(() =>
{
ImageDisplayForm imageDisplayForm = new ImageDisplayForm();
imageDisplayForm.Show();
}));
@@ -312,7 +325,7 @@ namespace WindowsFormsApp1
{
//反馈状态
Init.Plcstatus = PlcData.Read_Status;
Init.Plcstatus_LastTime = DateTime.Now;
otherdata.Plc_Status = PlcData.Read_Status.ToString();
if (PlcData.Read_Status == 2)
@@ -327,9 +340,24 @@ namespace WindowsFormsApp1
var statusresult = apiClient.CallFunctionByName("Status", PlcData, otherdata);
if (statusresult.Success)
{
LogExecute.OEElogNet.WriteDebug($"上报机台状态成功: {plcstatus.GetName(typeof(plcstatus), Init.Plcstatus)} {Init.ErrorCode}");
MES_MsgfORM("Status", statusresult, statusresult.Requesttime);
LogExecute.OEElogNet.WriteDebug($"上报机台状态成功: {plcstatus.GetName(typeof(plcstatus), Init.Plcstatus)} {otherdata.Plc_Status}");
//beginScrewReportTimer = 0;
if (!statusReportTimer.Enabled)
{
this.Invoke(new Action(() =>
{
statusReportTimer.Start();
}));
}
else
{
this.Invoke(new Action(() =>
{
statusReportTimer.Stop();
statusReportTimer.Start();
}));
}
//MES_MsgfORM("Status", statusresult, statusresult.Requesttime);
if (statusresult.Mesresult != mesresult.PASS)
{
PlcData.Write_Status = 1001;
@@ -377,7 +405,7 @@ namespace WindowsFormsApp1
siemensHelp.WriteAddress(plcaddress, PlcData);
}
}
continue;
//continue;
}
else
{
@@ -398,6 +426,8 @@ namespace WindowsFormsApp1
OldPlcTrigger[Plc.id] = PlcData.Read_Trigger;
}
LogExecute.logNet.WriteDebug($"读取状态字{Plc.plcname}:{Plc.id}-{PlcData.Read_Trigger}");
if (PlcData.Read_Trigger == 0 && PlcData.Write_Status == 0)
{
continue;
@@ -416,9 +446,10 @@ namespace WindowsFormsApp1
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止");
}
LogExecute.logNet.WriteDebug($"写入状态字0");
continue;
}
LogExecute.logNet.WriteDebug($"读取状态字{Plc.id}-{PlcData.Read_Trigger}");
var nowflow = Init.t_Flows.FirstOrDefault(a => a.hopestatus == PlcData.Read_Trigger);
if (nowflow == null)
@@ -434,7 +465,7 @@ namespace WindowsFormsApp1
}
#endregion
#region 根据流程,判断是否需要扫码、气密、扭力等
if (nowflow.scan)
{
@@ -472,62 +503,62 @@ namespace WindowsFormsApp1
{
continue;
}
/*
//扫码
var stationid = Init.t_Line.lineremark2;
// ccd扫码
if ("Assy1,".Contains(stationid))
{
SQLiteHelper<t_keyvalue> sQLiteHelper_key = new db.SQLiteHelper<t_keyvalue>();
var key_sqlresult = sQLiteHelper_key.QueryAll();
/*
//扫码
var stationid = Init.t_Line.lineremark2;
// ccd扫码
if ("Assy1,".Contains(stationid))
{
SQLiteHelper<t_keyvalue> sQLiteHelper_key = new db.SQLiteHelper<t_keyvalue>();
var key_sqlresult = sQLiteHelper_key.QueryAll();
var result1 = apiClient.CallFunctionByName("SN_FeedingCheck", PlcData, new otherdata() { JS_SN = PlcData.Read_MaterialCode2 });
if (result1.Success && result1.Mesresult == mesresult.PASS)
{
//继续调用接口
var result2 = apiClient.CallFunctionByName("Link_Comp", PlcData, new otherdata() { JS_SN = PlcData.Read_MaterialCode2 });
if (result2.Success && result2.Mesresult == mesresult.PASS)
{
// 写数据到 主页的barcode 数据库改,缓存改
var txt = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode1");
txt.value = PlcData.Read_MaterialCode2;
var result1 = apiClient.CallFunctionByName("SN_FeedingCheck", PlcData, new otherdata() { JS_SN = PlcData.Read_MaterialCode2 });
if (result1.Success && result1.Mesresult == mesresult.PASS)
{
//继续调用接口
var result2 = apiClient.CallFunctionByName("Link_Comp", PlcData, new otherdata() { JS_SN = PlcData.Read_MaterialCode2 });
if (result2.Success && result2.Mesresult == mesresult.PASS)
{
// 写数据到 主页的barcode 数据库改,缓存改
var txt = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode1");
txt.value = PlcData.Read_MaterialCode2;
var code = key_sqlresult.Data.First(x => x.key == txt.key);
code.value = PlcData.Read_MaterialCode2;
sQLiteHelper_key.Update(code);
}
else
{
LogExecute.logNet.WriteError($"{PlcData.Read_MaterialCode2}绑定NG");
}
}
else
{
LogExecute.logNet.WriteError($"{PlcData.Read_MaterialCode2}核对NG");
}
}
else
{
ScanForm_DZ scanForm = new ScanForm_DZ();
DialogResult scan_result = scanForm.ShowDialog();
}
ChangeBarcode();
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!writeresult.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止");
continue;
}
else
{
//MES链接状态.Text = "MES链接状态:OK";
//MES链接状态.BackColor = SystemColors.Control;
//MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
}
continue;
*/
var code = key_sqlresult.Data.First(x => x.key == txt.key);
code.value = PlcData.Read_MaterialCode2;
sQLiteHelper_key.Update(code);
}
else
{
LogExecute.logNet.WriteError($"{PlcData.Read_MaterialCode2}绑定NG");
}
}
else
{
LogExecute.logNet.WriteError($"{PlcData.Read_MaterialCode2}核对NG");
}
}
else
{
ScanForm_DZ scanForm = new ScanForm_DZ();
DialogResult scan_result = scanForm.ShowDialog();
}
ChangeBarcode();
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!writeresult.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止");
continue;
}
else
{
//MES链接状态.Text = "MES链接状态:OK";
//MES链接状态.BackColor = SystemColors.Control;
//MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
}
continue;
*/
//if (scan_result == DialogResult.OK)
//{
// string returnValue = scanForm.ReturnValue;
@@ -554,23 +585,21 @@ namespace WindowsFormsApp1
}
otherdata.FinalPressureCurve = pressurecurveaddress_result.Data;
}
//if (nowflow.finaltorquecurve)
//{
// //扭力曲线(这里不处理,后端API获取)
//}
//螺丝扭力
if (nowflow.finaltorquevalue)
{
//螺丝枪扭力数据
var finaltorquevalue_result = siemensHelp.ReadAddress(torqueaddress);
if (!finaltorquevalue_result.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}螺丝枪扭力数据地址处理错误:处理停止");
continue;
}
otherdata.FinalTorqueValue = finaltorquevalue_result.Data;
/* var finaltorquevalue_result = siemensHelp.ReadAddress(torqueaddress);
if (!finaltorquevalue_result.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}螺丝枪扭力数据地址处理错误:处理停止");
continue;
}
otherdata.FinalTorqueValue = finaltorquevalue_result.Data;
*/
}
//气密
if (nowflow.airtight)
@@ -585,20 +614,29 @@ namespace WindowsFormsApp1
var finalanglevaluue_result = siemensHelp.ReadAddress(angleaddress);
if (!finalanglevaluue_result.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}螺丝枪角度数据地址处理错误:处理停止");
continue;
}
otherdata.FinalAngleValue = finalanglevaluue_result.Data;
otherdata.FinalAngleValue = Enumerable
.Range(0, (finalanglevaluue_result.Data.Count + 3) / 4) // 计算组数
.Select(i => finalanglevaluue_result.Data.Skip(i * 4).Take(4).ToList())
.ToList();
}
if (nowflow.fileupload)
{
//文件上传
}
// oeedatacollection
var oeeresult = siemensHelp.ReadAddress(oeeaddresses);
otherdata.Oeeaddresses = oeeaddresses;
try
{
var oeeresult = siemensHelp.ReadAddress(oeeaddresses);
otherdata.Oeeaddresses = oeeaddresses;
}
catch
{
LogExecute.logNet.WriteError("读取PLC OEE失败!");
}
#endregion
#region 判断物料调用次数 固化站,抽真空
@@ -735,7 +773,7 @@ namespace WindowsFormsApp1
{
ChangeBarcode();
MES_MsgfORM(nowinterface.code, result, result.Requesttime);
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!writeresult.Success)
{
@@ -760,7 +798,7 @@ namespace WindowsFormsApp1
PlcData.Write_Status = 1001;
}
siemensHelp.WriteAddress(plcaddress, PlcData);
LogExecute.logNet.WriteDebug($"上位机写入触发字:{PlcData.Write_Status}");
LogExecute.logNet.WriteDebug($"{Plc.plcname}:{Plc.plcip}上位机写入触发字:{PlcData.Write_Status}");
continue;
}
else
@@ -771,7 +809,8 @@ namespace WindowsFormsApp1
PlcData.Write_stSN = "";
}
}
LogExecute.logNet.WriteDebug($"{Plc.plcname}:{Plc.plcip}上位机写入触发字:{PlcData.Write_Status}");
}
}
else
@@ -884,7 +923,7 @@ namespace WindowsFormsApp1
foreach (var item in Init.t_Lineplcs)
{
if(!OldPlcTrigger.ContainsKey(item.plcid))
if (!OldPlcTrigger.ContainsKey(item.plcid))
OldPlcTrigger.Add(item.plcid, 0);
}
@@ -905,8 +944,16 @@ namespace WindowsFormsApp1
// 启动状态上报定时器
statusReportTimer.Start();
screwReportTimer.Start();
//测试环境不上传数据
if (Init.t_Keyvalues.FirstOrDefault(x => x.key == "TestMode").value == "0")
{
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(Init.t_Line.lineremark2.ToLower()))
{
screwReportTimer.Start();
}
fileUploadTimer.Start();
}
#endregion
#region 初始化COM口服务
@@ -989,7 +1036,7 @@ namespace WindowsFormsApp1
Init.threadHelps.Add(threadHelp1);
}
if(Init.t_User.username.ToLower() != "admin")
if (Init.t_User.username.ToLower() != "admin")
{
this.btnToggleTestMode.Enabled = false;
}
@@ -1073,6 +1120,7 @@ namespace WindowsFormsApp1
// 停止状态上报定时器
statusReportTimer.Stop();
screwReportTimer.Stop();
fileUploadTimer.Stop();
// 停止所有线程
if (Init.threadHelps != null)
@@ -1091,9 +1139,11 @@ namespace WindowsFormsApp1
}
}
thread.isrunning1 = false;
thread.Dispose();
}
catch { /* 忽略异常 */ }
}
Init.threadHelps.Clear();
}
// 安全关闭串口
@@ -1644,6 +1694,7 @@ namespace WindowsFormsApp1
{
//后一台气密
//<01>:(OK): 0.032 ml/min
//LogExecute.logNet.WriteDebug(ReturnValue);
Init.airtight.Leak_Value = ReturnValue.Substring(11, 5);
Init.airtight.LastTime = DateTime.Now;
}
@@ -1746,7 +1797,27 @@ namespace WindowsFormsApp1
};
kvHelper.Insert(newSetting);
}
if (newMode)
{
//调试
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(Init.t_Line.lineremark2.ToLower()))
{
if (screwReportTimer.Enabled)
screwReportTimer.Stop();
}
if (fileUploadTimer.Enabled)
fileUploadTimer.Stop();
}
else
{
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(Init.t_Line.lineremark2.ToLower()))
{
if(!screwReportTimer.Enabled)
screwReportTimer.Start();
}
if(!fileUploadTimer.Enabled)
fileUploadTimer.Start();
}
// 更新按钮状态
UpdateTestModeButtonState();
@@ -1775,10 +1846,13 @@ namespace WindowsFormsApp1
{
try
{
//beginScrewReportTimer++;
// 如果没有PLC数据或者状态为0,则不上报
if (Init.Plcstatus == 0 || Init.Plcstatus == -1)
{
return;
}
otherdata statusOtherData = new otherdata();
statusOtherData.Plc_Status = Init.Plcstatus.ToString();
if (Init.Plcstatus == 2)
@@ -1789,7 +1863,8 @@ namespace WindowsFormsApp1
var statusResult = statusApiClient.CallFunctionByName("Status", new plcdata(), statusOtherData);
if (statusResult.Success)
{
MES_MsgfORM("Status", statusResult, statusResult.Requesttime);
beginScrewReportTimer = 0;
//MES_MsgfORM("Status", statusResult, statusResult.Requesttime);
// 更新最后上报时间
Init.Plcstatus_LastTime = DateTime.Now;
@@ -1810,33 +1885,91 @@ namespace WindowsFormsApp1
//螺丝扭力上传定时器
private void ScrewReportTimer_Tick(object sender, EventArgs e)
{
SQLiteHelper<t_materialupload> sQLiteHelper_upload = new db.SQLiteHelper<t_materialupload>();
var material_sqlresult = sQLiteHelper_upload
.Query(x => x.datacollectionUploaded == 1);
if (material_sqlresult.Success)
// 螺丝站
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(Init.t_Line.lineremark2.ToLower()))
{
ApiClient apiClient = new ApiClient();
var materialList = material_sqlresult.Data.Take(5);
foreach(var material in materialList)
SQLiteHelper<t_materialupload> sQLiteHelper_upload = new db.SQLiteHelper<t_materialupload>();
var material_sqlresult = sQLiteHelper_upload
.Query(x => x.datacollectionUploaded == 1 && x.sn != "");
if (material_sqlresult.Success)
{
otherdata OtherData = new otherdata();
OtherData.material = material;
var result = apiClient.CallFunctionByName("Data_Collection", new plcdata(), OtherData);
if (result.Success)
ApiClient apiClient = new ApiClient();
var materialList = material_sqlresult.Data.Where(x => (DateTime.Now - x.outtime).TotalMinutes > 20).Take(5);
foreach (var material in materialList)
{
MES_MsgfORM("Data_Collection", result, result.Requesttime);
if(result.Mesresult == mesresult.PASS)
otherdata OtherData = new otherdata();
OtherData.material = material;
var result = apiClient.CallFunctionByName("Data_Collection", new plcdata(), OtherData);
if (result.Success)
{
//标记该物料已上传
material.datacollectionUploaded = 2;
sQLiteHelper_upload.Update(material);
LogExecute.OEElogNet.WriteDebug($"{material.sn} 扭力上报成功!");
//MES_MsgfORM("Data_Collection", result, result.Requesttime);
if (result.Mesresult == mesresult.PASS)
{
//标记该物料已上传
material.datacollectionUploaded = 2;
sQLiteHelper_upload.Update(material);
LogExecute.logNet.WriteDebug($"{material.sn} 扭力上报成功!");
}
else if (result.Mesresult == mesresult.NONE)
{
material.datacollectionUploaded = 3;
sQLiteHelper_upload.Update(material);
}
}
}
}
}
}
// 定时扫描 周期扫描未上传 图片,视频等 sn,然后调用上传文件接口 todo
private void FileUploadTimer_Tick(object sender, EventArgs e)
{
//LogExecute.logNet.WriteDebug($"定时器文件执行!");
SQLiteHelper<t_materialupload> sQLiteHelper_upload = new db.SQLiteHelper<t_materialupload>();
var material_sqlresult = sQLiteHelper_upload
.Query(x => (x.imageUploaded == 1 || x.vedioUploaded == 1)
&& x.sn != ""
&& x.sn != "TEST MODE testsn");
if (material_sqlresult.Success)
{
ApiClient apiClient = new ApiClient();
var materialList = material_sqlresult.Data.Take(5);
foreach (var material in materialList)
{
otherdata OtherData = new otherdata();
OtherData.material = material;
OtherData.FileUploadAddress = Init.t_Keyvalues.First(x => x.key == "UploadPath").value;
OtherData.ImageAddress = Init.t_Keyvalues.First(x => x.key == "ImageFilePath").value;
OtherData.VedioAddress = Init.t_Keyvalues.First(x => x.key == "VedioFilePath").value;
var result = apiClient.CallFunctionByName("SN_FileUpload", new plcdata(), OtherData);
if (result.Success)
{
//MES_MsgfORM("Data_Collection", result, result.Requesttime);
if (result.Mesresult == mesresult.PASS)
{
//标记该物料已上传
if (material.imageUploaded == 1)
material.imageUploaded = 2;
if (material.vedioUploaded == 1)
material.vedioUploaded = 2;
sQLiteHelper_upload.Update(material);
LogExecute.logNet.WriteDebug($"{material.sn} 文件上传成功!");
}
else if (result.Mesresult == mesresult.NONE)
{
//标记该物料已上传
if (material.imageUploaded == 1)
material.imageUploaded = 3;
if (material.vedioUploaded == 1)
material.vedioUploaded = 3;
sQLiteHelper_upload.Update(material);
}
}
}
}
}
#endregion 定时器
/// <summary>
@@ -1889,43 +2022,74 @@ namespace WindowsFormsApp1
}
}
}
//plc心跳
private void plcheart(t_plc Plc, CancellationToken token)
{
while (!token.IsCancellationRequested)
Task.Factory.StartNew(() =>
{
try
while (!token.IsCancellationRequested)
{
SiemensHelp siemensHelp = Plc.plchelp;
List<t_plcaddress> plcaddress = Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id);
plcdata PlcData = new plcdata();
var resdresult = siemensHelp.ReadAddress(plcaddress, PlcData);
if (!resdresult.Success)
try
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}读取全部地址处理错误!");
SiemensHelp siemensHelp = Plc.plchelp;
List<t_plcaddress> plcaddress = Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id
&& a.code == "Write_Heartbeat" || a.code == "Read_Trigger");
List<t_plcaddress> timeplcaddress = Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id
&& a.code == "NowDateTime");
plcdata PlcData = new plcdata();
var resdresult = siemensHelp.ReadAddress(plcaddress, PlcData);
if (!resdresult.Success)
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}读取全部地址处理错误!");
}
if(PlcData.Read_Trigger == 3 && Application.OpenForms.Count > 1)
{
foreach (Form form in Application.OpenForms)
{
if (form.Name == "ScanForm")
{
this.Invoke(new Action(() =>
{
form.Close();
}));
}
}
}
//写入心跳
PlcData.Write_Heartbeat = PlcData.Write_Heartbeat == 0 ? (short)1 : (short)0;
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!haertresult.Success)
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入心跳失败!");
}
//写入时间
var timeData = new plcdata
{
NowDateTime = DateTime.Now.AddSeconds(3)
};
var timeresult = siemensHelp.WriteAddress(timeplcaddress, timeData);
if (!timeresult.Success)
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入时间失败!");
}
}
//写入心跳
PlcData.Write_Heartbeat = PlcData.Write_Heartbeat == 0 ? (short)1 : (short)0;
//LogExecute.logNet.WriteDebug($"{Plc.plcname}:{Plc.plcip}写入心跳{PlcData.Write_Heartbeat}!");
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!haertresult.Success)
catch (Exception)
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入心跳错误!");
}
finally
{
Thread.Sleep(1000);
}
}
catch (Exception)
{
}
finally
{
Thread.Sleep(1000);
}
}
}, token, TaskCreationOptions.LongRunning, TaskScheduler.Default
);
}
}
}
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -16,5 +16,6 @@ namespace WindowsFormsApp1.mod
public int vedioUploaded { get; set; }
public int datacollectionUploaded { get; set; }
public string date { get; set; }
public DateTime outtime { get; set; }
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ namespace WindowsFormsApp1.mod.server
/// <summary>
/// 螺丝枪角度
/// </summary>
public List<float> FinalAngleValue { get; set; }
public List<List<dynamic>> FinalAngleValue { get; set; }
/// <summary>
/// 螺丝枪扭力曲线
+1
View File
@@ -187,5 +187,6 @@ namespace WindowsFormsApp1.mod.server
/// 写入PLC的时间
/// </summary>
public DateTime Write_Time2 { get; set; }
public DateTime NowDateTime { get; set; }
}
}
+197 -134
View File
@@ -143,7 +143,14 @@ namespace WindowsFormsApp1.server
PlcData.Write_Status = (short)statusCode;
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
PlcData.Write_stSN = "TEST MODE testsn";
LogExecute.logNet.WriteDebug($"{eventName} 测试接口请求成功\n请求:{jsonPayload}\n");
if (eventName == "Status" || eventName == "Alarm" || eventName == "OEEDataCollection")
{
LogExecute.OEElogNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n");
}
else
{
LogExecute.logNet.WriteDebug($"{eventName} 测试接口请求成功\n请求:{jsonPayload}\n");
}
return ApiFormResult.Sucess(mesresult.PASS, true, "PASS", PlcData, DateTime.Now);
}
#endregion test
@@ -157,7 +164,8 @@ namespace WindowsFormsApp1.server
var response = _httpClient.PostAsync(url, httpContent).Result;
// 检查响应状态码
if (response.StatusCode == System.Net.HttpStatusCode.OK)
if (response.StatusCode == System.Net.HttpStatusCode.OK
|| response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
// 读取响应内容
string responseContent = response.Content.ReadAsStringAsync().Result;
@@ -168,20 +176,28 @@ namespace WindowsFormsApp1.server
// 访问动态对象的属性
if (res != null)
{
LogExecute.logNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
//oee相关日志单独存
if (eventName == "Status" || eventName == "Alarm" || eventName == "OEEDataCollection")
{
LogExecute.OEElogNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
}
else
{
LogExecute.logNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
}
// 成功!
if (res.Result != null && !string.IsNullOrEmpty(res.Result.Value))
{
var result = res.Result.Value == "PASS";
if (!string.IsNullOrEmpty(res?.Need_Work?.Value) && res?.Need_Work?.Value == "PASS")
result = true;
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
PlcData.Write_stSN = res.SN.Value;
if (result)
{
// 回写对应PLC
if (statusCode > 0)
PlcData.Write_Status = (short)statusCode;
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
PlcData.Write_stSN = res.SN.Value;
if (eventName == "SN_FeedingCheck")
{
var station = Init.t_Line.lineremark2.ToLower();
@@ -447,7 +463,7 @@ namespace WindowsFormsApp1.server
//判断站
var station = Init.t_Line.lineremark2.ToLower();
var fixsn_1 = "";
var locationindex = 1;
var locationindex = "";
switch (station)
{
case "potting"://灌胶
@@ -457,7 +473,7 @@ namespace WindowsFormsApp1.server
break;
default:
fixsn_1 = "CompSN";
locationindex = OtherData.locationindex;
locationindex = OtherData.locationindex.ToString();
break;
}
@@ -468,13 +484,13 @@ namespace WindowsFormsApp1.server
StationID = _stationID,
MachineID = _machineID,
OPID = OtherData.opindex,
Token = locationindex.ToString() ?? "",//判断站,胶水不用传
Token = locationindex ?? "",//判断站,胶水不用传
FixSN = fixsn_1,//判断站,胶水不用传
SN = OtherData.JS_SN ?? "",
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
};
return CallApi(url, request, "Glue_CheckOut", PlcData, PLC_Status.Glue_CheckOut);
return CallApi(url, request, "Glue_CheckOut", PlcData, 0);
}
/// <summary>
@@ -525,7 +541,7 @@ namespace WindowsFormsApp1.server
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.lineremark2}@{Init.t_Line.linecode}&includeCurve=true&includeSteps=false";
var geturl = $"http://10.50.12.41/getdata/v2/tighteningresults?startTime={OtherData.material.date.Substring(0, 10)}&endTime={DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")}&vin={OtherData.material.sn}&controllerName={Init.t_Line.lineremark2}@{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;
@@ -582,15 +598,17 @@ namespace WindowsFormsApp1.server
LogExecute.logNet.WriteError($"解析马头数据,发生错误: {ex.Message}");
}
}
else
{
return ApiFormResult.Sucess(mesresult.FAIL, false, "请求马头服务器获取数据失败", PlcData, DateTime.Now);
}
if (request.DC_INFO.Count == 0)
{
return ApiFormResult.Sucess(mesresult.NONE, false, "请求马头服务器获取数据失败", PlcData, DateTime.Now);
}
}
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)
@@ -620,7 +638,7 @@ namespace WindowsFormsApp1.server
StationID = _stationID,
MachineID = _machineID,
OPID = _opID,
AlarmID = Init.ErrorCode,
AlarmID = Init.ErrorCode ?? "",
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
ResetTime = ""
};
@@ -638,21 +656,41 @@ namespace WindowsFormsApp1.server
public ApiFormResult SN_FileUpload(string url, plcdata PlcData, otherdata OtherData)
{
// 准备文件 视频/图片 目的路径拼接
var month = DateTime.Now.ToString("yyyyMM");
var day = DateTime.Now.ToString("dd");
var month = "";
var day = "";
if (OtherData.material.imageUploaded == 1)
{
month = OtherData.material.date.Replace("-", "").Substring(0, 6);
day = OtherData.material.date.Replace("-", "").Substring(6, 2);
}
else
{
var monthList = OtherData.material.date.Split('-');
month = $"{monthList[0]}{monthList[1]}";
day = monthList[2];
}
var monthDay = DateTime.Now.ToString("MMdd");
var time = DateTime.Now.ToString("HHmmss");
var result = PlcData.Read_Result == 1 ? "OK" : "NG";
var result = OtherData.material.result;
var targetDirectory = $"{OtherData.FileUploadAddress}{_line.Substring(0, 2)}\\{month}\\{day}\\Line{_line.Substring(_line.Length - 2)}\\{_stationID}\\{_machineID}\\{result}";
var fileName = "";
try
{
string[] sourceFolders = new string[] {
string[] sourceFolders = new string[]
{
OtherData.ImageAddress,
OtherData.VedioAddress
};
if (OtherData.material.imageUploaded != 1)
{
sourceFolders[0] = "";
}
if (OtherData.material.vedioUploaded != 1)
{
sourceFolders[1] = "";
}
// 使用分号分隔多个源文件夹
string targetFolder = targetDirectory;
List<string> fileList = new List<string>();
@@ -666,11 +704,6 @@ namespace WindowsFormsApp1.server
return ApiFormResult.Error(mesresult.FAIL, false, "SN号为空", PlcData, DateTime.Now);
}
if (!Directory.Exists(targetFolder))
{
Directory.CreateDirectory(targetFolder);
}
foreach (string folder in sourceFolders)
{
if (string.IsNullOrEmpty(folder))
@@ -678,32 +711,32 @@ namespace WindowsFormsApp1.server
continue;
}
//判断此sn需要传哪些数据 图片 或视频 todo
string sourceFolder = sourceFolders[0];
if (sourceFolder == folder)
string sourceFolder = "";
if (OtherData.ImageAddress == folder)
{
// 图片
// 组装路径 可能需要从数据库读 result和sn和日期
sourceFolder = Path.Combine(sourceFolder, OtherData.material.date, "DCDC", result);
sourceFolder = Path.Combine(OtherData.ImageAddress, OtherData.material.date.Replace("-", ""), "DCDC", result);
}
else
{
// 视频
sourceFolder = Path.Combine(sourceFolder, DateTime.Now.ToString("yyyy-MM-dd"));
sourceFolder = Path.Combine(OtherData.VedioAddress, OtherData.material.date);
}
if (Directory.Exists(sourceFolder.Trim()))
{
string[] files = Directory.GetFiles(sourceFolder.Trim());
int num = 1;
var extensionstr = "";
foreach (string file in files)
foreach (string file in files.Where(x => x.Contains(snNumber)))
{
string fileName1 = Path.GetFileName(file);
string filePath = "";
if (!fileName1.Contains(snNumber))
{
continue;
}
extensionstr = Path.GetExtension(file);
var datetime = Directory.GetLastWriteTime(file);
monthDay = datetime.ToString("MMdd");
time = datetime.ToString("HHmmss");
fileName = $"{month}{day}_{_stationID}_{result}_{snNumber}_{monthDay}_{time}_{_machineID}_01_Detection_{num}{extensionstr}";
filePath = Path.Combine(sourceFolder, fileName1);
CopyFileToDirectory(filePath, targetFolder, fileName);
@@ -722,7 +755,7 @@ namespace WindowsFormsApp1.server
{
//标记sn的回传状态,以免下次定时器还能查到这种
LogExecute.logNet.WriteDebug($"在所有源文件夹中未找到包含SN号 {snNumber} 的文件");
return ApiFormResult.Error(mesresult.FAIL, false, "", PlcData, DateTime.Now);
return ApiFormResult.Sucess(mesresult.NONE, false, "", PlcData, DateTime.Now);
}
// 组装 request json
@@ -736,7 +769,7 @@ namespace WindowsFormsApp1.server
{
new
{
SN = PlcData.Write_stSN,
SN = snNumber,
FileInfo = fileList.Select(x => new
{
FileName = x,
@@ -747,7 +780,7 @@ namespace WindowsFormsApp1.server
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
};
return CallApi(url, request, "SN_FileUpload", PlcData, PLC_Status.SN_FileUpload);
return CallApi(url, request, "SN_FileUpload", PlcData, 0);
}
catch (Exception ex)
{
@@ -784,7 +817,7 @@ namespace WindowsFormsApp1.server
var result = PlcData.Read_Result == 1 ? "PASS" : "FAIL";
var logresult = PlcData.Read_Result == 1 ? "OK" : "NG";
// 基础请求对象
var request = new CheckOutObject()
{
@@ -852,55 +885,63 @@ namespace WindowsFormsApp1.server
//扭力,角度
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".Contains(stationid))
{
var count = OtherData.FinalAngleValue.Count(x => x > 0);
for (int i = 0; i < count; i++)
{
CsvLogger.Log($"{PlcData.Write_stSN},{OtherData.FinalAngleValue[i]},{OtherData.FinalTorqueValue[i]}");
}
Dictionary<int, int> countDict = new Dictionary<int, int>();
var AngleCount = 1;
foreach (var item in OtherData.FinalAngleValue.Where(x => x > 0))
foreach (var item in OtherData.FinalAngleValue)
{
//角度
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Angle{AngleCount}";
dcInfo.Value = item.ToString();
dcInfo.Result = result;
sninfo.DC_INFO.Add(dcInfo);
AngleCount++;
}
var TorqueCount = 1;
foreach (var item in OtherData.FinalTorqueValue.Where(x => x > 0))
{
//扭力
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Torque{TorqueCount}";
dcInfo.Value = item.ToString();
dcInfo.Result = result;
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
if (item[0] > 0)
{
sn = PlcData.Write_stSN,
CarrierID = PlcData.Read_MaterialCode1,
datacollectionUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyy-MM-dd")
};
materialuploadHelper.Insert(material);
var value = item[3];
if (!countDict.ContainsKey(value))
{
countDict[value] = 1;
}
else
{
countDict[value]++;
}
var scewResult = item[2] == 1 ? "PASS" : "FAIL";
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Angle{item[3]}_{countDict[value]}";
dcInfo.Value = item[1].ToString();
dcInfo.Result = scewResult;
sninfo.DC_INFO.Add(dcInfo);
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Torque{item[3]}_{countDict[value]}";
dcInfo.Value = item[0].ToString();
dcInfo.Result = scewResult;
sninfo.DC_INFO.Add(dcInfo);
CsvLogger.Log($"{PlcData.Write_stSN},{item[1]},{item[0]}");
}
}
else
if (!_isTestMode)
{
material.datacollectionUploaded = 1;
materialuploadHelper.Update(material);
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.Read_MaterialCode1,
datacollectionUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyy-MM-dd"),
outtime = DateTime.Now
};
materialuploadHelper.Insert(material);
}
else
{
material.datacollectionUploaded = 1;
materialuploadHelper.Update(material);
}
}
}
@@ -918,7 +959,7 @@ namespace WindowsFormsApp1.server
}
//LogExecute.SNlogNet.WriteDebug($"追溯码:{PlcData.Read_MaterialCode0},检测结果:{logresult}");
}
//抽真空 压力
if ("Vacuum".Contains(stationid))
{
@@ -941,7 +982,7 @@ namespace WindowsFormsApp1.server
str += $",{dcInfo.Value},";
CsvLogger.Log(str);
}
//固化 时间
if ("Curing".Contains(stationid))
{
@@ -967,6 +1008,12 @@ namespace WindowsFormsApp1.server
Result = result
});
CsvLogger.Log($"{PlcData.Write_stSN},{PlcData.Read_UploadData0.ToString()},{jrTime}");
var jrtime = ((TimeSpan)((material.Data.checkin2 ?? new DateTime()) - (material.Data.checkout1 ?? new DateTime()))).TotalSeconds;
PlcData.Write_ReceiveData0 = (float)jrtime;
var lqtime = ((TimeSpan)((material.Data.checkin3 ?? new DateTime()) - (material.Data.checkout2 ?? new DateTime()))).TotalSeconds;
PlcData.Write_ReceiveData1 = (float)lqtime;
}
else
{
@@ -1027,51 +1074,59 @@ namespace WindowsFormsApp1.server
sninfo.CompList.Add(compListItem);
}
//图片上传
if ("Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5".Contains(stationid))
if (!_isTestMode)
{
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
if (material == null)
//图片上传 Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5
if ("Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5".Contains(stationid))
{
material = new t_materialupload
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
if (material == null)
{
sn = PlcData.Write_stSN,
imageUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyyMMdd")
};
materialuploadHelper.Insert(material);
material = new t_materialupload
{
sn = PlcData.Write_stSN,
imageUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyy-MM-dd"),
outtime = DateTime.Now
};
materialuploadHelper.Insert(material);
}
else
{
material.imageUploaded = 1;
materialuploadHelper.Update(material);
}
}
else
//视频上传 WAT,Assy2,Assy3,ScrewS,Assy5,LoadAging,PrintLabel
if ("WAT,Assy2,Assy3,ScrewS,Assy5,LoadAging,PrintLabel".Contains(stationid))
{
material.imageUploaded = 1;
materialuploadHelper.Update(material);
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,
vedioUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyy-MM-dd"),
outtime = DateTime.Now
};
materialuploadHelper.Insert(material);
}
else
{
material.vedioUploaded = 1;
materialuploadHelper.Update(material);
}
}
}
//视频上传
if ("WAT,Assy2,Assy3,ScrewS,Assy5,LoadAging,PrintLabel".Contains(stationid))
{
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,
vedioUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyy-MM-dd")
};
materialuploadHelper.Insert(material);
}
else
{
material.vedioUploaded = 1;
materialuploadHelper.Update(material);
}
}
//调用OEEDataCollection
//CallFunctionByName("OEEDataCollection", PlcData, OtherData);
return CallApi(url, request, "SN_Checkout", PlcData, PLC_Status.SN_Checkout);
}
@@ -1137,8 +1192,9 @@ namespace WindowsFormsApp1.server
}
}
return CallApi(url, request, "OEEDataCollection", PlcData, PLC_Status.OEEDataCollection);
return CallApi(url, request, "OEEDataCollection", PlcData, 0);
}
#region 暂时不用
public ApiFormResult Test(string url, plcdata PlcData, otherdata OtherData)
{
@@ -1228,7 +1284,7 @@ namespace WindowsFormsApp1.server
try
{
// 打印调用开始日志
LogExecute.logNet.WriteDebug($"开始调用API: {functionName}...");
//LogExecute.logNet.WriteDebug($"开始调用API: {functionName}...");
// 检查API URL是否存在
if (!apiUrlDict.ContainsKey(functionName))
@@ -1240,13 +1296,13 @@ namespace WindowsFormsApp1.server
// 使用同步方法调用API,并结合重试策略
var result = retryPolicy.Execute(() =>
{
LogExecute.logNet.WriteDebug($"正在尝试调用API: {functionName}...");
//LogExecute.logNet.WriteDebug($"正在尝试调用API: {functionName}...");
// 调用该方法
return (ApiFormResult)methodInfo.Invoke(this, new object[] { apiUrlDict[functionName], plcdata, otherdata });
});
// 打印调用结束日志
LogExecute.logNet.WriteDebug($"API调用成功: {functionName}");
//LogExecute.logNet.WriteDebug($"API调用成功: {functionName}");
return result;
}
catch (Exception ex)
@@ -1257,6 +1313,7 @@ namespace WindowsFormsApp1.server
}
}
#region 辅助实体类
/// <summary>
/// checkout dcinfo item
/// </summary>
@@ -1328,10 +1385,10 @@ namespace WindowsFormsApp1.server
};
}
#endregion
#region checkout class
// 根对象类
public class CheckOutObject
// 根对象类
public class CheckOutObject
{
public List<SNInfoItem> SNInfo { get; set; }
public string Qty { get; set; }
@@ -1424,7 +1481,9 @@ namespace WindowsFormsApp1.server
public double angle { get; set; }
}
#endregion 马头扭力角度数据 类
#endregion 辅助实体类
// 文件copy方法
public bool CopyFileToDirectory(string sourceFilePath, string targetDirectory, string fileName)
{
@@ -1439,7 +1498,11 @@ namespace WindowsFormsApp1.server
{
Directory.CreateDirectory(targetDirectory);
}
// 判断是否重复上传
if (Directory.GetFiles(targetDirectory).Any(x => x.Contains(fileName)))
{
return true;
}
string targetPath = Path.Combine(targetDirectory, fileName);
try
+1 -1
View File
@@ -13,7 +13,7 @@ namespace WindowsFormsApp1.server
public static ILogNet PlclogNet = new LogNetDateTime("C:\\Log\\PlcLogs", GenerateMode.ByEveryDay);
public static ILogNet ApilogNet = new LogNetDateTime("C:\\Log\\Apilogs", GenerateMode.ByEveryHour);
public static ILogNet SNlogNet = new LogNetDateTime("C:\\Log\\SNlogs", GenerateMode.ByEveryDay);
public static ILogNet OEElogNet = new LogNetDateTime("C:\\Log\\Apilogs", GenerateMode.ByEveryDay);
public static ILogNet OEElogNet = new LogNetDateTime("C:\\Log\\OEElogs", GenerateMode.ByEveryDay);
public static HslCommunication.BasicFramework.SoftNumericalOrder softNumericalOrder = new HslCommunication.BasicFramework.SoftNumericalOrder("", "yyyyMMdd", 4, @"\numericalOrder.txt");
+53 -5
View File
@@ -280,6 +280,10 @@ namespace WindowsFormsApp1.server
.ToArray());
break;
case "dtl":
address[i].value = GetDTLTime(read.Content, index).ToString();
break;
default:
return BllResult.Error("找不到未知的数据类型");
}
@@ -359,6 +363,12 @@ namespace WindowsFormsApp1.server
stringBytes.CopyTo(writebyte, index);
break;
case "dtl":
DateTime totime = Convert.ToDateTime(value);
byte[] totime_byte = GetBytesFromDTLTime(totime);
totime_byte.CopyTo(writebyte, index);
break;
default:
return BllResult.Error("找不到未知的数据类型");
}
@@ -477,7 +487,7 @@ namespace WindowsFormsApp1.server
#endregion
#region 读取角度
public BllResult<List<float>> ReadAddress(List<t_angleaddress> address)
public BllResult<List<dynamic>> ReadAddress(List<t_angleaddress> address)
{
var ulist = address.GroupBy(a => a.dbaddress).ToList();
foreach (var u in ulist)
@@ -485,15 +495,18 @@ namespace WindowsFormsApp1.server
var readresult = ReadOneDB(u.ToList());
if (!readresult.Success)
{
return BllResult<List<float>>.Error(readresult.Msg);
return BllResult<List<dynamic>>.Error(readresult.Msg);
}
}
List<float> list = new List<float>();
List<dynamic> list = new List<dynamic>();
foreach (var add in address.OrderBy(a => a.addressoffset))
{
list.Add(float.Parse(add.value));
if(add.addresstype == "real")
list.Add(float.Parse(add.value));
else
list.Add(short.Parse(add.value));
}
return BllResult<List<float>>.Sucess(list, "成功");
return BllResult<List<dynamic>>.Sucess(list, "成功");
}
private BllResult ReadOneDB(List<t_angleaddress> address)
{
@@ -803,5 +816,40 @@ namespace WindowsFormsApp1.server
#endregion
#region
public byte[] GetBytesFromDTLTime(DateTime dateTime)
{
byte[] array = new byte[12];
ByteTransform.TransByte((short)dateTime.Year).CopyTo(array, 0);
array[2] = (byte)dateTime.Month;
array[3] = (byte)dateTime.Day;
array[4] = 5;
array[5] = (byte)dateTime.Hour;
array[6] = (byte)dateTime.Minute;
array[7] = (byte)dateTime.Second;
ByteTransform.TransByte(dateTime.Millisecond * 1000 * 1000).CopyTo(array, 8);
return array;
}
public DateTime GetDTLTime(byte[] buffer, int index)
{
int year = (int)ByteTransform.TransInt16(buffer, index);
int month = (int)buffer[index + 2];
int day = (int)buffer[index + 3];
int hour = (int)buffer[index + 5];
int minute = (int)buffer[index + 6];
int second = (int)buffer[index + 7];
int millisecond = ByteTransform.TransInt32(buffer, index + 8) / 1000 / 1000;
if (year == 0 && month == 0 && day == 0)
{
year = 1900;
month = 1;
day = 1;
}
return new DateTime(year, month, day, hour, minute, second, millisecond);
}
#endregion
}
}
+9 -3
View File
@@ -7,10 +7,16 @@ using System.Threading.Tasks;
namespace WindowsFormsApp1.server
{
public class ThreadHelp
public class ThreadHelp :IDisposable
{
public Thread Thread { get; set; }
public bool isrunning1 = false;
public CancellationTokenSource cancellationTokenSource1;
public bool isrunning1 {get;set;}= false;
public CancellationTokenSource cancellationTokenSource1{get;set;}
public void Dispose()
{
cancellationTokenSource1?.Cancel();
cancellationTokenSource1?.Dispose();
Thread = null;
}
}
}