25110601 没加华勤MES前

This commit is contained in:
moxiliang
2025-11-06 13:42:42 +08:00
parent 465daa14c4
commit 4eece9db0b
31 changed files with 541 additions and 363 deletions

View File

@@ -101,13 +101,13 @@ namespace SLC1_N
//Control.CheckForIllegalCrossThreadCalls = true;
// 界面初始化
lb_CH1Code.Text = "";
lb_CH2Code.Text = "";
tb_CH1Code.Text = "";
tb_CH2Code.Text = "";
lb_CH1_Result.Text = " ";
lb_CH2_Result.Text = " ";
lb_CH3Code.Text = "";
lb_CH4Code.Text = "";
tb_CH3Code.Text = "";
tb_CH4Code.Text = "";
lb_CH3_Result.Text = " ";
lb_CH4_Result.Text = " ";
@@ -716,7 +716,7 @@ namespace SLC1_N
return;
}
ch1_oldcode = CODE;
lb_CH1Code.Text = CODE;
tb_CH1Code.Text = CODE;
if (MESswitch)
{
@@ -754,7 +754,7 @@ namespace SLC1_N
return;
}
ch2_oldcode = CODE;
lb_CH2Code.Text = CODE;
tb_CH2Code.Text = CODE;
if (MESswitch)
{
@@ -1394,7 +1394,7 @@ namespace SLC1_N
// 表格
DataGridView1.Invoke(new System.Action<int, bool, string>(Display),
1, result, lb_CH1Code.Text);
1, result, tb_CH1Code.Text);
bool testfinish = false; // 测试结束标志位
@@ -1434,12 +1434,12 @@ namespace SLC1_N
UploadProductionData(m_production.GetTotal(), m_production.GetOK(), m_production.GetNG(), m_production.GetOKRate()); // 更新产能
// 文件
CreateFile(1, result, lb_CH1Code.Text);
CreateFile(1, result, tb_CH1Code.Text);
// MES
if (MESswitch)
{
RtValue rdata = chuzhan(1, lb_CH1Code.Text, result);
RtValue rdata = chuzhan(1, tb_CH1Code.Text, result);
if (rdata.result)
{
SetLabelText(lb_CH1MES_OUTstatus, "PASS", Color.Green);
@@ -1468,7 +1468,7 @@ namespace SLC1_N
}
CH1testCount = 0; // 重置测试次数
lb_CH1Code.Text = "";
tb_CH1Code.Text = "";
ch1workstation = (int)yiqi.standby;
}
}
@@ -1694,7 +1694,7 @@ namespace SLC1_N
// 表格
DataGridView2.Invoke(new System.Action<int, bool, string>(Display),
2, result, lb_CH2Code.Text);
2, result, tb_CH2Code.Text);
bool testfinish = false; // 测试结束标志位
@@ -1734,12 +1734,12 @@ namespace SLC1_N
UploadProductionData(m_production.GetTotal(), m_production.GetOK(), m_production.GetNG(), m_production.GetOKRate()); // 更新产能
// 文件
CreateFile(2, result, lb_CH2Code.Text);
CreateFile(2, result, tb_CH2Code.Text);
// MES
if (MESswitch)
{
RtValue rdata = chuzhan(2, lb_CH2Code.Text, result);
RtValue rdata = chuzhan(2, tb_CH2Code.Text, result);
if (rdata.result)
{
SetLabelText(lb_CH2MES_OUTstatus, "PASS", Color.Green);
@@ -1768,7 +1768,7 @@ namespace SLC1_N
}
CH2testCount = 0; // 重置测试次数
lb_CH2Code.Text = "";
tb_CH2Code.Text = "";
ch2workstation = (int)yiqi.standby;
}
}
@@ -1993,7 +1993,7 @@ namespace SLC1_N
// 表格
DataGridView1.Invoke(new System.Action<int, bool, string>(Display),
3, result, lb_CH3Code.Text);
3, result, tb_CH3Code.Text);
bool testfinish = false; // 测试结束标志位
@@ -2033,12 +2033,12 @@ namespace SLC1_N
UploadProductionData(m_production.GetTotal(), m_production.GetOK(), m_production.GetNG(), m_production.GetOKRate()); // 更新产能
// 文件
CreateFile(3, result, lb_CH3Code.Text);
CreateFile(3, result, tb_CH3Code.Text);
// MES
if (MESswitch)
{
RtValue rdata = chuzhan(3, lb_CH3Code.Text, result);
RtValue rdata = chuzhan(3, tb_CH3Code.Text, result);
if (rdata.result)
{
SetLabelText(lb_CH3MES_OUTstatus, "PASS", Color.Green);
@@ -2067,7 +2067,7 @@ namespace SLC1_N
}
CH3testCount = 0; // 重置测试次数
lb_CH3Code.Text = "";
tb_CH3Code.Text = "";
ch3workstation = (int)yiqi.standby;
}
}
@@ -2294,7 +2294,7 @@ namespace SLC1_N
// 表格
DataGridView2.Invoke(new System.Action<int, bool, string>(Display),
4, result, lb_CH4Code.Text);
4, result, tb_CH4Code.Text);
bool testfinish = false; // 测试结束标志位
@@ -2334,12 +2334,12 @@ namespace SLC1_N
UploadProductionData(m_production.GetTotal(), m_production.GetOK(), m_production.GetNG(), m_production.GetOKRate()); // 更新产能
// 文件
CreateFile(4, result, lb_CH4Code.Text);
CreateFile(4, result, tb_CH4Code.Text);
// MES
if (MESswitch)
{
RtValue rdata = chuzhan(4, lb_CH4Code.Text, result);
RtValue rdata = chuzhan(4, tb_CH4Code.Text, result);
if (rdata.result)
{
SetLabelText(lb_CH4MES_OUTstatus, "PASS", Color.Green);
@@ -2368,7 +2368,7 @@ namespace SLC1_N
}
CH4testCount = 0; // 重置测试次数
lb_CH4Code.Text = "";
tb_CH4Code.Text = "";
ch4workstation = (int)yiqi.standby;
}
}
@@ -3966,7 +3966,7 @@ namespace SLC1_N
// 清除条码1
private void button2_Click(object sender, EventArgs e)
{
lb_CH1Code.Text = "";
tb_CH1Code.Text = "";
ch1_oldcode = "";
lb_CH1MES_INstatus.Text = "##";
}
@@ -3974,21 +3974,21 @@ namespace SLC1_N
// 清除条码2
private void button3_Click(object sender, EventArgs e)
{
lb_CH2Code.Text = "";
tb_CH2Code.Text = "";
ch1_oldcode = "";
lb_CH2MES_INstatus.Text = "##";
}
// 清除条码3
private void bt_code3clear_Click(object sender, EventArgs e)
{
lb_CH3Code.Text = "";
tb_CH3Code.Text = "";
ch1_oldcode = "";
lb_CH3MES_INstatus.Text = "##";
}
// 清除条码4
private void bt_code4clear_Click(object sender, EventArgs e)
{
lb_CH4Code.Text = "";
tb_CH4Code.Text = "";
ch1_oldcode = "";
lb_CH4MES_INstatus.Text = "##";
}
@@ -4153,24 +4153,24 @@ namespace SLC1_N
private void UpdateCodeBox(string CODE)
{
// 1-4顺序放
if (string.IsNullOrEmpty(lb_CH1Code.Text))
if (string.IsNullOrEmpty(tb_CH1Code.Text))
{
lb_CH1Code.Text = CODE;
tb_CH1Code.Text = CODE;
lastUseCodebox = 1;
}
else if (string.IsNullOrEmpty(lb_CH2Code.Text))
else if (string.IsNullOrEmpty(tb_CH2Code.Text))
{
lb_CH2Code.Text = CODE;
tb_CH2Code.Text = CODE;
lastUseCodebox = 2;
}
else if (string.IsNullOrEmpty(lb_CH3Code.Text))
else if (string.IsNullOrEmpty(tb_CH3Code.Text))
{
lb_CH3Code.Text = CODE;
tb_CH3Code.Text = CODE;
lastUseCodebox = 3;
}
else if (string.IsNullOrEmpty(lb_CH4Code.Text))
else if (string.IsNullOrEmpty(tb_CH4Code.Text))
{
lb_CH4Code.Text = CODE;
tb_CH4Code.Text = CODE;
lastUseCodebox = 4;
}
else // suoy 所有框都有条码时
@@ -4179,10 +4179,10 @@ namespace SLC1_N
switch (lastUseCodebox)
{
case 1: lb_CH1Code.Text = CODE; break;
case 2: lb_CH2Code.Text = CODE; break;
case 3: lb_CH3Code.Text = CODE; break;
case 4: lb_CH4Code.Text = CODE; break;
case 1: tb_CH1Code.Text = CODE; break;
case 2: tb_CH2Code.Text = CODE; break;
case 3: tb_CH3Code.Text = CODE; break;
case 4: tb_CH4Code.Text = CODE; break;
}
}
}
@@ -4215,7 +4215,7 @@ namespace SLC1_N
return;
lastCode = code; // 保存
if (lb_CH1Code.Text == code || lb_CH2Code.Text == code || lb_CH3Code.Text == code || lb_CH4Code.Text == code)
if (tb_CH1Code.Text == code || tb_CH2Code.Text == code || tb_CH3Code.Text == code || tb_CH4Code.Text == code)
{
//MessageBox.Show($"条码 {CODE} 已存在", "重复提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
@@ -4277,9 +4277,9 @@ namespace SLC1_N
Console.WriteLine("扫码枪2串口收到:" + code);
if (codelen == tb_CH2codeLeng.Text.Trim())
{
if (code != lb_CH2Code.Text)
if (code != tb_CH2Code.Text)
{
lb_CH2Code.Text = code;
tb_CH2Code.Text = code;
SetUITextBox(tb_CH2MainMessage, "CH2扫码完成");
}
else
@@ -4326,7 +4326,7 @@ namespace SLC1_N
//code = code.Split(';')[0];
//Console.WriteLine("扫码枪3串口去掉分隔符:" + code);
if (lb_CH1Code.Text == code || lb_CH2Code.Text == code || lb_CH3Code.Text == code || lb_CH4Code.Text == code)
if (tb_CH1Code.Text == code || tb_CH2Code.Text == code || tb_CH3Code.Text == code || tb_CH4Code.Text == code)
{
//MessageBox.Show($"条码 {CODE} 已存在", "重复提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
SerialPort_CH3Saoma.DiscardInBuffer();
@@ -4335,7 +4335,7 @@ namespace SLC1_N
if (code.Length.ToString() == tb_CH3codeLeng.Text.Trim())
{
lb_CH3Code.Text = code;
tb_CH3Code.Text = code;
}
else
{
@@ -4376,7 +4376,7 @@ namespace SLC1_N
//code = code.Split(';')[0];
//Console.WriteLine("扫码枪4串口去掉分隔符:" + code);
if (lb_CH1Code.Text == code || lb_CH2Code.Text == code || lb_CH3Code.Text == code || lb_CH4Code.Text == code)
if (tb_CH1Code.Text == code || tb_CH2Code.Text == code || tb_CH3Code.Text == code || tb_CH4Code.Text == code)
{
//MessageBox.Show($"条码 {CODE} 已存在", "重复提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
SerialPort_CH4Saoma.DiscardInBuffer();
@@ -4385,7 +4385,7 @@ namespace SLC1_N
if (code.Length.ToString() == tb_CH4codeLeng.Text.Trim())
{
lb_CH4Code.Text = code;
tb_CH4Code.Text = code;
}
else
{
@@ -4409,12 +4409,12 @@ namespace SLC1_N
// 条码变化函数
private void CH1Code_TextChanged(object sender, EventArgs e)
{
if (!lb_CH1Code.Text.IsNullOrEmpty())
if (!tb_CH1Code.Text.IsNullOrEmpty())
{
bool len_bool = lb_CH1Code.Text.Length.ToString() == tb_CH1codeLeng.Text.Trim(); // 长度
bool rep_bool = (lb_CH1Code.Text != lb_CH2Code.Text &&
lb_CH1Code.Text != lb_CH3Code.Text &&
lb_CH1Code.Text != lb_CH4Code.Text); // 重复
bool len_bool = tb_CH1Code.Text.Length.ToString() == tb_CH1codeLeng.Text.Trim(); // 长度
bool rep_bool = (tb_CH1Code.Text != tb_CH2Code.Text &&
tb_CH1Code.Text != tb_CH3Code.Text &&
tb_CH1Code.Text != tb_CH4Code.Text); // 重复
if (len_bool && rep_bool)
{
Console.WriteLine("CH1Code_TextChanged()");
@@ -4426,7 +4426,7 @@ namespace SLC1_N
Task.Run(() =>
{
// MES入站
RtValue ret = ruzhan(1, lb_CH1Code.Text);
RtValue ret = ruzhan(1, tb_CH1Code.Text);
if (ret.result)
{
SetLabelText(lb_CH1MES_INstatus, "PASS", Color.Green);
@@ -4491,22 +4491,22 @@ namespace SLC1_N
else
{
if(!len_bool)
SetUITextBox(tb_CH1MainMessage, $"[CH1]当前条码长度{lb_CH1Code.Text.Length},限定{tb_CH1codeLeng.Text}");
SetUITextBox(tb_CH1MainMessage, $"[CH1]当前条码长度{tb_CH1Code.Text.Length},限定{tb_CH1codeLeng.Text}");
else if(!rep_bool)
SetUITextBox(tb_CH1MainMessage, "[CH1]当前条码重复"); // 看起来条码接收函数处理了,这里不会触发
lb_CH1Code.Text = "";
tb_CH1Code.Text = "";
}
}
}
private void CH2Code_TextChanged(object sender, EventArgs e)
{
if (!lb_CH2Code.Text.IsNullOrEmpty())
if (!tb_CH2Code.Text.IsNullOrEmpty())
{
bool len_bool = lb_CH2Code.Text.Length.ToString() == tb_CH2codeLeng.Text.Trim();
bool rep_bool = (lb_CH2Code.Text != lb_CH1Code.Text &&
lb_CH2Code.Text != lb_CH3Code.Text &&
lb_CH2Code.Text != lb_CH4Code.Text);
bool len_bool = tb_CH2Code.Text.Length.ToString() == tb_CH2codeLeng.Text.Trim();
bool rep_bool = (tb_CH2Code.Text != tb_CH1Code.Text &&
tb_CH2Code.Text != tb_CH3Code.Text &&
tb_CH2Code.Text != tb_CH4Code.Text);
if (len_bool && rep_bool)
{
Console.WriteLine("CH2Code_TextChanged()");
@@ -4518,7 +4518,7 @@ namespace SLC1_N
Task.Run(() =>
{
// MES入站
RtValue ret = ruzhan(2, lb_CH2Code.Text);
RtValue ret = ruzhan(2, tb_CH2Code.Text);
if (ret.result)
{
SetLabelText(lb_CH2MES_INstatus, "PASS", Color.Green);
@@ -4583,10 +4583,10 @@ namespace SLC1_N
else
{
if (!len_bool)
SetUITextBox(tb_CH2MainMessage, $"[CH2]当前条码长度{lb_CH2Code.Text.Length},限定{tb_CH2codeLeng.Text}");
SetUITextBox(tb_CH2MainMessage, $"[CH2]当前条码长度{tb_CH2Code.Text.Length},限定{tb_CH2codeLeng.Text}");
else if (!rep_bool)
SetUITextBox(tb_CH2MainMessage, "[CH2]当前条码重复");
lb_CH2Code.Text = "";
tb_CH2Code.Text = "";
}
}
}
@@ -4594,12 +4594,12 @@ namespace SLC1_N
private void lb_CH3Code_TextChanged(object sender, EventArgs e)
{
if (!lb_CH3Code.Text.IsNullOrEmpty())
if (!tb_CH3Code.Text.IsNullOrEmpty())
{
bool len_bool = lb_CH3Code.Text.Length.ToString() == tb_CH3codeLeng.Text.Trim();
bool rep_bool = (lb_CH3Code.Text != lb_CH1Code.Text &&
lb_CH3Code.Text != lb_CH2Code.Text &&
lb_CH3Code.Text != lb_CH4Code.Text);
bool len_bool = tb_CH3Code.Text.Length.ToString() == tb_CH3codeLeng.Text.Trim();
bool rep_bool = (tb_CH3Code.Text != tb_CH1Code.Text &&
tb_CH3Code.Text != tb_CH2Code.Text &&
tb_CH3Code.Text != tb_CH4Code.Text);
if (len_bool && rep_bool)
{
Console.WriteLine("CH3Code_TextChanged()");
@@ -4611,7 +4611,7 @@ namespace SLC1_N
Task.Run(() =>
{
// MES入站
RtValue ret = ruzhan(3, lb_CH3Code.Text);
RtValue ret = ruzhan(3, tb_CH3Code.Text);
if (ret.result)
{
SetLabelText(lb_CH3MES_INstatus, "PASS", Color.Green);
@@ -4676,22 +4676,22 @@ namespace SLC1_N
else
{
if (!len_bool)
SetUITextBox(tb_CH1MainMessage, $"[CH3]当前条码长度{lb_CH3Code.Text.Length},限定{tb_CH3codeLeng.Text}");
SetUITextBox(tb_CH1MainMessage, $"[CH3]当前条码长度{tb_CH3Code.Text.Length},限定{tb_CH3codeLeng.Text}");
else if (!rep_bool)
SetUITextBox(tb_CH1MainMessage, "[CH3]当前条码重复");
lb_CH3Code.Text = "";
tb_CH3Code.Text = "";
}
}
}
private void lb_CH4Code_TextChanged(object sender, EventArgs e)
{
if (!lb_CH4Code.Text.IsNullOrEmpty())
if (!tb_CH4Code.Text.IsNullOrEmpty())
{
bool len_bool = lb_CH4Code.Text.Length.ToString() == tb_CH4codeLeng.Text.Trim();
bool rep_bool = (lb_CH4Code.Text != lb_CH1Code.Text &&
lb_CH4Code.Text != lb_CH2Code.Text &&
lb_CH4Code.Text != lb_CH3Code.Text);
bool len_bool = tb_CH4Code.Text.Length.ToString() == tb_CH4codeLeng.Text.Trim();
bool rep_bool = (tb_CH4Code.Text != tb_CH1Code.Text &&
tb_CH4Code.Text != tb_CH2Code.Text &&
tb_CH4Code.Text != tb_CH3Code.Text);
if (len_bool && rep_bool)
{
Console.WriteLine("CH4Code_TextChanged()");
@@ -4703,7 +4703,7 @@ namespace SLC1_N
Task.Run(() =>
{
// MES入站
RtValue ret = ruzhan(4, lb_CH4Code.Text);
RtValue ret = ruzhan(4, tb_CH4Code.Text);
if (ret.result)
{
SetLabelText(lb_CH4MES_INstatus, "PASS", Color.Green);
@@ -4768,10 +4768,10 @@ namespace SLC1_N
else
{
if (!len_bool)
SetUITextBox(tb_CH2MainMessage, $"[CH4]当前条码长度{lb_CH4Code.Text.Length},限定{tb_CH4codeLeng.Text}");
SetUITextBox(tb_CH2MainMessage, $"[CH4]当前条码长度{tb_CH4Code.Text.Length},限定{tb_CH4codeLeng.Text}");
else if (!rep_bool)
SetUITextBox(tb_CH2MainMessage, "[CH4]当前条码重复");
lb_CH4Code.Text = "";
tb_CH4Code.Text = "";
}
}
}
@@ -5248,5 +5248,70 @@ namespace SLC1_N
OpenForm(elec, true);
}
}
#region USB扫码
private StringBuilder codeBuff = new StringBuilder();
private DateTime lastKeyTime = DateTime.Now;
private readonly int timeoutMs = 300;
private bool monitorAllInput = false;
private void tb_CHxCode_KeyPress(object sender, KeyPressEventArgs e)
{
if (monitorAllInput || sender is Sunny.UI.UITextBox)
{
ProcessKeyPress(e.KeyChar);
e.Handled = true; // 阻止字符显示
}
}
// 条码字符处理
private void ProcessKeyPress(char keyChar)
{
TimeSpan elapsed = DateTime.Now - lastKeyTime;
if (elapsed.TotalMilliseconds > timeoutMs)
{
codeBuff.Clear();
}
lastKeyTime = DateTime.Now;
if (keyChar == '\r' || keyChar == '\n')
{
string barcode = codeBuff.ToString().Trim();
if (!string.IsNullOrEmpty(barcode))
{
UpdateCodeBox(barcode);
}
codeBuff.Clear();
}
else
{
codeBuff.Append(keyChar);
}
}
// 主窗口的KeyPreview设置为true重写函数捕获所有键盘输入勿删没有引用但是运行会调用
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (monitorAllInput)
{
ProcessKeyPress(e.KeyChar);
e.Handled = true; // 阻止进一步处理
}
base.OnKeyPress(e); // 调用基类实现,确保其他功能正常
}
// 专注扫码复选框
private void chk_SaomaFocus_CheckedChanged(object sender, EventArgs e)
{
monitorAllInput = chk_SaomaFocus.Checked;
if (monitorAllInput)
{
// 监控所有输入时,让文本框获取焦点以便接收键盘事件
this.Focus();
}
}
#endregion
}
}