Commit 19246ac9 张东亮

添加监控相机保存

1 个父辈 392ed316
...@@ -66,8 +66,10 @@ ...@@ -66,8 +66,10 @@
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<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.Web" /> <Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" /> <Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
...@@ -77,6 +79,7 @@ ...@@ -77,6 +79,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="deviceLibrary\IPCameraHelper.cs" />
<Compile Include="manager\agvClient\AgvClient.cs" /> <Compile Include="manager\agvClient\AgvClient.cs" />
<Compile Include="manager\BufferDataManager.cs" /> <Compile Include="manager\BufferDataManager.cs" />
<Compile Include="manager\StoreManager.cs" /> <Compile Include="manager\StoreManager.cs" />
...@@ -185,6 +188,10 @@ ...@@ -185,6 +188,10 @@
<Project>{43cdd09e-fcf3-4960-a01d-3bbfe9933122}</Project> <Project>{43cdd09e-fcf3-4960-a01d-3bbfe9933122}</Project>
<Name>Common</Name> <Name>Common</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\ConfigHelper\ConfigHelper\ConfigHelper.csproj">
<Project>{290182db-d949-434e-9ff7-c59bde3f433a}</Project>
<Name>ConfigHelper</Name>
</ProjectReference>
<ProjectReference Include="..\HuichuanLibrary\HuichuanLibrary.csproj"> <ProjectReference Include="..\HuichuanLibrary\HuichuanLibrary.csproj">
<Project>{c9575c5e-9d4b-4b4f-be41-926652b8985f}</Project> <Project>{c9575c5e-9d4b-4b4f-be41-926652b8985f}</Project>
<Name>HuichuanLibrary</Name> <Name>HuichuanLibrary</Name>
......
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 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()
{
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 camName, string fileName = "")
{
string url = $"{baseDir}/cam/startRecord?camName={camName}&filename={fileName}";
string res = HttpHelper.Get(url);
LogUtil.info($"开始记录视频:{fileName},{res}");
}
public static void StopRecord(string camName)
{
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();
}
}
}
}
}
using log4net; using OnlineStore.Common;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary; using OnlineStore.LoadCSVLibrary;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary namespace OnlineStore.DeviceLibrary
...@@ -117,6 +111,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -117,6 +111,7 @@ namespace OnlineStore.DeviceLibrary
//CSVPositionReader<DrawerPosition>.AddCSVFile(drawConfigFile); //CSVPositionReader<DrawerPosition>.AddCSVFile(drawConfigFile);
XLRStore = new XLRStoreBean(Config, inputConfig, boxConfig); XLRStore = new XLRStoreBean(Config, inputConfig, boxConfig);
IPCameraHelper.InstallService();
LogUtil.info("加载 完成!"); LogUtil.info("加载 完成!");
return true; return true;
} }
......
...@@ -62,74 +62,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -62,74 +62,16 @@ namespace OnlineStore.DeviceLibrary
{ {
Bitmap bmp = AcqImage(name); Bitmap bmp = AcqImage(name);
if (bmp != null) if (bmp != null)
//{
// if (IsRecord)
// {
// cnt++;
// Task.Factory.StartNew(delegate
// {
// SaveImage("box_A", cnt);
// });
// Task.Factory.StartNew(delegate
// {
// SaveImage("box_B", cnt);
// });
// if ((DateTime.Now - dateTime).TotalMinutes > 2)
// StopRecord();
// }
camera_event?.Invoke(new CameraArgs(name, bmp)); camera_event?.Invoke(new CameraArgs(name, bmp));
// }
Thread.Sleep(300); Thread.Sleep(300);
} }
} }
void StopCamera()
{
IsOpen = false;
camera.Close();
camera.Dispose();
}
public Bitmap AcqImage(string camName) public Bitmap AcqImage(string camName)
{ {
Bitmap bitmap = camera.GetImage(camName); Bitmap bitmap = camera.GetImage(camName);
return bitmap; return bitmap;
} }
string imgPath = ConfigAppSettings.GetValue(Setting_Init.ImagePath); string imgPath = ConfigAppSettings.GetValue(Setting_Init.ImagePath);
//public void SaveImage(string camName)
//{
// try
// {
// if (MoveInfo.MoveParam == null)
// {
// string path = Application.StartupPath + imgPath + camName + "\\" + DateTime.Now.ToString("yyyyMMdd");
// if (AutoSaveImage)
// {
// if (!System.IO.Directory.Exists(path))
// Directory.CreateDirectory(path);
// camera.SaveImage(camName, path, DateTime.Now.ToString("hhmmssfff"), System.Drawing.Imaging.ImageFormat.Bmp);
// }
// }
// else
// {
// if (MoveInfo.MoveParam.PosInfo != null)
// {
// InOutPosInfo inOutPosInfo = MoveInfo.MoveParam.PosInfo;
// string path = Application.StartupPath + imgPath + camName + "\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId;
// if (AutoSaveImage)
// {
// if (!System.IO.Directory.Exists(path))
// Directory.CreateDirectory(path);
// camera.SaveImage(camName, path, $"{inOutPosInfo.barcode}-{MoveInfo.MoveType}-{DateTime.Now.ToString("hhmmssfff")}", System.Drawing.Imaging.ImageFormat.Bmp);
// }
// }
// }
// }
// catch (Exception ex)
// {
// LogUtil.error($"保存{camName}图片失败", ex);
// }
//}
public void SaveImage(string camName) public void SaveImage(string camName)
{ {
try try
...@@ -175,69 +117,33 @@ namespace OnlineStore.DeviceLibrary ...@@ -175,69 +117,33 @@ namespace OnlineStore.DeviceLibrary
} }
#region 监控保存 #region 监控保存
void SaveImage(string camName, int count) public const string boxACamName = "box_A";
public const string boxBCamName = "box_B";
public void StartRecord(string boxAFileName, string boxBFileName)
{ {
try StartBoxARecord(boxAFileName);
{ StartBoxBRecord(boxBFileName);
if (inOutPosInfo != null)
{
string path = Application.StartupPath + imgPath + camName + "\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId;
if (!System.IO.Directory.Exists(path))
Directory.CreateDirectory(path);
Task.Factory.StartNew(() =>
{
camera.SaveImage(camName, path, $"{count.ToString().PadLeft(4, '0')}", System.Drawing.Imaging.ImageFormat.Bmp);
});
}
}
catch (Exception ex)
{
LogUtil.error($"保存{camName}图片失败", ex);
}
} }
FFMPEG ffmpegA = new FFMPEG(); public void StartBoxARecord(string filename)
FFMPEG ffmpegB = new FFMPEG();
bool IsRecord = false;
int cnt = 0;
InOutPosInfo inOutPosInfo = null;
DateTime dateTime = DateTime.Now;
/// <summary>
/// 开始记录
/// </summary>
public void StartRecord(bool isTest = false)
{ {
//if (isTest) IPCameraHelper.StartRecord(boxACamName, filename);
//{ }
// inOutPosInfo = new InOutPosInfo("code" + DateTime.Now.ToString("mmssfff"), DateTime.Now.ToString("yyyyMMddhh")); public void StartBoxBRecord(string filename)
//} {
//else IPCameraHelper.StartRecord(boxBCamName, filename);
//{ }
// inOutPosInfo = MoveInfo.MoveParam.PosInfo.ToCopy(); public void StopBoxARecord()
//} {
//cnt = 0; IPCameraHelper.StopRecord(boxACamName);
//string inputfolderA = Application.StartupPath + imgPath + "box_A\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId; }
//string inputfolderB = Application.StartupPath + imgPath + "box_B\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId; public void StopBoxBRecord()
//string outputfolderA = Application.StartupPath + "\\Videos\\box_A\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId; {
//string outputfolderB = Application.StartupPath + "\\Videos\\box_B\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId; IPCameraHelper.StopRecord(boxBCamName);
//ffmpegA.SetParam(inputfolderA, outputfolderA, $"{DateTime.Now.ToString("hhmmss")}_{inOutPosInfo.barcode}.mp4");
//ffmpegB.SetParam(inputfolderB, outputfolderB, $"{DateTime.Now.ToString("hhmmss")}_{inOutPosInfo.barcode}.mp4");
//dateTime = DateTime.Now;
//IsRecord = true;
} }
/// <summary>
/// 停止记录
/// </summary>
public void StopRecord() public void StopRecord()
{ {
if (!IsRecord) StopBoxARecord();
return; StopBoxBRecord();
IsRecord = false;
//LogUtil.info("监控视频开始转换");
//Task task1 = ffmpegA.ConvertImgsToMp4();
//Task task2 = ffmpegB.ConvertImgsToMp4();
//Task.WaitAll(new Task[] { task1, task2 }, TimeSpan.FromMinutes(1));
//LogUtil.info("监控视频转换完成");
} }
#endregion #endregion
} }
......
...@@ -430,7 +430,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -430,7 +430,14 @@ namespace OnlineStore.DeviceLibrary
LogInfo($"入库 {MoveInfo.SLog}:入库结束[{MoveInfo.MoveParam.PosInfo.PosId}][耗时:{(DateTime.Now - startTime).TotalSeconds.ToString("f2")}秒][{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]"); LogInfo($"入库 {MoveInfo.SLog}:入库结束[{MoveInfo.MoveParam.PosInfo.PosId}][耗时:{(DateTime.Now - startTime).TotalSeconds.ToString("f2")}秒][{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
MoveInfo.EndMove(); MoveInfo.EndMove();
//停止记录 //停止记录
StopRecord(); if (CheckASide())
{
StopBoxARecord();
}
else
{
StopBoxBRecord();
}
AutoInout.InOutEndProcess(this, MoveType.InStore); AutoInout.InOutEndProcess(this, MoveType.InStore);
} }
...@@ -451,7 +458,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -451,7 +458,14 @@ namespace OnlineStore.DeviceLibrary
LogInfo($"入库 {MoveInfo.SLog}:入库结束[{MoveInfo.MoveParam.PosInfo.PosId}][耗时:{(DateTime.Now - startTime).TotalSeconds.ToString("f2")}秒][{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]"); LogInfo($"入库 {MoveInfo.SLog}:入库结束[{MoveInfo.MoveParam.PosInfo.PosId}][耗时:{(DateTime.Now - startTime).TotalSeconds.ToString("f2")}秒][{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
MoveInfo.EndMove(); MoveInfo.EndMove();
//停止记录 //停止记录
StopRecord(); if (CheckASide())
{
StopBoxARecord();
}
else
{
StopBoxBRecord();
}
AutoInout.InOutEndProcess(this, MoveType.InStore); AutoInout.InOutEndProcess(this, MoveType.InStore);
break; break;
} }
......
...@@ -300,9 +300,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -300,9 +300,16 @@ namespace OnlineStore.DeviceLibrary
break; break;
case StepEnum.SO_20_Finish: case StepEnum.SO_20_Finish:
SetBoxStatus(DeviceStatus.StoreOnline, RunStatus.Runing); SetBoxStatus(DeviceStatus.StoreOnline, RunStatus.Runing);
MoveInfo.EndMove();
//停止记录 //停止记录
StopRecord(); if (CheckASide())
{
StopBoxARecord();
}
else
{
StopBoxBRecord();
}
MoveInfo.EndMove();
AutoInout.InOutEndProcess(this, MoveType.OutStore); AutoInout.InOutEndProcess(this, MoveType.OutStore);
break; break;
} }
......
...@@ -946,7 +946,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -946,7 +946,14 @@ namespace OnlineStore.DeviceLibrary
// LogInfo("LoadInoutParam:" + JsonHelper.SerializeObject(param.MoveP)); // LogInfo("LoadInoutParam:" + JsonHelper.SerializeObject(param.MoveP));
MoveInfo.NewMove(MoveType.InStore, param); MoveInfo.NewMove(MoveType.InStore, param);
///开始记录 ///开始记录
StartRecord(); if (CheckASide())
{
StartBoxARecord($"IN-{param.PosInfo.barcode}-{param.PosInfo.PosId}");
}
else
{
StartBoxBRecord($"IN-{param.PosInfo.barcode}-{param.PosInfo.PosId}");
}
IgnoreCamDect = false; IgnoreCamDect = false;
SetBoxStatus(DeviceStatus.InStoreExecute, RunStatus.Busy, param.PosInfo.PosId, param.PosInfo.barcode); SetBoxStatus(DeviceStatus.InStoreExecute, RunStatus.Busy, param.PosInfo.PosId, param.PosInfo.barcode);
MoveInfo.NextMoveStep(StepEnum.SI_00_StartInstore); MoveInfo.NextMoveStep(StepEnum.SI_00_StartInstore);
...@@ -1175,7 +1182,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -1175,7 +1182,14 @@ namespace OnlineStore.DeviceLibrary
CurHSerial = param.PosInfo.hSerial; CurHSerial = param.PosInfo.hSerial;
LogInfo("启动出库【" + param.PosInfo.ToStr() + "】 "); LogInfo("启动出库【" + param.PosInfo.ToStr() + "】 ");
///开始记录 ///开始记录
StartRecord(); if (CheckASide())
{
StartBoxARecord($"OUT-{param.PosInfo.barcode}-{param.PosInfo.PosId}");
}
else
{
StartBoxBRecord($"OUT-{param.PosInfo.barcode}-{param.PosInfo.PosId}");
}
//LogInfo("LoadInoutParam:" + JsonHelper.SerializeObject(param.MoveP)); //LogInfo("LoadInoutParam:" + JsonHelper.SerializeObject(param.MoveP));
IgnoreCamDect = false; IgnoreCamDect = false;
MoveInfo.NextMoveStep(StepEnum.SO_00_StartOutstore); MoveInfo.NextMoveStep(StepEnum.SO_00_StartOutstore);
......
...@@ -549,26 +549,6 @@ namespace OnlineStore.XLRStore ...@@ -549,26 +549,6 @@ namespace OnlineStore.XLRStore
{ {
boxBean.IgnoreCamDect = true; boxBean.IgnoreCamDect = true;
} }
private void button1_Click(object sender, EventArgs e)
{
boxBean.StartRecord(true);
}
private void button2_Click(object sender, EventArgs e)
{
boxBean.StopRecord();
}
private void chbDebug_CheckedChanged_1(object sender, EventArgs e)
{
}
private void chbDebug_CheckedChanged_2(object sender, EventArgs e)
{
}
} }
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!