| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace RailLocalMeter
- {
- /// <summary>
- /// 海康视频流获取及截图操作
- /// </summary>
- public class CamerEs
- {
- public CamerEs(string _ip, string _port, string _uid, string _pwd)
- {
- ip = _ip;
- port = _port;
- uid = _uid;
- pwd = _pwd;
- _dvr = new HkDvr();
- }
- private HkDvr _dvr;
- bool ret = false;
- private string ip = "", port = "", uid = "", pwd = "";
- /// <summary>
- /// 连接设备
- /// </summary>
- /// <param name="Ip">IP地址</param>
- /// <param name="Port">端口</param>
- /// <param name="Uid">用户名</param>
- /// <param name="Pwd">密码</param>
- public void Connection()
- {
- if (_dvr.UserId < 0)
- {
- //IP,PORT,UID,PWD
- ret = _dvr.Init(ip + "," + port + "," + uid + "," + pwd);
- ret = _dvr.Open();
- }
- }
- private bool startTalk = false;
- /// <summary>
- /// 打开视频
- /// </summary>
- /// <param name="picture"></param>
- /// <param name="i"></param>
- public void RealPlay(PictureBox picture, int i)
- {
- if (_dvr.UserId > -1)
- {
- _dvr.RealPlay(i, picture.Handle);
- }
- }
- /// <summary>
- /// 关闭视频
- /// </summary>
- /// <param name="i"></param>
- public void StopRealPlay(int i)
- {
- if (_dvr.UserId > -1)
- {
- _dvr.StopRealPlay(i);
- }
- }
- /// <summary>
- /// 关闭视频
- /// </summary>
- public void Close()
- {
- if (_dvr.UserId > -1)
- {
- _dvr.Close();
- }
- }
- /// <summary>
- /// 截图
- /// </summary>
- /// <param name="voiType">0抓拍机 1一般的摄像头</param>
- /// <param name="filePath">文件存储位置及文件名称,文件名称应该是 计量作业编号_计量点_第几张 or 计量作业编号_第几张</param>
- /// <returns>是否截图成功,true成功,false失败,异常的话会在logs中写入信息</returns>
- public bool CapPic(uint channel, string filePath)
- {
- return _dvr.CapturePicture(channel, filePath);
- /*
- _dvr.CapturePicture(1, 1, filePath);
- _dvr.CapturePicture(1, 2, filePath.Substring(0, filePath.Length - 5) + "2.jpg");
- _dvr.CapturePicture(1, 3, filePath.Substring(0, filePath.Length - 5) + "3.jpg");
- return true;
- //*/
- }
- public bool CapPicFromVedio(uint chanel, string filePath)
- {
- try
- {
- return _dvr.CapturePicture(chanel, filePath + chanel + ".jpg");
- }
- catch (Exception)
- {
- return false;
- }
- }
- /// <summary>
- /// 硬盘录像机截图
- /// </summary>
- /// <param name="filePath"></param>
- /// <returns></returns>
- public bool CapPicFromVedio(string filePath)
- {
- try
- {
- bool a1 = _dvr.CapturePicture(1, filePath + "1.jpg");
- bool a2 = _dvr.CapturePicture(2, filePath + "2.jpg");
- bool a3 = _dvr.CapturePicture(3, filePath + "3.jpg");
- bool a4 = _dvr.CapturePicture(4, filePath + "4.jpg");
- bool a5 = _dvr.CapturePicture(5, filePath + "5.jpg");
- bool a6 = _dvr.CapturePicture(6, filePath + "6.jpg");
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
- /// <summary>
- /// 打开对讲
- /// </summary>
- /// <returns></returns>
- public bool StartTalk()
- {
- if (_dvr.UserId > -1 && !startTalk)
- {
- _dvr.StartTalk();
- startTalk = true;
- }
- return true;
- }
- /// <summary>
- /// 关闭对讲
- /// </summary>
- /// <returns></returns>
- public bool StopTalk()
- {
- if (_dvr.UserId > -1 && startTalk)
- {
- _dvr.StopTalk();
- startTalk = false;
- return true;
- }
- return true;
- }
- public bool SendVoice(string soundName)
- {
- bool ret = false;
- _dvr.SetVolume(0xffff);
- bool voiceOpend = false;
- if (_dvr.VoiceHandle > -1) //播放语音前,需要关闭对讲
- {
- _dvr.StopTalk();
- voiceOpend = true;
- }
- bool b = _dvr.OpenSound();
- string path = AppConfigCache.path + "\\Sound\\" + soundName + ".wav";
- ret = _dvr.SendVoiceData(path);
- _dvr.CloseSound();
- if (voiceOpend)
- {
- _dvr.StartTalk();
- }
- return ret;
- }
- public bool SendVoiceWrw(string soundName)
- {
- bool ret = false;
- _dvr.SetVolume(0xffff);
- bool voiceOpend = false;
- if (_dvr.VoiceHandle > -1) //播放语音前,需要关闭对讲
- {
- _dvr.StopTalk();
- voiceOpend = true;
- }
- bool b = _dvr.OpenSound();
- string path = AppConfigCache.path + "\\Sound\\" + soundName + ".wav";
- for (int i = 0; i < 5; i++)
- {
- ret = _dvr.SendVoiceDataWrw(path);
- if (ret) break;
- }
- _dvr.CloseSound();
- if (voiceOpend)
- {
- _dvr.StartTalk();
- }
- //LogController.GetInstance().WriteLog(33, $"发送语音\"{soundName}\",结果:{ret}");
- return ret;
- }
- }
- }
|