Compare commits
2 Commits
1444e6b948
...
2c0e5217bc
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c0e5217bc | |||
| f7cb1c10a5 |
@@ -29,7 +29,9 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
using Excel = Microsoft.Office.Interop.Excel;
|
||||
using Timer = System.Windows.Forms.Timer;
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
//using Timer = System.Windows.Forms.Timer;
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
using System.Timers;
|
||||
namespace 精工涂胶检测项目
|
||||
{
|
||||
@@ -108,13 +110,25 @@ namespace 精工涂胶检测项目
|
||||
CogPMAlignTool mPM;
|
||||
CogFixtureTool mFIX;
|
||||
int currentStatus;
|
||||
private Timer inactivityTimer;
|
||||
#region ≡≡≡≡≡≡≡≡≡≡【inactivityTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【0】【BEGIN】
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
//private Timer inactivityTimer;
|
||||
private System.Timers.Timer mInactivityTimer;
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
#endregion ≡≡≡≡≡≡≡≡≡≡【inactivityTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【0】【END】
|
||||
|
||||
FormLogin formLogin;
|
||||
private MyMessageFilter messageFilter;
|
||||
public ModbusTcpClient modbusClient; // 新增Modbus客户端实例
|
||||
private Timer modbusPollTimer; // 新增轮询定时器
|
||||
private Timer modbusHeartbeat;
|
||||
|
||||
#region ≡≡≡≡≡≡≡≡≡≡【modbusPollTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【0】【BEGIN】
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
//private Timer modbusPollTimer; // 新增轮询定时器
|
||||
private System.Timers.Timer mModbusPollTimer;
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
#endregion ≡≡≡≡≡≡≡≡≡≡【modbusPollTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【0】【END】
|
||||
|
||||
private System.Timers.Timer modbusHeartbeat;
|
||||
public Plc plc;
|
||||
|
||||
public bool _autoModbusReconnect = true;
|
||||
@@ -221,20 +235,32 @@ namespace 精工涂胶检测项目
|
||||
{
|
||||
if (modbusHeartbeat == null)
|
||||
{
|
||||
modbusHeartbeat = new Timer { Interval = 500 };
|
||||
modbusHeartbeat.Tick += async (s, e) =>
|
||||
modbusHeartbeat = new System.Timers.Timer { Interval = 500 };
|
||||
modbusHeartbeat.AutoReset = true;
|
||||
modbusHeartbeat.SynchronizingObject = null;
|
||||
modbusHeartbeat.Elapsed += async (s, e) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
modbusClient.WriteSingleRegister("0", 1);
|
||||
Thread.Sleep(50);
|
||||
await Task.Delay(50);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"Modbus心跳失败:{ex.Message}", 2);
|
||||
}
|
||||
};
|
||||
modbusHeartbeat.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void StopHeartBeat()
|
||||
{
|
||||
if (modbusHeartbeat == null && modbusHeartbeat.Enabled)
|
||||
if (modbusHeartbeat != null)
|
||||
{
|
||||
modbusHeartbeat.Stop();
|
||||
modbusHeartbeat.Dispose();
|
||||
modbusHeartbeat = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,6 +328,8 @@ namespace 精工涂胶检测项目
|
||||
// 再次回收(清理等待终结后的对象)
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
#region ≡≡≡≡≡≡≡≡≡≡【modbusPollTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【1】【BEGIN】
|
||||
private void StartModbusPolling()
|
||||
{ // 创建定时器:3000 毫秒 = 3 秒
|
||||
_gcTimer = new System.Timers.Timer(3000);
|
||||
@@ -314,11 +342,19 @@ namespace 精工涂胶检测项目
|
||||
|
||||
// 启动定时器
|
||||
_gcTimer.Start();
|
||||
if (modbusPollTimer == null)
|
||||
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
//if (modbusPollTimer == null)
|
||||
if (mModbusPollTimer == null)
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
{
|
||||
Vpro初始化();
|
||||
modbusPollTimer = new Timer { Interval = 1000 };
|
||||
modbusPollTimer.Tick += async (s, e) =>
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
//modbusPollTimer = new Timer { Interval = 1000 };
|
||||
//modbusPollTimer.Tick += async (s, e) =>
|
||||
mModbusPollTimer = new System.Timers.Timer(1000);
|
||||
mModbusPollTimer.Elapsed += async (s, e) =>
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
{
|
||||
if (!modbusClient.IsConnected) return;
|
||||
|
||||
@@ -357,7 +393,6 @@ namespace 精工涂胶检测项目
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (trigger == "\u0000" || trigger == "")
|
||||
{
|
||||
AddLog("相机收到PLC结束触发信号", 0);
|
||||
@@ -365,7 +400,6 @@ namespace 精工涂胶检测项目
|
||||
AddLog("给PLC发送ResultAcq置零信号", 0);
|
||||
}
|
||||
|
||||
|
||||
//触发标定程序
|
||||
if (trigger == "\u0002")
|
||||
{
|
||||
@@ -381,8 +415,6 @@ namespace 精工涂胶检测项目
|
||||
cog3DDisplayV2WF1.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (resultHeartBeat.IsSuccess)
|
||||
@@ -424,12 +456,23 @@ namespace 精工涂胶检测项目
|
||||
};
|
||||
}
|
||||
|
||||
if (!modbusPollTimer.Enabled)
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
//if (!modbusPollTimer.Enabled)
|
||||
//{
|
||||
// modbusPollTimer.Start();
|
||||
// AddLog("Modbus实时读取已启动", 0);
|
||||
//}
|
||||
|
||||
if (!mModbusPollTimer.Enabled)
|
||||
{
|
||||
modbusPollTimer.Start();
|
||||
mModbusPollTimer.Start();
|
||||
AddLog("Modbus实时读取已启动", 0);
|
||||
}
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
}
|
||||
#endregion ≡≡≡≡≡≡≡≡≡≡【modbusPollTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【1】【END】
|
||||
|
||||
|
||||
public string ConvertShortsToAsciiString(short[] shorts, bool isLittleEndian = false)
|
||||
{
|
||||
var bytes = new List<byte>();
|
||||
@@ -468,18 +511,30 @@ namespace 精工涂胶检测项目
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region ≡≡≡≡≡≡≡≡≡≡【inactivityTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【1】【BEGIN】
|
||||
private void 计时器初始化()
|
||||
{
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
// 初始化不活动计时器
|
||||
// 初始化不活动计时器
|
||||
inactivityTimer = new Timer();
|
||||
inactivityTimer.Interval = 300000; // 5秒
|
||||
inactivityTimer.Tick += InactivityTimer_Tick;
|
||||
//inactivityTimer = new Timer();
|
||||
//inactivityTimer.Interval = 300000; // 5秒【这是5秒为啥写300秒,到底是多少】
|
||||
//inactivityTimer.Tick += InactivityTimer_Tick;
|
||||
|
||||
mInactivityTimer = new System.Timers.Timer(5000); //5秒
|
||||
mInactivityTimer.Elapsed += InactivityTimer_Elapsed;
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
|
||||
// 初始化消息过滤器
|
||||
messageFilter = new MyMessageFilter();
|
||||
Application.AddMessageFilter(messageFilter);
|
||||
messageFilter.ActivityDetected += MessageFilter_ActivityDetected;
|
||||
}
|
||||
#endregion ≡≡≡≡≡≡≡≡≡≡【inactivityTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【1】【END】
|
||||
|
||||
|
||||
|
||||
private void Tcp事件注册()
|
||||
{
|
||||
//事件注册
|
||||
@@ -526,36 +581,68 @@ namespace 精工涂胶检测项目
|
||||
|
||||
myJobManager.UserResultAvailable += MyJobManager_UserResultAvailable;
|
||||
}
|
||||
|
||||
#region ≡≡≡≡≡≡≡≡≡≡【modbusPollTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【2】【BEGIN】
|
||||
private void StopModbusPolling()
|
||||
{
|
||||
if (modbusPollTimer != null && modbusPollTimer.Enabled)
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
//if (modbusPollTimer != null && modbusPollTimer.Enabled)
|
||||
//{
|
||||
// modbusPollTimer.Stop();
|
||||
// AddLog("Modbus断线,已停止实时读取", 1);
|
||||
//}
|
||||
|
||||
if (mModbusPollTimer != null && mModbusPollTimer.Enabled)
|
||||
{
|
||||
modbusPollTimer.Stop();
|
||||
mModbusPollTimer.Stop();
|
||||
AddLog("Modbus断线,已停止实时读取", 1);
|
||||
}
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
}
|
||||
#endregion ≡≡≡≡≡≡≡≡≡≡【modbusPollTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【2】【END】
|
||||
|
||||
private void _modbusClient_Disconnected(object sender, string e)
|
||||
{
|
||||
AddLog($"PLC连接断开:{e}", 1);
|
||||
}
|
||||
|
||||
private void InactivityTimer_Tick(object sender, EventArgs e)
|
||||
|
||||
#region ≡≡≡≡≡≡≡≡≡≡【inactivityTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【2】【BEGIN】
|
||||
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
//private void InactivityTimer_Tick(object sender, EventArgs e)
|
||||
//{
|
||||
// if (currentStatus == 3)
|
||||
// {
|
||||
// SetMainEnabled(0, "登录");
|
||||
// inactivityTimer.Stop();
|
||||
// }
|
||||
//}
|
||||
|
||||
private void InactivityTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
if (currentStatus == 3)
|
||||
{
|
||||
SetMainEnabled(0, "登录");
|
||||
inactivityTimer.Stop();
|
||||
mInactivityTimer.Stop();
|
||||
}
|
||||
}
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
|
||||
private void MessageFilter_ActivityDetected(object sender, EventArgs e)
|
||||
{
|
||||
if (currentStatus == 3) // 仅admin状态重置计时器
|
||||
{
|
||||
inactivityTimer.Stop();
|
||||
inactivityTimer.Start();
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
//inactivityTimer.Stop();
|
||||
//inactivityTimer.Start();
|
||||
|
||||
mInactivityTimer.Stop();
|
||||
mInactivityTimer.Start();
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
}
|
||||
}
|
||||
#endregion ≡≡≡≡≡≡≡≡≡≡【inactivityTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【2】【END】
|
||||
|
||||
/// <summary>
|
||||
/// 程序关闭方法
|
||||
@@ -598,6 +685,8 @@ namespace 精工涂胶检测项目
|
||||
}
|
||||
}
|
||||
private void MyJobManager_UserResultAvailable(object sender, CogJobManagerActionEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
///待会儿需要改,通过ToolBlock是否报错来判断。
|
||||
//结果处理代码
|
||||
@@ -626,13 +715,47 @@ namespace 精工涂胶检测项目
|
||||
ICogRecord BOT6;
|
||||
ICogRecord BDKTJ;
|
||||
ICogRecord TJ;
|
||||
ICogRecord topRecord = myJobManager.UserResult();
|
||||
ICogRecord topRecord;
|
||||
|
||||
string currentDateFolder;
|
||||
try
|
||||
{
|
||||
topRecord = myJobManager.UserResult();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"获取用户结果失败:{ex.Message}", 1);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
string s = ProductSN.Substring(2);
|
||||
///create graphic wrapper for the range image with its grey overlay
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"获取产品SN失败:{ex.Message}", 1);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
Cog3DRangeImageGraphic rImgG = myToolBlock1.Outputs["CombinedImage"].Value as Cog3DRangeImageGraphic;
|
||||
cog3DDisplayV2WF1.Add(rImgG);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"获取图像失败:{ex.Message}", 1);
|
||||
return;
|
||||
}
|
||||
string rootPath = @"D:\Date";
|
||||
string currentDateFolder = Form1.CreateCurrentDateFolder(rootPath);
|
||||
try
|
||||
{
|
||||
currentDateFolder = Form1.CreateCurrentDateFolder(rootPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"创建当前文件夹失败:{ex.Message}", 1);
|
||||
return;
|
||||
}
|
||||
AddLog("当前文件夹已创建", 1);
|
||||
//图像显示需要改
|
||||
// ICogRecord ShowImageRecord = topRecord.SubRecords["ShowLastRunRecordForUserQueue"].SubRecords["LastRun"].SubRecords["Image Source.OutputImage"];
|
||||
@@ -655,12 +778,21 @@ namespace 精工涂胶检测项目
|
||||
|
||||
label2.Invoke(new Action(() => label2.Text = s));
|
||||
Image img = cogRecordDisplay1.CreateContentBitmap(Cognex.VisionPro.Display.CogDisplayContentBitmapConstants.Display);
|
||||
string imageName = s +DateTime.Now.ToString("ss")+ ".Png";
|
||||
imageSavePath = Path.Combine(currentDateFolder,imageName);
|
||||
string imageName = s + DateTime.Now.ToString("ss") + ".Png";
|
||||
imageSavePath = Path.Combine(currentDateFolder, imageName);
|
||||
try
|
||||
{
|
||||
img.Save(imageSavePath, ImageFormat.Png);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"保存图像失败:{ex.Message}", 1);
|
||||
return;
|
||||
}
|
||||
cogRecordDisplay1.AutoFit = true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
tmpVolum1 = topRecord.SubRecords["Volum1"];
|
||||
tmpArea1 = topRecord.SubRecords["Area1"];
|
||||
tmpVolum2 = topRecord.SubRecords["Volum2"];
|
||||
@@ -681,10 +813,14 @@ namespace 精工涂胶检测项目
|
||||
BOT3 = topRecord.SubRecords["BOT3"];
|
||||
BOT4 = topRecord.SubRecords["BOT1"];
|
||||
BOT5 = topRecord.SubRecords["BOT2"];
|
||||
BOT6= topRecord.SubRecords["BOT3"];
|
||||
BOT6 = topRecord.SubRecords["BOT3"];
|
||||
TJ = topRecord.SubRecords["TJ"];
|
||||
//label11.Text = tmpVolum.ToString();
|
||||
//label12.Text = tmpArea.ToString();//
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"获取数据失败:{ex.Message}", 1);
|
||||
return;
|
||||
}
|
||||
|
||||
string volumStatus;
|
||||
string areaStatus;
|
||||
@@ -699,28 +835,52 @@ namespace 精工涂胶检测项目
|
||||
double dj = 1.0;
|
||||
double qx = 1.0;
|
||||
double dw = 1.0;
|
||||
double volum1 = (double)tmpVolum1.Content;
|
||||
double area1 = (double)tmpArea1.Content;
|
||||
double volum2 = (double)tmpVolum2.Content;
|
||||
double area2 = (double)tmpArea2.Content;
|
||||
double volum3 = (double)tmpVolum3.Content;
|
||||
double area3 = (double)tmpArea3.Content;
|
||||
double top1 = (double)TOP1.Content;
|
||||
double top2 = (double)TOP2.Content;
|
||||
double top3 = (double)TOP3.Content;
|
||||
double top4 = (double)TOP1.Content;
|
||||
double top5 = (double)TOP2.Content;
|
||||
double top6 = (double)TOP3.Content;
|
||||
double topmj = (double)TOP2.Content*(double)TOP3.Content;
|
||||
double bot1 = (double)BOT1.Content;
|
||||
double bot2 = (double)BOT2.Content;
|
||||
double bot3 = (double)BOT3.Content;
|
||||
double bot4 = (double)BOT4.Content;
|
||||
double bot5 = (double)BOT5.Content;
|
||||
double bot6 = (double)BOT6.Content;
|
||||
double botmj = (double)BOT1.Content * (double)BOT3.Content;
|
||||
|
||||
double volum1;
|
||||
double area1;
|
||||
double volum2;
|
||||
double area2;
|
||||
double volum3;
|
||||
double area3;
|
||||
double top1;
|
||||
double top2;
|
||||
double top3;
|
||||
double top4;
|
||||
double top5;
|
||||
double top6;
|
||||
double topmj;
|
||||
double bot1;
|
||||
double bot2;
|
||||
double bot3;
|
||||
double bot4;
|
||||
double bot5;
|
||||
double bot6;
|
||||
double botmj;
|
||||
double bdktj;
|
||||
try
|
||||
{
|
||||
volum1 = (double)tmpVolum1.Content;
|
||||
area1 = (double)tmpArea1.Content;
|
||||
volum2 = (double)tmpVolum2.Content;
|
||||
area2 = (double)tmpArea2.Content;
|
||||
volum3 = (double)tmpVolum3.Content;
|
||||
area3 = (double)tmpArea3.Content;
|
||||
top1 = (double)TOP1.Content;
|
||||
top2 = (double)TOP2.Content;
|
||||
top3 = (double)TOP3.Content;
|
||||
top4 = (double)TOP1.Content;
|
||||
top5 = (double)TOP2.Content;
|
||||
top6 = (double)TOP3.Content;
|
||||
topmj = (double)TOP2.Content * (double)TOP3.Content;
|
||||
bot1 = (double)BOT1.Content;
|
||||
bot2 = (double)BOT2.Content;
|
||||
bot3 = (double)BOT3.Content;
|
||||
bot4 = (double)BOT4.Content;
|
||||
bot5 = (double)BOT5.Content;
|
||||
bot6 = (double)BOT6.Content;
|
||||
botmj = (double)BOT1.Content * (double)BOT3.Content;
|
||||
//算体积
|
||||
double bdktj = (double)TJ.Content-3800;// 0.333333 *20*(topmj+botmj+3200);
|
||||
bdktj = (double)TJ.Content - 3800;// 0.333333 *20*(topmj+botmj+3200);
|
||||
//string dj = DJCJ.ToString();
|
||||
if (checkBox3.Checked)
|
||||
{
|
||||
@@ -731,6 +891,13 @@ namespace 精工涂胶检测项目
|
||||
qx = (double)QX.Content;
|
||||
}
|
||||
dw = (double)DW.Content;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"获取数据失败:{ex.Message}", 1);
|
||||
return;
|
||||
}
|
||||
|
||||
//定义12个阈值参数
|
||||
string CSV1max;
|
||||
string CSV1min;
|
||||
@@ -749,8 +916,9 @@ namespace 精工涂胶检测项目
|
||||
//使用阈值
|
||||
|
||||
try
|
||||
{string used=label81.Text;
|
||||
string usePath= Path.Combine(@"D:\", $"{used}.txt");
|
||||
{
|
||||
string used = label81.Text;
|
||||
string usePath = Path.Combine(@"D:\", $"{used}.txt");
|
||||
if (File.Exists(usePath))
|
||||
{
|
||||
string[] lines = File.ReadAllLines(usePath); // 读取所有行[^1]
|
||||
@@ -781,13 +949,13 @@ namespace 精工涂胶检测项目
|
||||
csv3min = Convert.ToInt32(CSV3min);
|
||||
csa3max = Convert.ToInt32(CSA3max);
|
||||
csa3min = Convert.ToInt32(CSA3min);
|
||||
bdyz= Convert.ToInt32(BdYZ);
|
||||
bdyz = Convert.ToInt32(BdYZ);
|
||||
TOPMJMin = 1600 * ((100 - bdyz) * 0.01);
|
||||
TOPMJMax = 1600 * ((100 + bdyz) * 0.01);
|
||||
BOTMJMin = 6400 * ((100 - bdyz) * 0.01);
|
||||
BOTMJMax = 6400 * ((100 + bdyz) * 0.01);
|
||||
TOP1Min = 40 * ((100 - bdyz) * 0.01);
|
||||
TOP1Max = 40 * ((100+ bdyz) * 0.01);
|
||||
TOP1Max = 40 * ((100 + bdyz) * 0.01);
|
||||
TOP2Min = 40 * ((100 - bdyz) * 0.01);
|
||||
TOP2Max = 40 * ((100 + bdyz) * 0.01);
|
||||
TOP3Min = 40 * ((100 - bdyz) * 0.01);
|
||||
@@ -810,7 +978,7 @@ namespace 精工涂胶检测项目
|
||||
BOT5Max = 80 * ((100 + bdyz) * 0.01);
|
||||
BOT6Min = 80 * ((100 - bdyz) * 0.01);
|
||||
BOT6Max = 80 * ((100 + bdyz) * 0.01);
|
||||
BDKTJMin =74000;
|
||||
BDKTJMin = 74000;
|
||||
BDKTJMax = 75000;
|
||||
}
|
||||
if (checkBox5.Checked)
|
||||
@@ -818,7 +986,7 @@ namespace 精工涂胶检测项目
|
||||
|
||||
label64.Text = BDKTJMin.ToString() + "~" + BDKTJMax.ToString() + "mm³";
|
||||
}
|
||||
if (checkBox2.Checked== false)
|
||||
if (checkBox2.Checked == false)
|
||||
{
|
||||
csv1max = 999999;
|
||||
csv1min = 0; //700
|
||||
@@ -845,7 +1013,7 @@ namespace 精工涂胶检测项目
|
||||
{
|
||||
|
||||
}
|
||||
if (volum1 > csv1min && volum1 < csv1max&& dw < 3&& dj < 2 && dw < 3)
|
||||
if (volum1 > csv1min && volum1 < csv1max && dw < 3 && dj < 2 && dw < 3)
|
||||
{
|
||||
volumStatus1 = "OK";
|
||||
}
|
||||
@@ -872,7 +1040,7 @@ namespace 精工涂胶检测项目
|
||||
volumStatus3 = "NG";
|
||||
|
||||
}
|
||||
if (area1 > csa1min && area1 < csa1max&& dw < 2&& dj <2)
|
||||
if (area1 > csa1min && area1 < csa1max && dw < 2 && dj < 2)
|
||||
{
|
||||
areaStatus1 = "OK";
|
||||
}
|
||||
@@ -972,7 +1140,7 @@ namespace 精工涂胶检测项目
|
||||
if (label54.InvokeRequired && myToolBlock2.RunStatus.Result == CogToolResultConstants.Accept)
|
||||
{
|
||||
label54.Invoke(new Action(() => label54.Text = bdktj.ToString("0.00" + "mm³")));
|
||||
if (bdktj > 74770 && bdktj < 75008 )
|
||||
if (bdktj > 74770 && bdktj < 75008)
|
||||
{
|
||||
label80.Invoke(new Action(() => label80.Text = ("OK")));
|
||||
label80.Invoke(new Action(() => label80.BackColor = Color.Green));
|
||||
@@ -1127,6 +1295,8 @@ namespace 精工涂胶检测项目
|
||||
lbl_CheckNum.Invoke(new Action(() => lbl_OkRate.Text = (OKs / zs).ToString("0.00%")));
|
||||
|
||||
}
|
||||
try
|
||||
{
|
||||
modbusClient.WriteSingleRegister("4", (short)modbusResult);//ModbusResult
|
||||
modbusClient.WriteSingleRegisterString("31", "11" + imageSavePath); //存图路径
|
||||
string Area1 = area1.ToString("0.00");
|
||||
@@ -1142,6 +1312,11 @@ namespace 精工涂胶检测项目
|
||||
modbusClient.WriteSingleRegisterString("90", "11" + Volume2);//区域2体积
|
||||
modbusClient.WriteSingleRegisterString("96", "11" + Area3);//区域3面积
|
||||
modbusClient.WriteSingleRegisterString("102", "11" + Volume3);//区域3体积
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"发送数据失败:{ex.Message}", 1);
|
||||
}
|
||||
|
||||
if (ProductSN == null)
|
||||
{
|
||||
@@ -1159,7 +1334,7 @@ namespace 精工涂胶检测项目
|
||||
string bdexcelPath = Path.Combine(rootPath, bddateFileName);
|
||||
//CaptureSelfForm(this,savePath);
|
||||
bool isNewFile = !File.Exists(excelPath);
|
||||
if (checkBox5.Checked==false)
|
||||
if (checkBox5.Checked == false)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -1208,14 +1383,17 @@ namespace 精工涂胶检测项目
|
||||
AddLog("数据写入成功", 1);
|
||||
}
|
||||
|
||||
catch (Exception ex) { AddLog("数据写入成功", 1); ; }
|
||||
catch (Exception ex) { AddLog($"数据写入失败:{ex.Message}", 1); ; }
|
||||
finally
|
||||
{
|
||||
if (workbook != null) { workbook.Close();
|
||||
if (workbook != null)
|
||||
{
|
||||
workbook.Close();
|
||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
|
||||
}
|
||||
if (excelApp != null)
|
||||
{ excelApp.Quit();
|
||||
{
|
||||
excelApp.Quit();
|
||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
|
||||
}
|
||||
worksheet = null;
|
||||
@@ -1226,7 +1404,8 @@ namespace 精工涂胶检测项目
|
||||
}
|
||||
}
|
||||
bool isbdNewFile = !File.Exists(bdexcelPath);
|
||||
if (checkBox5.Checked==true) {
|
||||
if (checkBox5.Checked == true)
|
||||
{
|
||||
try
|
||||
{
|
||||
excelApp = new Excel.Application();
|
||||
@@ -1312,6 +1491,12 @@ namespace 精工涂胶检测项目
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -1570,6 +1755,8 @@ namespace 精工涂胶检测项目
|
||||
public void SetMainEnabled(int status, string account)
|
||||
{
|
||||
currentStatus = status; // 更新当前状态
|
||||
|
||||
#region ≡≡≡≡≡≡≡≡≡≡【inactivityTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【3】【BEGIN】
|
||||
switch (status)
|
||||
{
|
||||
case 0:
|
||||
@@ -1582,7 +1769,10 @@ namespace 精工涂胶检测项目
|
||||
this.登录ToolStripMenuItem1.Text = "登录";
|
||||
this.退出登录ToolStripMenuItem.Enabled = false;
|
||||
this.btn_Auto.Enabled = false;
|
||||
inactivityTimer.Stop();
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
//inactivityTimer.Stop();
|
||||
mInactivityTimer.Stop();
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
break;
|
||||
case 1:
|
||||
this.登录ToolStripMenuItem.Enabled = true;
|
||||
@@ -1618,9 +1808,13 @@ namespace 精工涂胶检测项目
|
||||
this.登录ToolStripMenuItem1.Enabled = false;
|
||||
this.退出登录ToolStripMenuItem.Enabled = true;
|
||||
this.btn_Auto.Enabled = true;
|
||||
inactivityTimer.Start();
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【BEGIN】
|
||||
//inactivityTimer.Start();
|
||||
mInactivityTimer.Start();
|
||||
//≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡【END】
|
||||
break;
|
||||
}
|
||||
#endregion ≡≡≡≡≡≡≡≡≡≡【inactivityTimer 定时器修改】:由 System.Windows.Forms.Timer 改为 System.Timers.Timer ≡≡≡≡≡≡≡≡≡≡【3】【END】
|
||||
}
|
||||
|
||||
private void 登录ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user