Commit a9c5a5a2 刘韬

添加管理员密码控制,添加超时撤销管理员

1 个父辈 5fd287da
......@@ -111,6 +111,7 @@ namespace OnlineStore.Common
public static string InstoreEndSendShelf = "InstoreEndSendShelf";
public static string OutstoreEndSendShelf= "OutstoreEndSendShelf";
public static string ElectricGripperForce = "ElectricGripperForce";
public static string debugwaittime= "debugwaittime";
//public static string LastOutShelfType= "LastOutShelfType";
}
}
......@@ -57,9 +57,9 @@ namespace OnlineStore.Common
}
return a;
}
public static int GetIntValue(string key)
public static int GetIntValue(string key,int defalutvalue=0)
{
int a = 0;
int a = defalutvalue;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
......
......@@ -227,6 +227,8 @@ namespace OnlineStore.DUOStore
private void btnSotreReset_Click(object sender, EventArgs e)
{
if (!Program.TestAdmin())
return;
if (StoreManager.Store.runStatus >= StoreRunStatus.HomeMoving)
{
StoreManager.Store.ResetLine();
......
using OnlineStore.DUOStore;
using System.Windows.Forms;
namespace OnlineStore.DUOStore
{
......
......@@ -29,6 +29,7 @@ namespace OnlineStore.DUOStore
{
Control.CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
}
#region "初始化界面数据"
......@@ -576,6 +577,8 @@ namespace OnlineStore.DUOStore
private void 停止ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!Program.TestAdmin())
return;
try
{
if (BoxBean.runStatus >= StoreRunStatus.HomeMoving)
......@@ -596,6 +599,8 @@ namespace OnlineStore.DUOStore
private void btnSotreReset_Click(object sender, EventArgs e)
{
if (!Program.TestAdmin())
return;
if (BoxBean.runStatus >= StoreRunStatus.HomeMoving)
{
this.BoxBean.Reset();
......
......@@ -32,13 +32,25 @@
this.btnNext = new System.Windows.Forms.Button();
this.btnBack = new System.Windows.Forms.Button();
this.txtPwd = new System.Windows.Forms.TextBox();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.panel1 = new System.Windows.Forms.Panel();
this.btn_editpwd = new System.Windows.Forms.LinkLabel();
this.panel_edit = new System.Windows.Forms.Panel();
this.txt_newpwdagain = new System.Windows.Forms.TextBox();
this.txt_newpwd = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.panel2 = new System.Windows.Forms.Panel();
this.flowLayoutPanel1.SuspendLayout();
this.panel1.SuspendLayout();
this.panel_edit.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(153, 61);
this.label1.Location = new System.Drawing.Point(176, 22);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(126, 25);
this.label1.TabIndex = 0;
......@@ -49,7 +61,7 @@
this.btnNext.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.btnNext.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnNext.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnNext.Location = new System.Drawing.Point(221, 163);
this.btnNext.Location = new System.Drawing.Point(244, 17);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(120, 45);
this.btnNext.TabIndex = 275;
......@@ -62,7 +74,7 @@
this.btnBack.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.btnBack.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnBack.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnBack.Location = new System.Drawing.Point(95, 163);
this.btnBack.Location = new System.Drawing.Point(118, 17);
this.btnBack.Name = "btnBack";
this.btnBack.Size = new System.Drawing.Size(120, 45);
this.btnBack.TabIndex = 274;
......@@ -73,30 +85,115 @@
// txtPwd
//
this.txtPwd.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtPwd.Location = new System.Drawing.Point(112, 97);
this.txtPwd.Location = new System.Drawing.Point(132, 60);
this.txtPwd.Name = "txtPwd";
this.txtPwd.PasswordChar = '*';
this.txtPwd.Size = new System.Drawing.Size(215, 33);
this.txtPwd.TabIndex = 276;
this.txtPwd.Text = "123456";
this.txtPwd.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtPwd_KeyDown);
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.Controls.Add(this.panel1);
this.flowLayoutPanel1.Controls.Add(this.panel_edit);
this.flowLayoutPanel1.Controls.Add(this.panel2);
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(482, 422);
this.flowLayoutPanel1.TabIndex = 278;
//
// panel1
//
this.panel1.Controls.Add(this.btn_editpwd);
this.panel1.Controls.Add(this.txtPwd);
this.panel1.Controls.Add(this.label1);
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Margin = new System.Windows.Forms.Padding(0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(470, 107);
this.panel1.TabIndex = 277;
//
// btn_editpwd
//
this.btn_editpwd.AutoSize = true;
this.btn_editpwd.Location = new System.Drawing.Point(411, 9);
this.btn_editpwd.Name = "btn_editpwd";
this.btn_editpwd.Size = new System.Drawing.Size(56, 17);
this.btn_editpwd.TabIndex = 277;
this.btn_editpwd.TabStop = true;
this.btn_editpwd.Text = "修改密码";
this.btn_editpwd.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.btn_editpwd_LinkClicked);
//
// panel_edit
//
this.panel_edit.Controls.Add(this.txt_newpwdagain);
this.panel_edit.Controls.Add(this.txt_newpwd);
this.panel_edit.Controls.Add(this.label2);
this.panel_edit.Location = new System.Drawing.Point(0, 107);
this.panel_edit.Margin = new System.Windows.Forms.Padding(0);
this.panel_edit.Name = "panel_edit";
this.panel_edit.Size = new System.Drawing.Size(470, 141);
this.panel_edit.TabIndex = 279;
//
// txt_newpwdagain
//
this.txt_newpwdagain.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txt_newpwdagain.Location = new System.Drawing.Point(132, 96);
this.txt_newpwdagain.Name = "txt_newpwdagain";
this.txt_newpwdagain.PasswordChar = '*';
this.txt_newpwdagain.Size = new System.Drawing.Size(215, 33);
this.txt_newpwdagain.TabIndex = 276;
this.txt_newpwdagain.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtPwd_KeyDown);
//
// txt_newpwd
//
this.txt_newpwd.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txt_newpwd.Location = new System.Drawing.Point(132, 57);
this.txt_newpwd.Name = "txt_newpwd";
this.txt_newpwd.PasswordChar = '*';
this.txt_newpwd.Size = new System.Drawing.Size(215, 33);
this.txt_newpwd.TabIndex = 276;
this.txt_newpwd.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtPwd_KeyDown);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(167, 20);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(145, 25);
this.label2.TabIndex = 0;
this.label2.Text = "请输入新密码:";
//
// panel2
//
this.panel2.Controls.Add(this.btnBack);
this.panel2.Controls.Add(this.btnNext);
this.panel2.Location = new System.Drawing.Point(0, 248);
this.panel2.Margin = new System.Windows.Forms.Padding(0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(470, 71);
this.panel2.TabIndex = 278;
//
// FrmPwd
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(437, 268);
this.Controls.Add(this.txtPwd);
this.Controls.Add(this.btnNext);
this.Controls.Add(this.btnBack);
this.Controls.Add(this.label1);
this.ClientSize = new System.Drawing.Size(482, 422);
this.Controls.Add(this.flowLayoutPanel1);
this.Name = "FrmPwd";
this.Text = "请输入密码";
this.Load += new System.EventHandler(this.FrmPwd_Load);
this.Shown += new System.EventHandler(this.FrmPwd_Shown);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FrmPwd_KeyDown);
this.flowLayoutPanel1.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.panel_edit.ResumeLayout(false);
this.panel_edit.PerformLayout();
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
......@@ -106,5 +203,13 @@
private System.Windows.Forms.Button btnNext;
private System.Windows.Forms.Button btnBack;
private System.Windows.Forms.TextBox txtPwd;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel_edit;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.LinkLabel btn_editpwd;
private System.Windows.Forms.TextBox txt_newpwdagain;
private System.Windows.Forms.TextBox txt_newpwd;
private System.Windows.Forms.Label label2;
}
}
\ No newline at end of file
......@@ -17,17 +17,29 @@ namespace OnlineStore.DUOStore
public delegate void PwdOK(int type);
public event PwdOK PwdOKFun;
private int OpenType = 0;
int paneleditheight = 0;
public FrmPwd(int type)
{
OpenType = type;
InitializeComponent();
paneleditheight = panel_edit.Height;
panel_edit.Height = 0;
}
private void FrmPwd_Load(object sender, EventArgs e)
{
FormResize();
this.DialogResult = DialogResult.None;
}
void FormResize() {
int Height = 0;
foreach (Control c in flowLayoutPanel1.Controls)
{
Height += c.Height;
}
this.Height = Height + 50;
}
private void btnNext_Click(object sender, EventArgs e)
{
string pwd = txtPwd.Text;
......@@ -37,24 +49,29 @@ namespace OnlineStore.DUOStore
configPwd = "123456";
ConfigAppSettings.SaveValue(Setting_Init.Config_Pwd,configPwd);
}
if (panel_edit.Height == paneleditheight) {
if (pwd.Equals(configPwd)) {
if (txt_newpwd.Text != txt_newpwdagain.Text)
{
MessageBox.Show("2次输入的新密码不一致");
return;
}
//configPwd = txt_newpwd.Text;
ConfigAppSettings.SaveValue(Setting_Init.Config_Pwd, txt_newpwd.Text);
MessageBox.Show("密码修改成功!");
}
else
{
MessageBox.Show("请输入正确的旧密码");
txtPwd.Focus();
return;
}
}
if (pwd.Equals(configPwd))
{
this.DialogResult = DialogResult.OK;
//if (OpenType.Equals(1))
//{
// FrmDebugMenu main = new FrmDebugMenu();
// main.ShowDialog();
//}
//else if (OpenType.Equals(2))
//{
// FrmProgramList board = new FrmProgramList();
// board.ShowDialog();
//}
//else if (OpenType.Equals(3))
//{
// FrmBoardList board = new FrmBoardList();
// board.ShowDialog();
//}
PwdOKFun?.Invoke(OpenType);
this.DialogResult = DialogResult.OK;
this.Close();
......@@ -98,5 +115,11 @@ namespace OnlineStore.DUOStore
txtPwd.Focus();
}
private void btn_editpwd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
panel_edit.Height = paneleditheight;
FormResize();
}
}
}
......@@ -43,6 +43,7 @@
this.chbAutoRun = new System.Windows.Forms.CheckBox();
this.btnCopyLog = new System.Windows.Forms.Button();
this.btnClearLog = new System.Windows.Forms.Button();
this.lblAgv = new System.Windows.Forms.Label();
this.lblMission = new System.Windows.Forms.Label();
this.lblShelf = new System.Windows.Forms.Label();
this.chbUseBuzzer = new System.Windows.Forms.CheckBox();
......@@ -78,7 +79,6 @@
this.toolStripSeparator8 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.lblAgv = new System.Windows.Forms.Label();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
......@@ -128,6 +128,8 @@
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox2.TabIndex = 273;
this.pictureBox2.TabStop = false;
this.pictureBox2.DoubleClick += new System.EventHandler(this.pictureBox1_DoubleClick);
this.pictureBox2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
//
// pictureBox1
//
......@@ -137,6 +139,8 @@
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 272;
this.pictureBox1.TabStop = false;
this.pictureBox1.DoubleClick += new System.EventHandler(this.pictureBox1_DoubleClick);
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
//
// panel1
//
......@@ -260,6 +264,16 @@
this.btnClearLog.Visible = false;
this.btnClearLog.Click += new System.EventHandler(this.btnClearLog_Click);
//
// lblAgv
//
this.lblAgv.AutoSize = true;
this.lblAgv.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblAgv.Location = new System.Drawing.Point(3, 111);
this.lblAgv.Name = "lblAgv";
this.lblAgv.Size = new System.Drawing.Size(57, 17);
this.lblAgv.TabIndex = 204;
this.lblAgv.Text = "AGV状态";
//
// lblMission
//
this.lblMission.AutoSize = true;
......@@ -555,16 +569,6 @@
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// lblAgv
//
this.lblAgv.AutoSize = true;
this.lblAgv.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblAgv.Location = new System.Drawing.Point(3, 111);
this.lblAgv.Name = "lblAgv";
this.lblAgv.Size = new System.Drawing.Size(57, 17);
this.lblAgv.TabIndex = 204;
this.lblAgv.Text = "AGV状态";
//
// FrmStore
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
......
......@@ -19,12 +19,14 @@ using UserFromControl;
namespace OnlineStore.DUOStore
{
internal partial class FrmStore : Form
internal partial class FrmStore : Form, IMessageFilter
{
public static DUOStoreBean store = null;
private List<TabPage> tabPageList = new List<TabPage>();
private bool LoadOk = false;
private System.Timers.Timer startTimer = null;
int debugwaittime = ConfigAppSettings.GetIntValue(Setting_Init.debugwaittime,3);
//bool isAdmin = false;
internal FrmStore()
{
InitializeComponent();
......@@ -34,8 +36,40 @@ namespace OnlineStore.DUOStore
startTimer.AutoReset = false;
Control.CheckForIllegalCrossThreadCalls = false;
LogUtil.showLogEvent += LogUtil_showLogEvent;
Application.AddMessageFilter(this);
var t2 =new Timer();
t2.Interval = 1000;
t2.Tick += (o,e) => {
if (Program.IsAdmin && (DateTime.Now - lasttouch).TotalSeconds > debugwaittime * 60)
{
Program.IsAdmin = false;
DebugOpen(false);
}
};
t2.Start();
}
DateTime lasttouch = DateTime.Now;
IntPtr lastpoint = IntPtr.Zero;
public bool PreFilterMessage(ref Message msg)
{
const int WM_MOUSEMOVE = 0x200;
const int WM_LBUTTONDOWN = 0x201;
if ((msg.Msg == WM_MOUSEMOVE) && lastpoint != msg.LParam)
{
lasttouch = DateTime.Now;
lastpoint = msg.LParam;
//Console.WriteLine(lasttouch);
}
else if (msg.Msg == WM_LBUTTONDOWN)
{
lasttouch = DateTime.Now;
lastpoint = msg.LParam;
// Console.WriteLine(lasttouch);
}
return false;
}
private void FrmMain_Load(object sender, EventArgs e)
{
......@@ -316,13 +350,13 @@ namespace OnlineStore.DUOStore
{
try
{
FrmPwd fw = new FrmPwd(10);
DialogResult result = fw.ShowDialog();
if (!result.Equals(DialogResult.OK))
{
LogUtil.info("切换界面显示时,没有正确输入密码");
return;
}
//FrmPwd fw = new FrmPwd(10);
//DialogResult result = fw.ShowDialog();
//if (!result.Equals(DialogResult.OK))
//{
// LogUtil.info("切换界面显示时,没有正确输入密码");
// return;
//}
this.Opacity = 100;
this.Visible = true;
......@@ -402,6 +436,8 @@ namespace OnlineStore.DUOStore
}
private void 停止所有料仓TToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!Program.TestAdmin())
return;
if (store != null)
{
if (store.runStatus.Equals(StoreRunStatus.Wait))
......@@ -419,6 +455,8 @@ namespace OnlineStore.DUOStore
private void 复位RToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!Program.TestAdmin())
return;
if (store.runStatus.Equals(StoreRunStatus.Wait))
{
MessageBox.Show(store.Name + "DUO料仓未启动,无法复位");
......@@ -597,22 +635,36 @@ namespace OnlineStore.DUOStore
private void 退出ToolStripMenuItem_Click_1(object sender, EventArgs e)
{
ExitApp();
if (Program.TestAdmin())
ExitApp();
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
ExitApp();
if (Program.TestAdmin())
ExitApp();
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
if (toolStripMenuItem2.Text .Equals("启用调试"))
if (toolStripMenuItem2.Text.Equals("启用调试"))
{
DebugOpen(true );
//if (!Program.IsAdmin)
{
FrmPwd fw = new FrmPwd(10);
DialogResult result = fw.ShowDialog();
if (!result.Equals(DialogResult.OK))
{
LogUtil.info("切换界面显示时,没有正确输入密码");
return;
}
}
Program.IsAdmin = true;
DebugOpen(true);
}
else
{
Program.IsAdmin = false;
DebugOpen(false);
}
}
......@@ -649,10 +701,12 @@ namespace OnlineStore.DUOStore
if (isopen)
{
LogUtil.info("禁用调试");
toolStripMenuItem2.Text = "禁用调试";
}
else
{
LogUtil.info("启用调试");
toolStripMenuItem2.Text = "启用调试";
}
}
......@@ -776,5 +830,30 @@ namespace OnlineStore.DUOStore
{
StoreManager.LastVisualRfid = "";
}
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
((Control)sender).Dock = DockStyle.Fill;
((Control)sender).BringToFront();
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
((Control)sender).Dock = DockStyle.None;
}
bool TestAdmin() {
if (!Program.IsAdmin)
{
FrmPwd fw = new FrmPwd(10);
DialogResult result = fw.ShowDialog();
if (!result.Equals(DialogResult.OK))
{
//LogUtil.info("切换界面显示时,没有正确输入密码");
return false;
}
}
Program.IsAdmin = true;
return true;
}
}
}
......@@ -19,6 +19,7 @@ namespace OnlineStore.DUOStore
static class Program
{
public static bool IsAdmin = false;
#region 方法四:使用的Win32函数的声明
/// <summary>
......@@ -150,5 +151,19 @@ namespace OnlineStore.DUOStore
//这里可以进一步地写日志
LogUtil.error("LogUnhandledException:"+exceptionobj.ToString());
}
public static bool TestAdmin()
{
FrmPwd fw = new FrmPwd(10);
DialogResult result = fw.ShowDialog();
if (!result.Equals(DialogResult.OK))
{
//LogUtil.info("切换界面显示时,没有正确输入密码");
return false;
}
Program.IsAdmin = true;
return true;
}
}
}
......@@ -42,8 +42,8 @@
<Reference Include="Agv.Client">
<HintPath>..\..\..\775-AGVClientTest\Agv.Client.dll</HintPath>
</Reference>
<Reference Include="Asa.HIK.IPCamera">
<HintPath>..\..\..\camera\Asa.HIK.IPCamera.dll</HintPath>
<Reference Include="Asa.Camera.VisionLib">
<HintPath>..\..\..\camera\Asa.Camera.VisionLib.dll</HintPath>
</Reference>
<Reference Include="Asa.IOModule.AIOBOX, Version=2.4.0.7, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
......
......@@ -68,7 +68,11 @@ namespace OnlineStore.DeviceLibrary
UpdownAxis = new AxisBean(config.UpDown_Axis, Name);
ComAxis = new AxisBean(config.Comp_Axis, Name);
mainTimer.Enabled = false;
LoadCameraConfig(config.Id.ToString());
try
{
LoadCameraConfig(config.Id.ToString());
}
catch { }
}
private void IoCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
......
using OnlineStore.Common;
using Asa.Camera;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
......@@ -6,6 +7,7 @@ using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
......@@ -14,58 +16,93 @@ namespace OnlineStore.DeviceLibrary
partial class BoxBean
{
Thread camerathread;
Asa.HIK.IPCamera camera;
Asa.Camera.VisionLib camera;
public event EventHandler<Bitmap> camera_event;
void LoadCameraConfig(string id) {
string path = @".\StoreConfig\box_"+id+"_Camera.json";
public string CameraDeviceName = "monitor1";
public void LoadCameraConfig(string id)
{
string path = @".\StoreConfig\box_" + id + "_Camera.json";
if (!File.Exists(path))
{
LogUtil.error(Name + "找不到监控相机配置文件"+ path);
LogUtil.error(Name + "找不到监控相机配置文件" + path);
return;
}
try
{
var configtxt = File.ReadAllText(path);
if (configtxt.IndexOf("Pwd") > 0)
{
configtxt = configtxt.Replace("Pwd", "Password");
configtxt = configtxt.Replace("\"8000\"", "8000");
File.WriteAllText(path, configtxt);
}
var m = Regex.Match(configtxt, "name\".*?\"(.+)\"", RegexOptions.IgnoreCase);
CameraDeviceName = m.Groups[1].Value;
camera = new VisionLib(path, "HIK.IPCamera");
}
catch (Exception e)
{
LogUtil.error(Name + "加载监控相机配置文件失败:" + e.ToString());
return;
}
camera.Open(CameraDeviceName);
Bitmap bmp = camera.GetImage(CameraDeviceName);
if (bmp == null)
{
LogUtil.error(Name + $"监控相机打开失败");
}
camera = new Asa.HIK.IPCamera(path);
bool rtn = camera.Load();
if (!rtn)
LogUtil.error(Name + "加载监控相机配置文件失败");
camerathread = new Thread(new ThreadStart(startCamera));
camerathread.Start();
//pictureBox1.Image = bmp;
GC.KeepAlive(camerathread);
}
void startCamera() {
if (!camera.IsOpen[0])
int errortimes = 0;
void startCamera()
{
while (true)
{
var rtn = camera.Open(0);
if (!rtn)
LogUtil.error(Name + "打开监控相机失败");
}
while (camera.IsOpen[0])
{
var rtn = camera.GrabOne(0, out Bitmap bmp);
if (rtn)
try
{
camera_event?.Invoke(this, bmp);
Bitmap bmp = camera.GetImage(CameraDeviceName);
if (bmp != null)
{
errortimes = 0;
camera_event?.Invoke(this, bmp);
}
else if (bmp == null && errortimes < 5)
{
errortimes++;
LogUtil.error(Name + $"相机获取图像出错,{errortimes}");
}
else if (errortimes == 5)
{
camera.Open();
errortimes++;
LogUtil.error(Name + $"相机错误次数过多,重新打开,{errortimes}");
}
else if (errortimes == 6)
{
LogUtil.error(Name + $"相机连接失败, 相机线程退出,{errortimes}");
break;
}
Thread.Sleep(1000 / 7);
}
catch
{
errortimes++;
}
Thread.Sleep(1000/7);
}
camera.Close(0);
camera.Close();
camera.Dispose();
}
void CameraGrabOne(string filename) {
void CameraGrabOne(string filename)
{
try
{
LogUtil.info(Name + "库位文件名:" + filename);
//return;
if (!camera.IsOpen[0])
{
camera.Open(0);
LogUtil.error(Name + "打开监控相机失败2");
}
var rtn = camera.GrabOne(0, out Bitmap bmp);
if (rtn)
Bitmap bmp = camera.GetImage(CameraDeviceName);
if (bmp != null)
{
if (File.Exists(filename))
File.Delete(filename);
......@@ -73,19 +110,9 @@ namespace OnlineStore.DeviceLibrary
bmp.Save(filename, ImageFormat.Jpeg);
bmp.Dispose();
}
else {
rtn = camera.GrabOne(0, out bmp);
if (rtn)
{
if (File.Exists(filename))
File.Delete(filename);
bmp.Save(filename, ImageFormat.Jpeg);
bmp.Dispose();
}
}
}
catch (Exception e) {
catch (Exception e)
{
LogUtil.error(Name + e.ToString());
}
}
......
......@@ -246,7 +246,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NextMoveStep(StoreMoveStep.SI_09_InoutToP1);
InOutStoreLog(outType + "进出轴返回P1 [" + moveP.InOut_P1 + "] ");
InOutBackToP1(moveP.InOut_P1);
OutDoorReelType = 2;
//OutDoorReelType = 2;
}
else if (MoveInfo.IsStep(StoreMoveStep.SI_09_InoutToP1))
{
......@@ -266,6 +266,7 @@ namespace OnlineStore.DeviceLibrary
TimeSpan span = DateTime.Now - startInStoreTime;
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosID : "";
LogUtil.info(Name + " 【" + posId + "】入库结束,耗时【" + FormUtil.GetSpanStr(span) + "】");
OutDoorReelType = 0;
MoveEndP();
AutoInout.InOutEndProcess(this, MoveType.InStore);
}
......
......@@ -1662,7 +1662,7 @@ namespace OnlineStore.DeviceLibrary
{
if (MoveInfo.MoveStep >= StoreMoveStep.LO_13_UpdownDown && MoveInfo.MoveStep <= StoreMoveStep.LO_15_UpdownUp)
{
if (MoveInfo.MoveParam.TargetBox.Equals(id))
if (MoveInfo.MoveParam != null && MoveInfo.MoveParam.TargetBox.Equals(id))
{
return false;
}
......@@ -1672,7 +1672,7 @@ namespace OnlineStore.DeviceLibrary
{
if (MoveInfo.MoveStep >= StoreMoveStep.LI_23_UpdownDown && MoveInfo.MoveStep <= StoreMoveStep.LI_26_AxisToWait)
{
if (MoveInfo.MoveParam.TargetBox.Equals(id))
if (MoveInfo.MoveParam!=null && MoveInfo.MoveParam.TargetBox.Equals(id))
{
return false;
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!