CamerEs2.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using Common;
  2. using MeterPlugInLibrary;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace CarMeterSystem
  10. {
  11. public class CamerEs2
  12. {
  13. public CamerEs2(string _ip, string _port, string _uid, string _pwd)
  14. {
  15. ip = _ip;
  16. port = _port;
  17. uid = _uid;
  18. pwd = _pwd;
  19. _dvr = new HkDvr();
  20. }
  21. private HkDvr _dvr;
  22. bool ret = false;
  23. private string ip = "", port = "", uid = "", pwd = "";
  24. /// <summary>
  25. /// 连接设备
  26. /// </summary>
  27. /// <param name="Ip">IP地址</param>
  28. /// <param name="Port">端口</param>
  29. /// <param name="Uid">用户名</param>
  30. /// <param name="Pwd">密码</param>
  31. public void Connection()
  32. {
  33. if (_dvr.UserId < 0)
  34. {
  35. //IP,PORT,UID,PWD
  36. ret = _dvr.Init(ip + "," + port + "," + uid + "," + pwd);
  37. ret = _dvr.Open();
  38. }
  39. }
  40. private bool startTalk = false;
  41. /// <summary>
  42. /// 打开视频
  43. /// </summary>
  44. /// <param name="picture"></param>
  45. /// <param name="i"></param>
  46. public void RealPlay(PictureBox picture, int i)
  47. {
  48. if (_dvr.UserId > -1)
  49. {
  50. _dvr.RealPlay(i, picture.Handle);
  51. }
  52. }
  53. /// <summary>
  54. /// 关闭视频
  55. /// </summary>
  56. /// <param name="i"></param>
  57. public void StopRealPlay(int i)
  58. {
  59. if (_dvr.UserId > -1)
  60. {
  61. _dvr.StopRealPlay(i);
  62. }
  63. }
  64. /// <summary>
  65. /// 关闭视频
  66. /// </summary>
  67. public void Close()
  68. {
  69. if (_dvr.UserId > -1)
  70. {
  71. _dvr.Close();
  72. }
  73. }
  74. /// <summary>
  75. /// 截图
  76. /// </summary>
  77. /// <param name="voiType">0抓拍机 1一般的摄像头</param>
  78. /// <param name="filePath">文件存储位置及文件名称,文件名称应该是 计量作业编号_计量点_第几张 or 计量作业编号_第几张</param>
  79. /// <returns>是否截图成功,true成功,false失败,异常的话会在logs中写入信息</returns>
  80. public bool CapPic(int voiType, uint channel, string filePath)
  81. {
  82. return _dvr.CapturePicture(voiType, channel, filePath);
  83. /*
  84. _dvr.CapturePicture(1, 1, filePath);
  85. _dvr.CapturePicture(1, 2, filePath.Substring(0, filePath.Length - 5) + "2.jpg");
  86. _dvr.CapturePicture(1, 3, filePath.Substring(0, filePath.Length - 5) + "3.jpg");
  87. return true;
  88. //*/
  89. }
  90. public bool CapPicFromVedio(uint chanel, string filePath)
  91. {
  92. try
  93. {
  94. return _dvr.CapturePicture(chanel, filePath + chanel + ".jpg");
  95. }
  96. catch (Exception)
  97. {
  98. return false;
  99. }
  100. }
  101. /// <summary>
  102. /// 硬盘录像机截图
  103. /// </summary>
  104. /// <param name="filePath"></param>
  105. /// <returns></returns>
  106. public bool CapPicFromVedio(string filePath)
  107. {
  108. try
  109. {
  110. bool a1 = _dvr.CapturePicture(1, filePath + "1.jpg");
  111. bool a2 = _dvr.CapturePicture(2, filePath + "2.jpg");
  112. bool a3 = _dvr.CapturePicture(3, filePath + "3.jpg");
  113. bool a4 = _dvr.CapturePicture(4, filePath + "4.jpg");
  114. bool a5 = _dvr.CapturePicture(5, filePath + "5.jpg");
  115. bool a6 = _dvr.CapturePicture(6, filePath + "6.jpg");
  116. return true;
  117. }
  118. catch (Exception)
  119. {
  120. return false;
  121. }
  122. }
  123. }
  124. }