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("启动监控相机服务");
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}");
}
else
catch (Exception ex)
{
ServiceStart(serviceName);
LogUtil.info("启动监控相机服务");
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();
}
}
}
......@@ -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!