Commit 2c48ddc1 LN

增加扫码测试按钮

1 个父辈 c6ed25ab
......@@ -163,11 +163,26 @@ namespace DeviceLibrary
public static void CloseCamera(string cameraName)
{
Camera._cam.Close(cameraName);
try
{
Camera._cam.Close(cameraName);
}
catch (Exception ex)
{
LogUtil.error("CloseCamera error :" + ex.ToString());
}
}
public static void CloseAllCamera()
{
Camera._cam.CloseAll();
try
{
Camera._cam.CloseAll();
}
catch(Exception ex)
{
LogUtil.error("CloseAllCamera error :"+ex.ToString());
}
}
......
......@@ -151,7 +151,7 @@ namespace DeviceLibrary
LogUtil.info("开始关闭系统.");
IOManager.CloseAllConnection();
CameraA.stopCamera();
CodeManager.CloseAllCamera();
if (mainMachine != null)
{
// mainMachine.SingleDoor.Dispose();
......@@ -162,6 +162,10 @@ namespace DeviceLibrary
UserPause("", userpause);
}
public static void UserPause(string msg="",bool userpause=true) {
if (mainMachine == null)
{
return;
}
UserPauseSet?.Invoke(null, userpause);
mainMachine.UserPause = userpause;
if (userpause)
......
......@@ -39,6 +39,8 @@ namespace TheMachine
this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
this.禁用蜂鸣器ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
this.退出ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.语言toolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.简体中文ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
......@@ -58,8 +60,8 @@ namespace TheMachine
this.btn_IgnoreX09 = new System.Windows.Forms.Button();
this.btn_PauseBuzzer = new System.Windows.Forms.Button();
this.listView1 = new System.Windows.Forms.ListView();
this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.btnUpScan = new System.Windows.Forms.Button();
this.btnDownScan = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
this.tabc.SuspendLayout();
this.tabP1.SuspendLayout();
......@@ -104,32 +106,32 @@ namespace TheMachine
// btn_run
//
this.btn_run.Name = "btn_run";
this.btn_run.Size = new System.Drawing.Size(180, 26);
this.btn_run.Size = new System.Drawing.Size(176, 26);
this.btn_run.Text = "启动";
this.btn_run.Click += new System.EventHandler(this.btn_run_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(177, 6);
this.toolStripSeparator2.Size = new System.Drawing.Size(173, 6);
//
// btn_stop
//
this.btn_stop.Name = "btn_stop";
this.btn_stop.Size = new System.Drawing.Size(180, 26);
this.btn_stop.Size = new System.Drawing.Size(176, 26);
this.btn_stop.Text = "停止";
this.btn_stop.Click += new System.EventHandler(this.btn_stop_Click);
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(177, 6);
this.toolStripSeparator3.Size = new System.Drawing.Size(173, 6);
//
// 启用调试模式ToolStripMenuItem
//
this.启用调试模式ToolStripMenuItem.Enabled = false;
this.启用调试模式ToolStripMenuItem.Name = "启用调试模式ToolStripMenuItem";
this.启用调试模式ToolStripMenuItem.Size = new System.Drawing.Size(180, 26);
this.启用调试模式ToolStripMenuItem.Size = new System.Drawing.Size(176, 26);
this.启用调试模式ToolStripMenuItem.Tag = "not";
this.启用调试模式ToolStripMenuItem.Text = "启用配置模式";
this.启用调试模式ToolStripMenuItem.Click += new System.EventHandler(this.启用调试模式ToolStripMenuItem_Click);
......@@ -137,24 +139,36 @@ namespace TheMachine
// toolStripSeparator4
//
this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(177, 6);
this.toolStripSeparator4.Size = new System.Drawing.Size(173, 6);
//
// 禁用蜂鸣器ToolStripMenuItem
//
this.禁用蜂鸣器ToolStripMenuItem.Name = "禁用蜂鸣器ToolStripMenuItem";
this.禁用蜂鸣器ToolStripMenuItem.Size = new System.Drawing.Size(180, 26);
this.禁用蜂鸣器ToolStripMenuItem.Size = new System.Drawing.Size(176, 26);
this.禁用蜂鸣器ToolStripMenuItem.Text = "禁用蜂鸣器";
this.禁用蜂鸣器ToolStripMenuItem.Click += new System.EventHandler(this.禁用蜂鸣器ToolStripMenuItem_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(177, 6);
this.toolStripSeparator1.Size = new System.Drawing.Size(173, 6);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(176, 26);
this.toolStripMenuItem1.Text = "扫码测试";
this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click);
//
// toolStripSeparator5
//
this.toolStripSeparator5.Name = "toolStripSeparator5";
this.toolStripSeparator5.Size = new System.Drawing.Size(173, 6);
//
// 退出ToolStripMenuItem
//
this.退出ToolStripMenuItem.Name = "退出ToolStripMenuItem";
this.退出ToolStripMenuItem.Size = new System.Drawing.Size(180, 26);
this.退出ToolStripMenuItem.Size = new System.Drawing.Size(176, 26);
this.退出ToolStripMenuItem.Text = "退出";
this.退出ToolStripMenuItem.Click += new System.EventHandler(this.退出ToolStripMenuItem_Click);
//
......@@ -171,7 +185,7 @@ namespace TheMachine
// 简体中文ToolStripMenuItem
//
this.简体中文ToolStripMenuItem.Name = "简体中文ToolStripMenuItem";
this.简体中文ToolStripMenuItem.Size = new System.Drawing.Size(180, 26);
this.简体中文ToolStripMenuItem.Size = new System.Drawing.Size(144, 26);
this.简体中文ToolStripMenuItem.Tag = "not";
this.简体中文ToolStripMenuItem.Text = "简体中文";
this.简体中文ToolStripMenuItem.Click += new System.EventHandler(this.简体中文ToolStripMenuItem_Click);
......@@ -179,7 +193,7 @@ namespace TheMachine
// englishToolStripMenuItem
//
this.englishToolStripMenuItem.Name = "englishToolStripMenuItem";
this.englishToolStripMenuItem.Size = new System.Drawing.Size(180, 26);
this.englishToolStripMenuItem.Size = new System.Drawing.Size(144, 26);
this.englishToolStripMenuItem.Tag = "not";
this.englishToolStripMenuItem.Text = "English";
this.englishToolStripMenuItem.Click += new System.EventHandler(this.englishToolStripMenuItem_Click);
......@@ -217,6 +231,8 @@ namespace TheMachine
//
// pnl
//
this.pnl.Controls.Add(this.btnDownScan);
this.pnl.Controls.Add(this.btnUpScan);
this.pnl.Controls.Add(this.btnResetOut4);
this.pnl.Controls.Add(this.btnResetOut3);
this.pnl.Controls.Add(this.btnResetOut2);
......@@ -374,17 +390,29 @@ namespace TheMachine
this.listView1.TabIndex = 2;
this.listView1.UseCompatibleStateImageBehavior = false;
//
// toolStripSeparator5
//
this.toolStripSeparator5.Name = "toolStripSeparator5";
this.toolStripSeparator5.Size = new System.Drawing.Size(177, 6);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(180, 26);
this.toolStripMenuItem1.Text = "扫码测试";
this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click);
// btnUpScan
//
this.btnUpScan.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnUpScan.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnUpScan.Location = new System.Drawing.Point(862, 171);
this.btnUpScan.Name = "btnUpScan";
this.btnUpScan.Size = new System.Drawing.Size(130, 32);
this.btnUpScan.TabIndex = 275;
this.btnUpScan.Text = "上层扫码测试";
this.btnUpScan.UseVisualStyleBackColor = true;
this.btnUpScan.Click += new System.EventHandler(this.btnUpScan_Click);
//
// btnDownScan
//
this.btnDownScan.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnDownScan.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnDownScan.Location = new System.Drawing.Point(862, 209);
this.btnDownScan.Name = "btnDownScan";
this.btnDownScan.Size = new System.Drawing.Size(130, 32);
this.btnDownScan.TabIndex = 276;
this.btnDownScan.Text = "下层扫码测试";
this.btnDownScan.UseVisualStyleBackColor = true;
this.btnDownScan.Click += new System.EventHandler(this.btnDownScan_Click);
//
// FormMain
//
......@@ -446,6 +474,8 @@ namespace TheMachine
private System.Windows.Forms.Button btnResetOut2;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator5;
private System.Windows.Forms.Button btnDownScan;
private System.Windows.Forms.Button btnUpScan;
}
}
......@@ -6,7 +6,8 @@ using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
......@@ -704,7 +705,40 @@ namespace TheMachine
frm.ShowDialog();
frm.Dispose();
}
catch { }
catch (Exception ex)
{
LogUtil.error("出错:" + ex.ToString());
}
}
private void btnUpScan_Click(object sender, EventArgs e)
{
string[] camers = Setting_Init.CameraScan_IN_1;
List<CodeLibrary.CodeInfo> codeInfos = CodeManager.CameraScan(camers.ToList());
string lastCode = "";
foreach (CodeLibrary.CodeInfo ca in codeInfos)
{
lastCode += ca.CodeStr + "#";
}
LogUtil.info("[" +String.Join(",",camers) + "]扫码测试结果:\r\n" + lastCode);
MessageBox.Show("[" + String.Join(",", camers) + crc.GetString("Res0109", "]扫码测试结果:") + lastCode);
}
private void btnDownScan_Click(object sender, EventArgs e)
{
string[] camers = Setting_Init.CameraScan_IN_2;
List<CodeLibrary.CodeInfo> codeInfos = CodeManager.CameraScan(camers.ToList());
string lastCode = "";
foreach (CodeLibrary.CodeInfo ca in codeInfos)
{
lastCode += ca.CodeStr + "#";
}
LogUtil.info("[" + String.Join(",", camers) + "]扫码测试结果:\r\n" + lastCode);
MessageBox.Show("[" + String.Join(",", camers) + crc.GetString("Res0109", "]扫码测试结果:") + lastCode);
}
}
}
\ No newline at end of file
using ConfigHelper;
using log4net.Config;
using Microsoft.Win32.TaskScheduler;
//using Microsoft.Win32.TaskScheduler;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
......@@ -48,7 +48,7 @@ namespace TheMachine
}
}
AddOrUpdateStartupTask();
//AddOrUpdateStartupTask();
Config.LoadMyConfig(new Setting_Init().GetType());
Application.ThreadException += Application_ThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
......@@ -62,16 +62,23 @@ namespace TheMachine
Application.Run(new FormMain());
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
LogUtil.error(e.ToString());
LogUnhandledException("CurrentDomain_UnhandledException", e.ToString() + "" + e.ExceptionObject.ToString() + " ");
}
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
LogUtil.error(e.ToString());
LogUnhandledException("Application_ThreadException", e.ToString() + "" + e.Exception.ToString() + " ");
}
static void LogUnhandledException(string type, string exceptionobj)
{
//这里可以进一步地写日志
LogUtil.error("【" + type + "】" + exceptionobj);
MessageBox.Show(exceptionobj, type);
LogUtil.error("【" + type + "】" + exceptionobj);
}
#region Win32函数的声明
......@@ -104,43 +111,43 @@ namespace TheMachine
public const int SW_RESTORE = 9;
#endregion
public static void AddOrUpdateStartupTask()
{
// 获取当前程序的路径和名称
string appPath = Process.GetCurrentProcess().MainModule.FileName;
string TaskName = "AutoStartup_" + Process.GetCurrentProcess().MainModule.ModuleName;
// 创建或更新计划任务
using (TaskService taskService = new TaskService())
{
// 获取任务定义,如果不存在则创建新的任务定义
TaskDefinition taskDefinition;
if (taskService.GetTask(TaskName) != null)
{
taskDefinition = taskService.GetTask(TaskName).Definition;
}
else
{
taskDefinition = taskService.NewTask();
taskDefinition.RegistrationInfo.Description = TaskName;
}
if (taskDefinition.Triggers.Count == 0 || taskDefinition.Triggers[0].TriggerType != TaskTriggerType.Logon)
{
// 设置触发器为用户登录后启动
LogonTrigger logonTrigger = (LogonTrigger)taskDefinition.Triggers.Add(new LogonTrigger());
logonTrigger.Delay = TimeSpan.FromSeconds(5);
}
// 设置操作为启动应用程序
taskDefinition.Actions.Clear();
taskDefinition.Actions.Add(new ExecAction(appPath, null, System.IO.Path.GetDirectoryName(appPath)));
// 设置任务的运行权限为管理员权限
taskDefinition.Principal.RunLevel = TaskRunLevel.Highest;
// 保存任务
taskService.RootFolder.RegisterTaskDefinition(TaskName, taskDefinition, TaskCreation.CreateOrUpdate, null, null, TaskLogonType.InteractiveToken, null);
}
}
//public static void AddOrUpdateStartupTask()
//{
// // 获取当前程序的路径和名称
// string appPath = Process.GetCurrentProcess().MainModule.FileName;
// string TaskName = "AutoStartup_" + Process.GetCurrentProcess().MainModule.ModuleName;
// // 创建或更新计划任务
// using (TaskService taskService = new TaskService())
// {
// // 获取任务定义,如果不存在则创建新的任务定义
// TaskDefinition taskDefinition;
// if (taskService.GetTask(TaskName) != null)
// {
// taskDefinition = taskService.GetTask(TaskName).Definition;
// }
// else
// {
// taskDefinition = taskService.NewTask();
// taskDefinition.RegistrationInfo.Description = TaskName;
// }
// if (taskDefinition.Triggers.Count == 0 || taskDefinition.Triggers[0].TriggerType != TaskTriggerType.Logon)
// {
// // 设置触发器为用户登录后启动
// LogonTrigger logonTrigger = (LogonTrigger)taskDefinition.Triggers.Add(new LogonTrigger());
// logonTrigger.Delay = TimeSpan.FromSeconds(5);
// }
// // 设置操作为启动应用程序
// taskDefinition.Actions.Clear();
// taskDefinition.Actions.Add(new ExecAction(appPath, null, System.IO.Path.GetDirectoryName(appPath)));
// // 设置任务的运行权限为管理员权限
// taskDefinition.Principal.RunLevel = TaskRunLevel.Highest;
// // 保存任务
// taskService.RootFolder.RegisterTaskDefinition(TaskName, taskDefinition, TaskCreation.CreateOrUpdate, null, null, TaskLogonType.InteractiveToken, null);
// }
//}
}
}
......@@ -53,12 +53,8 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\SharedDLL\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Win32.TaskScheduler, Version=2.10.1.0, Culture=neutral, PublicKeyToken=e25603a88b3aa7da, processorArchitecture=MSIL">
<HintPath>..\packages\TaskScheduler.2.10.1\lib\net452\Microsoft.Win32.TaskScheduler.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!