Commit 097668dc 张东亮

监控相机换为独立程序

1 个父辈 43914347
......@@ -3,6 +3,8 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
......@@ -13,31 +15,33 @@ namespace OnlineStore.DeviceLibrary
public class IPCameraHelper
{
//"E:\\Codes\\CSharp-Workspace\\MyProject\\WindowsService\\IPCamService\\bin\\Debug\\IPCamService.exe"
static string appPath = AppDomain.CurrentDomain.BaseDirectory;
static string serviceFilePath = ConfigHelper.Config.Get("IPCamService_FilePath", $"{appPath}IPCamService\\IPCamService.exe");
static string serviceName = ConfigHelper.Config.Get("IPCamService_ServiceName", "IPCamService");
/// <summary>
/// 安装服务
/// </summary>
public static void InstallService()
static string baseDir = ConfigHelper.Config.Get("IPCamService_HttpServer", "http://localhost:8088");
public static void StartIPCamService()
{
if (!IsServiceExisted(serviceName))
string appFilePath = ConfigHelper.Config.Get("IPCamService_FilePath", @"D:\IPCamera");
if (Directory.Exists(appFilePath))
{
InstallService(serviceFilePath);
LogUtil.info("安装监控相机服务");
ServiceStart(serviceName);
LogUtil.info("启动监控相机服务");
}
else
{
ServiceStart(serviceName);
LogUtil.info("启动监控相机服务");
var exe = "IPCamera.exe";
try
{
Process process = new Process();
process.StartInfo = new ProcessStartInfo();
process.StartInfo.FileName = exe;
process.StartInfo.WorkingDirectory = appFilePath;
process.Start();
LogUtil.info($"启动软件:{appFilePath}\\{exe}");
}
catch (Exception ex)
{
LogUtil.error($"启动软件失败:{appFilePath}\\{exe}",ex);
}
}
}
static string baseDir = ConfigHelper.Config.Get("IPCameraService_HttpServer", "http://localhost:8088");
public static void StartRecord(string camName, string fileName = "")
{
Task.Factory.StartNew(delegate {
Task.Factory.StartNew(delegate
{
string url = $"{baseDir}/cam/startRecord?camName={camName}&filename={fileName}";
string res = HttpHelper.Get(url);
LogUtil.info($"开始记录视频:{fileName},{res}");
......@@ -46,88 +50,13 @@ namespace OnlineStore.DeviceLibrary
}
public static void StopRecord(string camName)
{
Task.Factory.StartNew(delegate {
Task.Factory.StartNew(delegate
{
string url = $"{baseDir}/cam/stopRecord?camName={camName}";
string res = HttpHelper.Get(url);
LogUtil.info($"停止记录视频:{res}");
});
}
//判断服务是否存在
static bool IsServiceExisted(string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController sc in services)
{
if (sc.ServiceName.ToLower() == serviceName.ToLower())
{
return true;
}
}
return false;
}
//安装服务
static void InstallService(string serviceFilePath)
{
try
{
using (AssemblyInstaller installer = new AssemblyInstaller())
{
installer.UseNewContext = true;
installer.Path = serviceFilePath;
IDictionary savedState = new Hashtable();
installer.Install(savedState);
installer.Commit(savedState);
}
}
catch (Exception ex)
{
LogUtil.error("安装监控相机服务失败", ex);
}
}
//卸载服务
static void UninstallService(string serviceFilePath)
{
using (AssemblyInstaller installer = new AssemblyInstaller())
{
installer.UseNewContext = true;
installer.Path = serviceFilePath;
installer.Uninstall(null);
}
}
//启动服务
static void ServiceStart(string serviceName)
{
try
{
using (ServiceController control = new ServiceController(serviceName))
{
if (control.Status == ServiceControllerStatus.Stopped)
{
control.Start();
}
}
}
catch (Exception ex)
{
LogUtil.error($"启动监控相机服务失败", ex);
}
}
//停止服务
static void ServiceStop(string serviceName)
{
using (ServiceController control = new ServiceController(serviceName))
{
if (control.Status == ServiceControllerStatus.Running)
{
control.Stop();
}
}
}
}
}
......@@ -111,7 +111,7 @@ namespace OnlineStore.DeviceLibrary
//CSVPositionReader<DrawerPosition>.AddCSVFile(drawConfigFile);
XLRStore = new XLRStoreBean(Config, inputConfig, boxConfig);
IPCameraHelper.InstallService();
IPCameraHelper.StartIPCamService();
LogUtil.info("加载 完成!");
return true;
}
......
......@@ -39,15 +39,15 @@ namespace OnlineStore.DeviceLibrary
}
void StartCamera()
{
camera.Open("box_A");
camera.Open("box_B");
IsOpen = true;
camerathread[0] = new Thread(new ParameterizedThreadStart(startMonitor));
camerathread[0].IsBackground = true;
camerathread[0].Start("box_A");
camerathread[1] = new Thread(new ParameterizedThreadStart(startMonitor));
camerathread[1].IsBackground = true;
camerathread[1].Start("box_B");
//camera.Open("box_A");
//camera.Open("box_B");
//IsOpen = true;
//camerathread[0] = new Thread(new ParameterizedThreadStart(startMonitor));
//camerathread[0].IsBackground = true;
//camerathread[0].Start("box_A");
//camerathread[1] = new Thread(new ParameterizedThreadStart(startMonitor));
//camerathread[1].IsBackground = true;
//camerathread[1].Start("box_B");
}
void startMonitor(object obj)
......
......@@ -85,6 +85,7 @@
this.toolStripSeparator17 = 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();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
......@@ -437,7 +438,8 @@
this.toolStripSeparator7,
this.托盘初始化ToolStripMenuItem,
this.toolStripSeparator16,
this.toolStripMenuItem3});
this.toolStripMenuItem3,
this.查看监控ToolStripMenuItem});
this.设置TToolStripMenuItem.Name = "设置TToolStripMenuItem";
this.设置TToolStripMenuItem.Size = new System.Drawing.Size(112, 31);
this.设置TToolStripMenuItem.Text = "设备调试 ";
......@@ -604,6 +606,13 @@
this.启用门禁ToolStripMenuItem.Text = "启用门禁";
this.启用门禁ToolStripMenuItem.Click += new System.EventHandler(this.启用门禁ToolStripMenuItem_Click);
//
// 查看监控ToolStripMenuItem
//
this.查看监控ToolStripMenuItem.Name = "查看监控ToolStripMenuItem";
this.查看监控ToolStripMenuItem.Size = new System.Drawing.Size(224, 32);
this.查看监控ToolStripMenuItem.Text = "查看监控";
this.查看监控ToolStripMenuItem.Click += new System.EventHandler(this.查看监控ToolStripMenuItem_Click);
//
// FrmXLRStore
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
......@@ -694,6 +703,7 @@
private EquipControl ShelfBControl;
private System.Windows.Forms.ToolStripMenuItem 禁用安全光栅ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 启用门禁ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 查看监控ToolStripMenuItem;
}
}
......@@ -784,5 +784,9 @@ namespace OnlineStore.XLRStore
LogUtil.info(Name + " 点击:" + 启用门禁ToolStripMenuItem.Text);
}
private void 查看监控ToolStripMenuItem_Click(object sender, EventArgs e)
{
IPCameraHelper.StartIPCamService();
}
}
}
......@@ -39,10 +39,6 @@
this.lblThisSta = new System.Windows.Forms.Label();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.groupBox6 = new System.Windows.Forms.GroupBox();
this.lblInoutInfo = new System.Windows.Forms.Label();
this.lblMoveInfo = new System.Windows.Forms.Label();
......@@ -57,19 +53,17 @@
this.lblStoreStatus = new System.Windows.Forms.Label();
this.btnStart = new System.Windows.Forms.Button();
this.btnStop = new System.Windows.Forms.Button();
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
this.groupBox1.SuspendLayout();
this.groupBox4.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupDO.SuspendLayout();
this.tabControl1.SuspendLayout();
this.tabPage3.SuspendLayout();
this.groupBox5.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.groupBox6.SuspendLayout();
this.tabPage1.SuspendLayout();
this.panBase.SuspendLayout();
this.tableLayoutPanel3.SuspendLayout();
this.SuspendLayout();
//
// timer1
......@@ -311,14 +305,13 @@
//
// lblThisSta
//
this.lblThisSta.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblThisSta.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblThisSta.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblThisSta.ForeColor = System.Drawing.Color.Red;
this.lblThisSta.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.lblThisSta.Location = new System.Drawing.Point(244, 140);
this.lblThisSta.Location = new System.Drawing.Point(3, 328);
this.lblThisSta.Name = "lblThisSta";
this.lblThisSta.Size = new System.Drawing.Size(736, 28);
this.lblThisSta.Size = new System.Drawing.Size(973, 164);
this.lblThisSta.TabIndex = 246;
this.lblThisSta.Text = "等待启动";
this.lblThisSta.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
......@@ -338,8 +331,6 @@
//
// tabPage3
//
this.tabPage3.Controls.Add(this.groupBox5);
this.tabPage3.Controls.Add(this.groupBox2);
this.tabPage3.Controls.Add(this.groupBox6);
this.tabPage3.Location = new System.Drawing.Point(4, 29);
this.tabPage3.Name = "tabPage3";
......@@ -348,83 +339,36 @@
this.tabPage3.Text = " 设备状态 ";
this.tabPage3.UseVisualStyleBackColor = true;
//
// groupBox5
//
this.groupBox5.Controls.Add(this.pictureBox2);
this.groupBox5.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox5.Location = new System.Drawing.Point(578, 176);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(407, 342);
this.groupBox5.TabIndex = 280;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "B面相机";
//
// pictureBox2
//
this.pictureBox2.BackColor = System.Drawing.Color.DarkGray;
this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox2.Location = new System.Drawing.Point(3, 23);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(401, 316);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.pictureBox1);
this.groupBox2.Dock = System.Windows.Forms.DockStyle.Left;
this.groupBox2.Location = new System.Drawing.Point(0, 176);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(407, 342);
this.groupBox2.TabIndex = 279;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "A面相机";
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.DarkGray;
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(3, 23);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(401, 316);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// groupBox6
//
this.groupBox6.Controls.Add(this.lblInoutInfo);
this.groupBox6.Controls.Add(this.lblMoveInfo);
this.groupBox6.Controls.Add(this.tableLayoutPanel3);
this.groupBox6.Controls.Add(this.lblInstoreList);
this.groupBox6.Controls.Add(this.lblThisSta);
this.groupBox6.Dock = System.Windows.Forms.DockStyle.Top;
this.groupBox6.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox6.Location = new System.Drawing.Point(0, 0);
this.groupBox6.Name = "groupBox6";
this.groupBox6.Size = new System.Drawing.Size(985, 176);
this.groupBox6.Size = new System.Drawing.Size(985, 518);
this.groupBox6.TabIndex = 278;
this.groupBox6.TabStop = false;
this.groupBox6.Text = "当前状态";
//
// lblInoutInfo
//
this.lblInoutInfo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblInoutInfo.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblInoutInfo.ForeColor = System.Drawing.Color.Green;
this.lblInoutInfo.Location = new System.Drawing.Point(2, 21);
this.lblInoutInfo.Location = new System.Drawing.Point(3, 0);
this.lblInoutInfo.Name = "lblInoutInfo";
this.lblInoutInfo.Size = new System.Drawing.Size(977, 23);
this.lblInoutInfo.Size = new System.Drawing.Size(973, 164);
this.lblInoutInfo.TabIndex = 281;
this.lblInoutInfo.Text = "当前出入库:";
//
// lblMoveInfo
//
this.lblMoveInfo.AutoSize = true;
this.lblMoveInfo.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblMoveInfo.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblMoveInfo.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.lblMoveInfo.Location = new System.Drawing.Point(5, 44);
this.lblMoveInfo.Location = new System.Drawing.Point(3, 164);
this.lblMoveInfo.Name = "lblMoveInfo";
this.lblMoveInfo.Size = new System.Drawing.Size(84, 20);
this.lblMoveInfo.Size = new System.Drawing.Size(973, 164);
this.lblMoveInfo.TabIndex = 280;
this.lblMoveInfo.Text = "运动信息:";
//
......@@ -573,6 +517,23 @@
this.btnStop.UseVisualStyleBackColor = false;
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// tableLayoutPanel3
//
this.tableLayoutPanel3.ColumnCount = 1;
this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel3.Controls.Add(this.lblInoutInfo, 0, 0);
this.tableLayoutPanel3.Controls.Add(this.lblMoveInfo, 0, 1);
this.tableLayoutPanel3.Controls.Add(this.lblThisSta, 0, 2);
this.tableLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel3.Location = new System.Drawing.Point(3, 23);
this.tableLayoutPanel3.Name = "tableLayoutPanel3";
this.tableLayoutPanel3.RowCount = 3;
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableLayoutPanel3.Size = new System.Drawing.Size(979, 492);
this.tableLayoutPanel3.TabIndex = 282;
//
// FrmBoxEquip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
......@@ -595,15 +556,11 @@
this.groupDO.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.tabPage3.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.groupBox6.ResumeLayout(false);
this.groupBox6.PerformLayout();
this.tabPage1.ResumeLayout(false);
this.panBase.ResumeLayout(false);
this.panBase.PerformLayout();
this.tableLayoutPanel3.ResumeLayout(false);
this.ResumeLayout(false);
}
......@@ -643,13 +600,10 @@
protected System.Windows.Forms.Button btnStop;
private System.Windows.Forms.TabPage tabPage3;
protected System.Windows.Forms.Button btnDebugAxis;
private System.Windows.Forms.GroupBox groupBox5;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button btnIgnoreCam;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3;
}
}
......@@ -57,14 +57,14 @@ namespace OnlineStore.XLRStore
private void BoxBean_camera_event(CameraArgs cameraArgs)
{
// LogUtil.info($"事件触发{cameraArgs.CamName} 取图");
if(cameraArgs.CamName.Equals("box_A"))
{
pictureBox1.Image = cameraArgs.Image;
}
else if(cameraArgs.CamName.Equals("box_B"))
{
pictureBox2.Image = cameraArgs.Image;
}
//if(cameraArgs.CamName.Equals("box_A"))
//{
// pictureBox1.Image = cameraArgs.Image;
//}
//else if(cameraArgs.CamName.Equals("box_B"))
//{
// pictureBox2.Image = cameraArgs.Image;
//}
}
protected Dictionary<string, IOTextControl> DIControlList = new Dictionary<string, IOTextControl>();
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!