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