From c4e968254a4f1c5d538a9fd91284b4843ea08198 Mon Sep 17 00:00:00 2001 From: kazelee <1847801760@qq.com> Date: 星期五, 23 五月 2025 10:44:58 +0800 Subject: [PATCH] 内部联调,修复问题,添加取消任务功能 --- device/SnapDevice.cs | 236 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 119 insertions(+), 117 deletions(-) diff --git a/device/SnapDevice.cs b/device/SnapDevice.cs index 754d14f..c465b81 100644 --- a/device/SnapDevice.cs +++ b/device/SnapDevice.cs @@ -7,14 +7,14 @@ using System.Text; using System.Threading.Tasks; -using NetSDKCS; +//using NetSDKCS; // TODO SNAP namespace HH.WCS.Mobox3.AnGang.device { public class SnapDevice { private IntPtr _LoginID = IntPtr.Zero; private IntPtr _PlayID = IntPtr.Zero; //private fSnapRevCallBack _SnapRevCallBack; - private NET_DEVICEINFO_Ex _DeviceInfo = new NET_DEVICEINFO_Ex(); + //private NET_DEVICEINFO_Ex _DeviceInfo = new NET_DEVICEINFO_Ex(); // TODO SNAP private bool _IsSpanCapture = false; //private List<int> _channalList = new List<int>(); @@ -23,7 +23,7 @@ public SnapDevice() { try { //_SnapRevCallBack = new fSnapRevCallBack(SnapRevCallBack); - NETClient.Init(null, IntPtr.Zero, null); + //NETClient.Init(null, IntPtr.Zero, null); // TODO SNAP //NETClient.SetSnapRevCallBack(_SnapRevCallBack, IntPtr.Zero); } catch (Exception ex) { @@ -32,132 +32,134 @@ } ~SnapDevice() { - NETClient.Cleanup(); + //NETClient.Cleanup(); // TODO SNAP } - public void LoadInfo(Config.Snap snap) { - LoadInfo(snap.Ip, snap.Port, snap.Name, snap.Pwd); - } + //public void LoadInfo(Config.Snap snap) { + // LoadInfo(snap.Ip, snap.Port, snap.Name, snap.Pwd); + //} - public void LoadInfo(string ip, int port, string name, string pwd) { - if (IntPtr.Zero == _LoginID) { - ushort uPort = 0; - try { - uPort = Convert.ToUInt16(port); - } - catch { - LogHelper.Info("鍔犺浇Snap锛氱鍙e彿鏍煎紡閿欒"); - return; - } - _LoginID = NETClient.LoginWithHighLevelSecurity(ip, uPort, name, pwd, EM_LOGIN_SPAC_CAP_TYPE.TCP, IntPtr.Zero, ref _DeviceInfo); - if (IntPtr.Zero == _LoginID) { - LogHelper.Info(NETClient.GetLastError()); - return; - } - //_channalList.Clear(); - //for (int i = 0; i < _DeviceInfo.nChanNum; i++) { - // _channalList.Add(i + 1); - //} - _channalMax = _DeviceInfo.nChanNum; - } - else { - NETClient.Logout(_LoginID); - _LoginID = IntPtr.Zero; - if (_IsSpanCapture) { - _IsSpanCapture = false; + // TODO SNAP + + //public void LoadInfo(string ip, int port, string name, string pwd) { + // if (IntPtr.Zero == _LoginID) { + // ushort uPort = 0; + // try { + // uPort = Convert.ToUInt16(port); + // } + // catch { + // LogHelper.Info("鍔犺浇Snap锛氱鍙e彿鏍煎紡閿欒"); + // return; + // } + // _LoginID = NETClient.LoginWithHighLevelSecurity(ip, uPort, name, pwd, EM_LOGIN_SPAC_CAP_TYPE.TCP, IntPtr.Zero, ref _DeviceInfo); + // if (IntPtr.Zero == _LoginID) { + // LogHelper.Info("鐩告満鍒濆鍖栭敊璇細" + NETClient.GetLastError()); + // return; + // } + // //_channalList.Clear(); + // //for (int i = 0; i < _DeviceInfo.nChanNum; i++) { + // // _channalList.Add(i + 1); + // //} + // _channalMax = _DeviceInfo.nChanNum; + // } + // else { + // NETClient.Logout(_LoginID); + // _LoginID = IntPtr.Zero; + // if (_IsSpanCapture) { + // _IsSpanCapture = false; - } - } - } + // } + // } + //} - public bool SnapPictureToFileOK(ref string filePath, int channelIndex = 0) { - if (channelIndex >= _channalMax) { - LogHelper.Info($"閫氶亾鏁�'{channelIndex}' 瓒呭嚭閫氶亾鎬绘暟 '{_channalMax}'"); - //filePath = string.Empty; - return false; - } + //public bool SnapPictureToFileOK(ref string filePath, int channelIndex = 0) { + // if (channelIndex >= _channalMax) { + // LogHelper.Info($"閫氶亾鏁�'{channelIndex}' 瓒呭嚭閫氶亾鎬绘暟 '{_channalMax}'"); + // //filePath = string.Empty; + // return false; + // } - //DateTime now = DateTime.Now; - //string path = AppDomain.CurrentDomain.BaseDirectory + "image"; - //string fileName = string.Format("{0}{1}{2}{3}{4}{5}", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second) + ".jpg"; - //filePath = path + "\\" + fileName; + // //DateTime now = DateTime.Now; + // //string path = AppDomain.CurrentDomain.BaseDirectory + "image"; + // //string fileName = string.Format("{0}{1}{2}{3}{4}{5}", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second) + ".jpg"; + // //filePath = path + "\\" + fileName; - NET_SNAP_PARAMS asyncSnap = new NET_SNAP_PARAMS(); - //asyncSnap.Channel = (uint)this._channalList[channelIndex]; - asyncSnap.Channel = (uint)channelIndex; - asyncSnap.Quality = 6; - asyncSnap.ImageSize = 2; - asyncSnap.mode = 0; - asyncSnap.InterSnap = 0; + // NET_SNAP_PARAMS asyncSnap = new NET_SNAP_PARAMS(); + // //asyncSnap.Channel = (uint)this._channalList[channelIndex]; + // asyncSnap.Channel = (uint)channelIndex; + // asyncSnap.Quality = 6; + // asyncSnap.ImageSize = 2; + // asyncSnap.mode = 0; + // asyncSnap.InterSnap = 0; - NET_IN_SNAP_PIC_TO_FILE_PARAM inParam = new NET_IN_SNAP_PIC_TO_FILE_PARAM { - dwSize = (uint)Marshal.SizeOf(typeof(NET_IN_SNAP_PIC_TO_FILE_PARAM)), - stuParam = asyncSnap, - szFilePath = filePath, - }; + // NET_IN_SNAP_PIC_TO_FILE_PARAM inParam = new NET_IN_SNAP_PIC_TO_FILE_PARAM { + // dwSize = (uint)Marshal.SizeOf(typeof(NET_IN_SNAP_PIC_TO_FILE_PARAM)), + // stuParam = asyncSnap, + // szFilePath = filePath, + // }; - NET_OUT_SNAP_PIC_TO_FILE_PARAM outParam = new NET_OUT_SNAP_PIC_TO_FILE_PARAM() { - dwSize = (uint)Marshal.SizeOf(typeof(NET_OUT_SNAP_PIC_TO_FILE_PARAM)), - dwPicBufLen = 1024000, - szPicBuf = Marshal.AllocHGlobal(1024000), - }; + // NET_OUT_SNAP_PIC_TO_FILE_PARAM outParam = new NET_OUT_SNAP_PIC_TO_FILE_PARAM() { + // dwSize = (uint)Marshal.SizeOf(typeof(NET_OUT_SNAP_PIC_TO_FILE_PARAM)), + // dwPicBufLen = 1024000, + // szPicBuf = Marshal.AllocHGlobal(1024000), + // }; - bool ret = NETClient.SnapPictureToFile(_LoginID, ref inParam, ref outParam, 1000); - if (!ret) { - LogHelper.Info("鎶撳浘澶辫触"); - } - return ret; - } + // bool ret = NETClient.SnapPictureToFile(_LoginID, ref inParam, ref outParam, 1000); + // if (!ret) { + // LogHelper.Info("鎶撳浘澶辫触"); + // } + // return ret; + //} - public bool SnapPictureOk(int channelIndex = 0) { - if (channelIndex >= _channalMax) { - LogHelper.Info($"閫氶亾鏁�'{channelIndex}' 瓒呭嚭閫氶亾鎬绘暟 '{_channalMax}'"); - return false; - } + //public bool SnapPictureOk(int channelIndex = 0) { + // if (channelIndex >= _channalMax) { + // LogHelper.Info($"閫氶亾鏁�'{channelIndex}' 瓒呭嚭閫氶亾鎬绘暟 '{_channalMax}'"); + // return false; + // } - NET_SNAP_PARAMS asyncSnap = new NET_SNAP_PARAMS(); - //asyncSnap.Channel = (uint)this._channalList[channelIndex]; - asyncSnap.Channel = (uint)channelIndex; - asyncSnap.Quality = 6; - asyncSnap.ImageSize = 2; - asyncSnap.mode = 0; - asyncSnap.InterSnap = 0; - bool ret = NETClient.SnapPictureEx(_LoginID, asyncSnap, IntPtr.Zero); - if (!ret) { - LogHelper.Info(NETClient.GetLastError()); - return false; - } - return true; - } + // NET_SNAP_PARAMS asyncSnap = new NET_SNAP_PARAMS(); + // //asyncSnap.Channel = (uint)this._channalList[channelIndex]; + // asyncSnap.Channel = (uint)channelIndex; + // asyncSnap.Quality = 6; + // asyncSnap.ImageSize = 2; + // asyncSnap.mode = 0; + // asyncSnap.InterSnap = 0; + // bool ret = NETClient.SnapPictureEx(_LoginID, asyncSnap, IntPtr.Zero); + // if (!ret) { + // LogHelper.Info(NETClient.GetLastError()); + // return false; + // } + // return true; + //} - private void SnapRevCallBack(IntPtr lLoginID, IntPtr pBuf, uint RevLen, uint EncodeType, uint CmdSerial, IntPtr dwUser) { - string path = AppDomain.CurrentDomain.BaseDirectory + "image"; - if (!Directory.Exists(path)) { - Directory.CreateDirectory(path); - } - if (EncodeType == 10) //.jpg - { - DateTime now = DateTime.Now; - string fileName = string.Format("{0}-{1}-{2}-{3}-{4}-{5}", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second) + ".jpg"; - string filePath = path + "\\" + fileName; - byte[] data = new byte[RevLen]; - Marshal.Copy(pBuf, data, 0, (int)RevLen); - try { - //when the file is operate by local capture will throw expection. - using (FileStream stream = new FileStream(filePath, FileMode.OpenOrCreate)) { - stream.Write(data, 0, (int)RevLen); - stream.Flush(); - stream.Dispose(); - } - } - catch (Exception ex) { - LogHelper.Info($"鍙戠敓浜嗗紓甯革細{ex.Message}"); - return; - } - // 鏇夸唬Demo绋嬪簭鐨凢rame鍥剧墖灞曠ず - LogHelper.Info($"淇濆瓨鍥剧墖鍒帮細{filePath}"); - Process.Start(filePath); - } - } + //private void SnapRevCallBack(IntPtr lLoginID, IntPtr pBuf, uint RevLen, uint EncodeType, uint CmdSerial, IntPtr dwUser) { + // string path = AppDomain.CurrentDomain.BaseDirectory + "image"; + // if (!Directory.Exists(path)) { + // Directory.CreateDirectory(path); + // } + // if (EncodeType == 10) //.jpg + // { + // DateTime now = DateTime.Now; + // string fileName = string.Format("{0}-{1}-{2}-{3}-{4}-{5}", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second) + ".jpg"; + // string filePath = path + "\\" + fileName; + // byte[] data = new byte[RevLen]; + // Marshal.Copy(pBuf, data, 0, (int)RevLen); + // try { + // //when the file is operate by local capture will throw expection. + // using (FileStream stream = new FileStream(filePath, FileMode.OpenOrCreate)) { + // stream.Write(data, 0, (int)RevLen); + // stream.Flush(); + // stream.Dispose(); + // } + // } + // catch (Exception ex) { + // LogHelper.Info($"鍙戠敓浜嗗紓甯革細{ex.Message}"); + // return; + // } + // // 鏇夸唬Demo绋嬪簭鐨凢rame鍥剧墖灞曠ず + // LogHelper.Info($"淇濆瓨鍥剧墖鍒帮細{filePath}"); + // Process.Start(filePath); + // } + //} } } -- Gitblit v1.9.1