更改大部分页面,更改各个扫码逻辑

This commit is contained in:
bnala committed 2025-03-24 23:35:51 +08:00
1 parent 2bd24f5316
commit 1670395816
34 files changed
+2420 -1425

No files matched your search

+190 -63
View File
@@ -27,9 +27,6 @@ namespace WindowsFormsApp1
{
public partial class MainForm : Form
{
//private Thread thread_plc1;
//private Thread thread_plc2;
public MainForm()
{
InitializeComponent();
@@ -44,10 +41,19 @@ namespace WindowsFormsApp1
FormRecover();
线别.Text = "线别:" + Init.t_Line.linename;
段别.Text = "段别:" + Init.t_Line.linemode;
机台编号.Text = "机台编号:" + Init.t_Line.linecode;
操作人员ID.Text = "操作人员ID:" + Init.t_User.username;
linename.Text = Init.t_Line.linename;
linecode.Text = Init.t_Line.linecode;
linetype.Text = Init.t_Line.linetype;
linemode.Text = Init.t_Line.linemode;
lineremark1.Text = Init.t_Line.lineremark1;
lineremark2.Text = Init.t_Line.lineremark2;
lineremark3.Text = Init.t_Line.lineremark3;
lineremark4.Text = Init.t_Line.lineremark4;
lineremark5.Text = Init.t_Line.lineremark5;
lineremark6.Text = Init.t_Line.lineremark6;
lineremark7.Text = Init.t_Line.lineremark7;
操作人员ID.Text = Init.t_User.username;
}
@@ -62,6 +68,7 @@ namespace WindowsFormsApp1
break;
}
ChangeBarcode();
if (Plc == null)
{
@@ -74,8 +81,9 @@ namespace WindowsFormsApp1
var openresult = siemensHelp.OpenConn();
if (!openresult.Success)
{
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
PLC_Form(Plc, plcstate.NG, DateTime.Now);
LogExecute.logNet.WriteError($"{Plc.plcip}建立S7连接失败");
continue;
}
@@ -83,15 +91,16 @@ namespace WindowsFormsApp1
List<t_plcaddress> plcaddress = Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id);
List<t_angleaddress> angleaddress = Init.t_Angleaddresses.FindAll(a => a.plcid == Plc.id);
List<t_torqueaddress> torqueaddress = Init.t_Torqueaddresses.FindAll(a => a.plcid == Plc.id);
List<t_pressurecurve> pressurecurveaddress = Init.t_Pressurecurves.FindAll(a => a.plcid == Plc.id);
plcdata PlcData = new plcdata();
var resdresult = siemensHelp.ReadAddress(plcaddress, PlcData);
if (!resdresult.Success)
{
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
PLC_Form(Plc, plcstate.NG, DateTime.Now);
LogExecute.logNet.WriteError($"{Plc.plcip}读取全部地址处理错误:处理停止");
continue;
}
@@ -101,17 +110,19 @@ namespace WindowsFormsApp1
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!haertresult.Success)
{
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
PLC_Form(Plc, plcstate.NG, DateTime.Now);
LogExecute.logNet.WriteError($"{Plc.plcip}写入心跳错误:处理停止");
continue;
}
DateTime Plc_Time = DateTime.Now;
PLC链接状态.Text = "PLC链接状态:OK";
PLC链接状态.BackColor = SystemColors.Control;
PLC通讯时间.Text = "PLC通讯时间:" + Plc_Time.ToString("MM-dd HH:mm:ss");
//PLC链接状态.Text = "PLC链接状态:OK";
//PLC链接状态.BackColor = SystemColors.Control;
//PLC通讯时间.Text = "PLC通讯时间:" + Plc_Time.ToString("MM-dd HH:mm:ss");
PLC_Form(Plc, plcstate.OK, Plc_Time);
#endregion
ApiClient apiClient = new ApiClient();
@@ -119,7 +130,7 @@ namespace WindowsFormsApp1
#region 机台状态及报警
//机台状态
机台状态.Text = "机台状态:" + Enum.GetName(typeof(plcstatus), Init.Plcstatus);
//机台状态.Text = "机台状态:" + Enum.GetName(typeof(plcstatus), Init.Plcstatus);
int oldstatus = Init.Plcstatus;
if (PlcData.Read_Status != 0)
{
@@ -159,7 +170,7 @@ namespace WindowsFormsApp1
//机台报警
if (PlcData.Read_Status == (short)plcstatus.停机)
{
机台状态.BackColor = Color.Red;
//机台状态.BackColor = Color.Red;
if (oldstatus != (short)plcstatus.停机)
{
//反馈报警
@@ -196,7 +207,7 @@ namespace WindowsFormsApp1
}
else
{
机台状态.BackColor = SystemColors.Control;
//机台状态.BackColor = SystemColors.Control;
}
#endregion
#region 判断及查找流程
@@ -214,8 +225,9 @@ namespace WindowsFormsApp1
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!writeresult.Success)
{
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
PLC_Form(Plc, plcstate.NG, DateTime.Now);
LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止");
}
continue;
@@ -254,9 +266,36 @@ namespace WindowsFormsApp1
continue;
}
}
if (nowflow.dzscan)
{
//扫码
ScanForm_DZ scanForm = new ScanForm_DZ();
DialogResult scan_result = scanForm.ShowDialog();
if (scan_result == DialogResult.OK)
{
string returnValue = scanForm.ReturnValue;
otherdata.JS_SN = returnValue;
Init.ScanString = returnValue;
}
else
{
continue;
}
}
if (nowflow.finalpressurecurve)
{
//压力曲线
var pressurecurveaddress_result = siemensHelp.ReadAddress(pressurecurveaddress);
if (!pressurecurveaddress_result.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
PLC_Form(Plc, plcstate.NG, DateTime.Now);
LogExecute.logNet.WriteError($"{Plc.plcip}压力曲线数据地址处理错误:处理停止");
continue;
}
otherdata.FinalPressureCurve = pressurecurveaddress_result.Data;
}
//if (nowflow.finaltorquecurve)
//{
@@ -268,8 +307,9 @@ namespace WindowsFormsApp1
var finaltorquevalue_result = siemensHelp.ReadAddress(torqueaddress);
if (!finaltorquevalue_result.Success)
{
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
PLC_Form(Plc, plcstate.NG, DateTime.Now);
LogExecute.logNet.WriteError($"{Plc.plcip}螺丝枪扭力数据地址处理错误:处理停止");
continue;
}
@@ -286,8 +326,9 @@ namespace WindowsFormsApp1
var finalanglevaluue_result = siemensHelp.ReadAddress(angleaddress);
if (!finalanglevaluue_result.Success)
{
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
PLC_Form(Plc, plcstate.NG, DateTime.Now);
LogExecute.logNet.WriteError($"{Plc.plcip}螺丝枪角度数据地址处理错误:处理停止");
continue;
}
@@ -301,13 +342,20 @@ namespace WindowsFormsApp1
#region 调用后端接口
var result = apiClient.CallFunctionByName(nowinterface.code, PlcData, otherdata);
if (result.IsShow)
{
MES提示信息.Visible = true;
MES提示信息.Text = DateTime.Now.ToString("HH:mm:ss") + ":" + result.Msg;
}
if (result.Success)
{
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!writeresult.Success)
{
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
PLC_Form(Plc, plcstate.NG, DateTime.Now);
LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止");
continue;
}
@@ -347,20 +395,27 @@ namespace WindowsFormsApp1
}
#region 开始及结束处理按钮
private void 开始处理_Click(object sender, EventArgs e)
{
if (开始处理.Text == "开始处理")
{
SQLiteHelper<t_plc> sQLiteHelper_plc = new db.SQLiteHelper<t_plc>();
var plc_sqlresult = sQLiteHelper_plc.QueryAll();
var plc_sqlresult = sQLiteHelper_plc.QuerySingle(a=>a.id == Init.t_Line.plcid);
if (!plc_sqlresult.Success)
{
MessageBox.Show("无法初始化PLC信息,无法开始处理!");
return;
}
var plc_result = plc_sqlresult.Data.FindAll(a => Init.t_Lineplcs.Select(p => p.plcid).Contains(a.id));
SQLiteHelper<t_keyvalue> sQLiteHelper_key = new db.SQLiteHelper<t_keyvalue>();
var key_sqlresult = sQLiteHelper_key.QueryAll();
if (!key_sqlresult.Success)
{
MessageBox.Show("无法初始化信息信息,无法开始处理!");
return;
}
SQLiteHelper<t_flow> sQLiteHelper_flow = new db.SQLiteHelper<t_flow>();
var flow_result = sQLiteHelper_flow.Query(a => a.flowid == Init.t_Line.flowid);
@@ -394,6 +449,14 @@ namespace WindowsFormsApp1
return;
}
SQLiteHelper<t_pressurecurve> sQLiteHelper_pressurecurve = new db.SQLiteHelper<t_pressurecurve>();
var pressurecurve_result = sQLiteHelper_pressurecurve.QueryAll();
if (!pressurecurve_result.Success)
{
MessageBox.Show("无法初始化压力曲线信息,无法开始处理!");
return;
}
SQLiteHelper<t_interface> sQLiteHelper_interface = new db.SQLiteHelper<t_interface>();
var interface_result = sQLiteHelper_interface.QueryAll();
if (!interface_result.Success)
@@ -418,7 +481,9 @@ namespace WindowsFormsApp1
Init.t_Plcaddresses = address_result.Data;
Init.t_Angleaddresses = angleaddress_result.Data;
Init.t_Torqueaddresses = torqueaddress_result.Data;
Init.t_Pressurecurves = pressurecurve_result.Data;
Init.t_Interfaces = interface_result.Data;
Init.t_Keyvalues = key_sqlresult.Data;
#endregion
#region 初始化COM口服务
try
@@ -463,6 +528,8 @@ namespace WindowsFormsApp1
底部注释2.Text = "气密仪COM-Ready";
底部注释2.Visible = true;
}
胶水上下线.Enabled = true;
}
}
}
@@ -474,19 +541,17 @@ namespace WindowsFormsApp1
#endregion
Init.threadHelps = new List<ThreadHelp>();
foreach (var plc in plc_result)
var plc = plc_sqlresult.Data;
plc.plchelp = new SiemensHelp(plc.plcip, plc.timeout);
ThreadHelp threadHelp = new ThreadHelp();
if (!threadHelp.isrunning1)
{
plc.plchelp = new SiemensHelp(plc.plcip, plc.timeout);
ThreadHelp threadHelp = new ThreadHelp();
if (!threadHelp.isrunning1)
{
threadHelp.cancellationTokenSource1 = new CancellationTokenSource();
threadHelp.Thread = new Thread(() => build(plc, threadHelp.cancellationTokenSource1.Token));
threadHelp.Thread.Start();
threadHelp.isrunning1 = true;
}
Init.threadHelps.Add(threadHelp);
threadHelp.cancellationTokenSource1 = new CancellationTokenSource();
threadHelp.Thread = new Thread(() => build(plc, threadHelp.cancellationTokenSource1.Token));
threadHelp.Thread.Start();
threadHelp.isrunning1 = true;
}
Init.threadHelps.Add(threadHelp);
开始处理.Text = "停止处理";
开始处理.BackColor = Color.Red;
@@ -546,12 +611,6 @@ namespace WindowsFormsApp1
lINE_Manage.ShowDialog();
}
private void 产线关联PLC管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
LinePLC_Manage lINEPLC_Manage = new LinePLC_Manage();
lINEPLC_Manage.ShowDialog();
}
private void 系统参数配置ToolStripMenuItem_Click(object sender, EventArgs e)
{
KeyValue keyValue = new KeyValue();
@@ -656,16 +715,15 @@ namespace WindowsFormsApp1
MES通讯时间.Text = "MES通讯时间:None";
MES通讯时间.BackColor = SystemColors.Control;
PLC链接状态.Text = "PLC链接状态:None";
PLC链接状态.BackColor = SystemColors.Control;
PLC1名称.Visible = false;
PLC通讯时间.Text = "PLC通讯时间:None";
PLC通讯时间.BackColor = SystemColors.Control;
PLC1状态.Visible = false;
机台状态.Text = "机台状态:None";
机台状态.BackColor = SystemColors.Control;
PLC1机台状态.Visible = false;
胶水上下线.Enabled = false;
PLC1时间.Visible = false;
//胶水上下线.Enabled = false;
MES提示信息.Visible = false;
LOT号.Visible = false;
@@ -693,6 +751,83 @@ namespace WindowsFormsApp1
底部注释4.Visible = false;
底部注释5.Visible = false;
剩余寿命.Visible = false;
barcode1.Visible = false;
barcode2.Visible = false;
barcode3.Visible = false;
barcode4.Visible = false;
barcode5.Visible = false;
barcode6.Visible = false;
barcode7.Visible = false;
barcode8.Visible = false;
barcode9.Visible = false;
}
public void ChangeBarcode()
{
剩余寿命.Visible = true;
barcode1.Visible = true;
barcode2.Visible = true;
barcode3.Visible = true;
barcode4.Visible = true;
barcode5.Visible = true;
barcode6.Visible = true;
barcode7.Visible = true;
barcode8.Visible = true;
barcode9.Visible = true;
var power = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Power");
var i_barcode1 = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode1");
var i_barcode2 = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode2");
var i_barcode3 = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode3");
var i_barcode4 = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode4");
var i_barcode5 = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode5");
var i_barcode6 = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode6");
var i_barcode7 = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode7");
var i_barcode8 = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode8");
var i_barcode9 = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode9");
剩余寿命.Text = power == null ? "": power.value;
barcode1.Text = i_barcode1 == null ? "":i_barcode1.value;
barcode2.Text = i_barcode2 == null ? "":i_barcode2.value;
barcode3.Text = i_barcode3 == null ? "":i_barcode3.value;
barcode4.Text = i_barcode4 == null ? "":i_barcode4.value;
barcode5.Text = i_barcode5 == null ? "":i_barcode5.value;
barcode6.Text = i_barcode6 == null ? "":i_barcode6.value;
barcode7.Text = i_barcode7 == null ? "":i_barcode7.value;
barcode8.Text = i_barcode8 == null ? "":i_barcode8.value;
barcode9.Text = i_barcode9 == null ? "":i_barcode9.value;
}
public void PLC_Form(t_plc plc, plcstate state, DateTime time)
{
string plcname = plc.plcname + ":" + plc.plcip;
string datetime = time.ToString("HH:mm:ss");
PLC1名称.Visible = true;
PLC1状态.Visible = true;
PLC1机台状态.Visible = true;
PLC1时间.Visible = true;
PLC1名称.Text = plcname;
PLC1状态.Text = state.ToString();
PLC1机台状态.Text = Enum.GetName(typeof(plcstatus), Init.Plcstatus);
PLC1时间.Text = datetime;
if (PLC1状态.Text == plcstate.NG.ToString())
{
PLC1状态.BackColor = Color.Red;
}
else
{
PLC1状态.BackColor = SystemColors.Control;
}
if (PLC1机台状态.Text == plcstatus.停机.ToString())
{
PLC1机台状态.BackColor = Color.Red;
}
else
{
PLC1机台状态.BackColor = SystemColors.Control;
}
}
public void MES_MsgfORM(string name, mesresult result, DateTime dateTime)
@@ -808,14 +943,8 @@ namespace WindowsFormsApp1
#region 其他业务处理
private void 胶水上下线_Click(object sender, EventArgs e)
{
ScanForm scanForm = new ScanForm();
ScanForm_SSQ scanForm = new ScanForm_SSQ();
DialogResult result = scanForm.ShowDialog();
if (result == DialogResult.OK)
{
string returnValue = scanForm.ReturnValue;
MessageBox.Show($"返回值是:{returnValue}");
//调用三防漆之类的接口
}
}
public void AirtightPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
@@ -896,8 +1025,6 @@ namespace WindowsFormsApp1
LogExecute.logNet.WriteError($"通过气密仪获取到压力参数失败,错误原因{ex.Message}");
}
}
#endregion