Commit ba47a86f 张东亮

添加监控相机服务

1 个父辈 bc8ee93d
...@@ -89,7 +89,7 @@ namespace OnlineStore.Common ...@@ -89,7 +89,7 @@ namespace OnlineStore.Common
[MyConfigComment("摄像机名称列表#号分割")] [MyConfigComment("摄像机名称列表#号分割")]
public static MyConfig<string> CameraScan_CameraName = "CameraName"; public static MyConfig<string> CameraScan_CameraName = "CameraName";
[MyConfigComment("扫码类型清单#号分割")] [MyConfigComment("扫码类型清单#号分割")]
public static MyConfig<string> CameraScan_CodeType = "QR Code#Data Matrix ECC 200"; public static MyConfig<string> CameraScan_CodeType = "QR Code#Data Matrix ECC 200#eyem";
[MyConfigComment("扫码学习文件保存目录")] [MyConfigComment("扫码学习文件保存目录")]
public static MyConfig<string> CameraScan_CodeParamPath = "CodeParam"; public static MyConfig<string> CameraScan_CodeParamPath = "CodeParam";
[MyConfigComment("二维码扫码最大数量")] [MyConfigComment("二维码扫码最大数量")]
......
...@@ -59,8 +59,10 @@ ...@@ -59,8 +59,10 @@
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath> <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
...@@ -79,6 +81,7 @@ ...@@ -79,6 +81,7 @@
<Compile Include="DeviceLibrary\Camera.cs" /> <Compile Include="DeviceLibrary\Camera.cs" />
<Compile Include="DeviceLibrary\CylinderManger.cs" /> <Compile Include="DeviceLibrary\CylinderManger.cs" />
<Compile Include="DeviceLibrary\IOMonitor.cs" /> <Compile Include="DeviceLibrary\IOMonitor.cs" />
<Compile Include="DeviceLibrary\IPCameraHelper.cs" />
<Compile Include="DeviceLibrary\I_SafetyDevice.cs" /> <Compile Include="DeviceLibrary\I_SafetyDevice.cs" />
<Compile Include="DeviceLibrary\LiftMonitor.cs" /> <Compile Include="DeviceLibrary\LiftMonitor.cs" />
<Compile Include="DeviceLibrary\LineRunMonitor.cs" /> <Compile Include="DeviceLibrary\LineRunMonitor.cs" />
......
using OnlineStore.Common;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace 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()
{
if (!IsServiceExisted(serviceName))
{
InstallService(serviceFilePath);
LogUtil.info("安装监控相机服务");
ServiceStart(serviceName);
LogUtil.info("启动监控相机服务");
}
else
{
ServiceStart(serviceName);
LogUtil.info("启动监控相机服务");
}
}
static string baseDir = ConfigHelper.Config.Get("IPCameraService_HttpServer", "http://localhost:8088");
public static void StartRecord(string fileName="")
{
string url = $"{baseDir}/cam/startRecord?camName=cam1&filename={fileName}";
string res=HttpHelper.Get(url);
LogUtil.info($"开始记录视频:{fileName},{res}");
}
public static void StopRecord()
{
string url = $"{baseDir}/cam/stopRecord?camName=cam1";
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();
}
}
}
}
}
...@@ -81,6 +81,7 @@ namespace DeviceLibrary ...@@ -81,6 +81,7 @@ namespace DeviceLibrary
} }
else else
{ {
IPCameraHelper.StartRecord($"{WareCode}-{to.posid}");
WareCode = from.Reel.WareCode; WareCode = from.Reel.WareCode;
plateH = from.Reel.PlateH; plateH = from.Reel.PlateH;
From = from.clone(); From = from.clone();
...@@ -96,7 +97,7 @@ namespace DeviceLibrary ...@@ -96,7 +97,7 @@ namespace DeviceLibrary
Fix = BoxStorePosition.GetFixPos(Config, To.Reel); Fix = BoxStorePosition.GetFixPos(Config, To.Reel);
} }
MoveInfo.MoveParam.WareCode = WareCode; MoveInfo.MoveParam.WareCode = WareCode;
IPCameraHelper.StartRecord($"{WareCode}-{From?.posid}-{To?.posid}");
ErrMsgTxt = ""; ErrMsgTxt = "";
return true; return true;
//thread = new Thread(new ThreadStart(Run)); //thread = new Thread(new ThreadStart(Run));
...@@ -370,6 +371,7 @@ namespace DeviceLibrary ...@@ -370,6 +371,7 @@ namespace DeviceLibrary
ErrMsgTxt = ""; ErrMsgTxt = "";
To.posid = ""; To.posid = "";
storeMoveType = StoreMoveType.None; storeMoveType = StoreMoveType.None;
IPCameraHelper.StopRecord();
break; break;
case MoveStep.StoreTS_WaitOutProcess: case MoveStep.StoreTS_WaitOutProcess:
break; break;
......
...@@ -116,6 +116,7 @@ namespace DeviceLibrary ...@@ -116,6 +116,7 @@ namespace DeviceLibrary
IOMonitor.RegisterIO(IO_Type.Reset_BTN, Config, IO_VALUE.HIGH, Reset_BTN, 2500, 100); IOMonitor.RegisterIO(IO_Type.Reset_BTN, Config, IO_VALUE.HIGH, Reset_BTN, 2500, 100);
IOMonitor.RegisterIO(IO_Type.AutoRun_Single, Config, IO_VALUE.HIGH, Run_BTN, 2500, 100); IOMonitor.RegisterIO(IO_Type.AutoRun_Single, Config, IO_VALUE.HIGH, Run_BTN, 2500, 100);
LedProcessInit(); LedProcessInit();
IPCameraHelper.InstallService();
} }
...@@ -248,6 +249,7 @@ namespace DeviceLibrary ...@@ -248,6 +249,7 @@ namespace DeviceLibrary
ServerCM.storeStatus = currnetstoreStatus; ServerCM.storeStatus = currnetstoreStatus;
} }
} }
IPCameraHelper.StopRecord();
LogUtil.info("主线程已退出."); LogUtil.info("主线程已退出.");
} }
public void Start() public void Start()
......
...@@ -41,10 +41,12 @@ namespace TheMachine ...@@ -41,10 +41,12 @@ namespace TheMachine
this.uC_LedConfig1 = new TheMachine.UC.UC_LedConfig(); this.uC_LedConfig1 = new TheMachine.UC.UC_LedConfig();
this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage_set = new System.Windows.Forms.TabPage(); this.tabPage_set = new System.Windows.Forms.TabPage();
this.uC_SetUserPassword1 = new TheMachine.UC_SetUserPassword();
this.tabPage_ledtower = new System.Windows.Forms.TabPage(); this.tabPage_ledtower = new System.Windows.Forms.TabPage();
this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage1 = new System.Windows.Forms.TabPage();
this.fixtureSizeConfigControl1 = new DeviceLibrary.FixtureSizeConfigControl(); this.fixtureSizeConfigControl1 = new DeviceLibrary.FixtureSizeConfigControl();
this.uC_SetUserPassword1 = new TheMachine.UC_SetUserPassword(); this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.tp.SuspendLayout(); this.tp.SuspendLayout();
this.tabControl1.SuspendLayout(); this.tabControl1.SuspendLayout();
this.tabPage_set.SuspendLayout(); this.tabPage_set.SuspendLayout();
...@@ -56,10 +58,10 @@ namespace TheMachine ...@@ -56,10 +58,10 @@ namespace TheMachine
// //
this.chbAutoRun.AutoSize = true; this.chbAutoRun.AutoSize = true;
this.tp.SetColumnSpan(this.chbAutoRun, 2); this.tp.SetColumnSpan(this.chbAutoRun, 2);
this.chbAutoRun.Location = new System.Drawing.Point(10, 166); this.chbAutoRun.Location = new System.Drawing.Point(10, 169);
this.chbAutoRun.Margin = new System.Windows.Forms.Padding(10); this.chbAutoRun.Margin = new System.Windows.Forms.Padding(10);
this.chbAutoRun.Name = "chbAutoRun"; this.chbAutoRun.Name = "chbAutoRun";
this.chbAutoRun.Size = new System.Drawing.Size(84, 16); this.chbAutoRun.Size = new System.Drawing.Size(94, 17);
this.chbAutoRun.TabIndex = 1; this.chbAutoRun.TabIndex = 1;
this.chbAutoRun.Text = "开机自启动"; this.chbAutoRun.Text = "开机自启动";
this.chbAutoRun.UseVisualStyleBackColor = true; this.chbAutoRun.UseVisualStyleBackColor = true;
...@@ -68,7 +70,7 @@ namespace TheMachine ...@@ -68,7 +70,7 @@ namespace TheMachine
// //
this.cb_tempsensorport.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cb_tempsensorport.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cb_tempsensorport.FormattingEnabled = true; this.cb_tempsensorport.FormattingEnabled = true;
this.cb_tempsensorport.Location = new System.Drawing.Point(139, 6); this.cb_tempsensorport.Location = new System.Drawing.Point(144, 6);
this.cb_tempsensorport.Margin = new System.Windows.Forms.Padding(6); this.cb_tempsensorport.Margin = new System.Windows.Forms.Padding(6);
this.cb_tempsensorport.Name = "cb_tempsensorport"; this.cb_tempsensorport.Name = "cb_tempsensorport";
this.cb_tempsensorport.Size = new System.Drawing.Size(121, 20); this.cb_tempsensorport.Size = new System.Drawing.Size(121, 20);
...@@ -82,7 +84,7 @@ namespace TheMachine ...@@ -82,7 +84,7 @@ namespace TheMachine
this.label_tempsensor.Location = new System.Drawing.Point(10, 10); this.label_tempsensor.Location = new System.Drawing.Point(10, 10);
this.label_tempsensor.Margin = new System.Windows.Forms.Padding(10); this.label_tempsensor.Margin = new System.Windows.Forms.Padding(10);
this.label_tempsensor.Name = "label_tempsensor"; this.label_tempsensor.Name = "label_tempsensor";
this.label_tempsensor.Size = new System.Drawing.Size(107, 12); this.label_tempsensor.Size = new System.Drawing.Size(118, 13);
this.label_tempsensor.TabIndex = 3; this.label_tempsensor.TabIndex = 3;
this.label_tempsensor.Text = "温湿度控制器端口:"; this.label_tempsensor.Text = "温湿度控制器端口:";
this.label_tempsensor.TextAlign = System.Drawing.ContentAlignment.TopRight; this.label_tempsensor.TextAlign = System.Drawing.ContentAlignment.TopRight;
...@@ -90,7 +92,7 @@ namespace TheMachine ...@@ -90,7 +92,7 @@ namespace TheMachine
// button_positiontool // button_positiontool
// //
this.tp.SetColumnSpan(this.button_positiontool, 2); this.tp.SetColumnSpan(this.button_positiontool, 2);
this.button_positiontool.Location = new System.Drawing.Point(10, 74); this.button_positiontool.Location = new System.Drawing.Point(10, 76);
this.button_positiontool.Margin = new System.Windows.Forms.Padding(10); this.button_positiontool.Margin = new System.Windows.Forms.Padding(10);
this.button_positiontool.Name = "button_positiontool"; this.button_positiontool.Name = "button_positiontool";
this.button_positiontool.Size = new System.Drawing.Size(181, 36); this.button_positiontool.Size = new System.Drawing.Size(181, 36);
...@@ -103,10 +105,10 @@ namespace TheMachine ...@@ -103,10 +105,10 @@ namespace TheMachine
// //
this.lbl_hmdstate.AutoSize = true; this.lbl_hmdstate.AutoSize = true;
this.tp.SetColumnSpan(this.lbl_hmdstate, 2); this.tp.SetColumnSpan(this.lbl_hmdstate, 2);
this.lbl_hmdstate.Location = new System.Drawing.Point(10, 42); this.lbl_hmdstate.Location = new System.Drawing.Point(10, 43);
this.lbl_hmdstate.Margin = new System.Windows.Forms.Padding(10); this.lbl_hmdstate.Margin = new System.Windows.Forms.Padding(10);
this.lbl_hmdstate.Name = "lbl_hmdstate"; this.lbl_hmdstate.Name = "lbl_hmdstate";
this.lbl_hmdstate.Size = new System.Drawing.Size(53, 12); this.lbl_hmdstate.Size = new System.Drawing.Size(59, 13);
this.lbl_hmdstate.TabIndex = 5; this.lbl_hmdstate.TabIndex = 5;
this.lbl_hmdstate.Tag = "not"; this.lbl_hmdstate.Tag = "not";
this.lbl_hmdstate.Text = "当前状态"; this.lbl_hmdstate.Text = "当前状态";
...@@ -141,17 +143,17 @@ namespace TheMachine ...@@ -141,17 +143,17 @@ namespace TheMachine
this.tp.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tp.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tp.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tp.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tp.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tp.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tp.Size = new System.Drawing.Size(266, 192); this.tp.Size = new System.Drawing.Size(276, 196);
this.tp.TabIndex = 6; this.tp.TabIndex = 6;
// //
// cb_usefixpos // cb_usefixpos
// //
this.cb_usefixpos.AutoSize = true; this.cb_usefixpos.AutoSize = true;
this.tp.SetColumnSpan(this.cb_usefixpos, 2); this.tp.SetColumnSpan(this.cb_usefixpos, 2);
this.cb_usefixpos.Location = new System.Drawing.Point(10, 130); this.cb_usefixpos.Location = new System.Drawing.Point(10, 132);
this.cb_usefixpos.Margin = new System.Windows.Forms.Padding(10); this.cb_usefixpos.Margin = new System.Windows.Forms.Padding(10);
this.cb_usefixpos.Name = "cb_usefixpos"; this.cb_usefixpos.Name = "cb_usefixpos";
this.cb_usefixpos.Size = new System.Drawing.Size(96, 16); this.cb_usefixpos.Size = new System.Drawing.Size(107, 17);
this.cb_usefixpos.TabIndex = 6; this.cb_usefixpos.TabIndex = 6;
this.cb_usefixpos.Text = "启用校准库位"; this.cb_usefixpos.Text = "启用校准库位";
this.cb_usefixpos.UseVisualStyleBackColor = true; this.cb_usefixpos.UseVisualStyleBackColor = true;
...@@ -180,6 +182,8 @@ namespace TheMachine ...@@ -180,6 +182,8 @@ namespace TheMachine
// //
// tabPage_set // tabPage_set
// //
this.tabPage_set.Controls.Add(this.button2);
this.tabPage_set.Controls.Add(this.button1);
this.tabPage_set.Controls.Add(this.uC_SetUserPassword1); this.tabPage_set.Controls.Add(this.uC_SetUserPassword1);
this.tabPage_set.Controls.Add(this.tp); this.tabPage_set.Controls.Add(this.tp);
this.tabPage_set.Location = new System.Drawing.Point(4, 22); this.tabPage_set.Location = new System.Drawing.Point(4, 22);
...@@ -190,6 +194,15 @@ namespace TheMachine ...@@ -190,6 +194,15 @@ namespace TheMachine
this.tabPage_set.Text = "常规设置"; this.tabPage_set.Text = "常规设置";
this.tabPage_set.UseVisualStyleBackColor = true; this.tabPage_set.UseVisualStyleBackColor = true;
// //
// uC_SetUserPassword1
//
this.uC_SetUserPassword1.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uC_SetUserPassword1.Location = new System.Drawing.Point(335, 8);
this.uC_SetUserPassword1.Margin = new System.Windows.Forms.Padding(5);
this.uC_SetUserPassword1.Name = "uC_SetUserPassword1";
this.uC_SetUserPassword1.Size = new System.Drawing.Size(533, 596);
this.uC_SetUserPassword1.TabIndex = 7;
//
// tabPage_ledtower // tabPage_ledtower
// //
this.tabPage_ledtower.Controls.Add(this.uC_LedConfig1); this.tabPage_ledtower.Controls.Add(this.uC_LedConfig1);
...@@ -220,14 +233,25 @@ namespace TheMachine ...@@ -220,14 +233,25 @@ namespace TheMachine
this.fixtureSizeConfigControl1.Size = new System.Drawing.Size(1010, 708); this.fixtureSizeConfigControl1.Size = new System.Drawing.Size(1010, 708);
this.fixtureSizeConfigControl1.TabIndex = 0; this.fixtureSizeConfigControl1.TabIndex = 0;
// //
// uC_SetUserPassword1 // button1
// //
this.uC_SetUserPassword1.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.button1.Location = new System.Drawing.Point(53, 270);
this.uC_SetUserPassword1.Location = new System.Drawing.Point(335, 8); this.button1.Name = "button1";
this.uC_SetUserPassword1.Margin = new System.Windows.Forms.Padding(5); this.button1.Size = new System.Drawing.Size(156, 59);
this.uC_SetUserPassword1.Name = "uC_SetUserPassword1"; this.button1.TabIndex = 8;
this.uC_SetUserPassword1.Size = new System.Drawing.Size(533, 596); this.button1.Text = "开始记录监控";
this.uC_SetUserPassword1.TabIndex = 7; this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click_2);
//
// button2
//
this.button2.Location = new System.Drawing.Point(53, 365);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(156, 59);
this.button2.TabIndex = 9;
this.button2.Text = "停止记录监控";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
// //
// SettingControl // SettingControl
// //
...@@ -263,5 +287,7 @@ namespace TheMachine ...@@ -263,5 +287,7 @@ namespace TheMachine
private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabPage tabPage1;
private DeviceLibrary.FixtureSizeConfigControl fixtureSizeConfigControl1; private DeviceLibrary.FixtureSizeConfigControl fixtureSizeConfigControl1;
private UC_SetUserPassword uC_SetUserPassword1; private UC_SetUserPassword uC_SetUserPassword1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
} }
} }
...@@ -124,5 +124,15 @@ namespace TheMachine ...@@ -124,5 +124,15 @@ namespace TheMachine
{ {
} }
private void button1_Click_2(object sender, EventArgs e)
{
DeviceLibrary.IPCameraHelper.StartRecord("manual");
}
private void button2_Click(object sender, EventArgs e)
{
DeviceLibrary.IPCameraHelper.StopRecord();
}
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!