Form1.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using NetSDKCS;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace BeltScaleSystem
  12. {
  13. public partial class Form1 : Form
  14. {
  15. IntPtr _LoginID = IntPtr.Zero;
  16. NET_DEVICEINFO_Ex _DeviceInfo = new NET_DEVICEINFO_Ex();
  17. IntPtr _PlayID = IntPtr.Zero;
  18. IntPtr _AttachID = IntPtr.Zero;
  19. fDisConnectCallBack _DisConnectCallBack;
  20. fHaveReConnectCallBack _ReConnectCallBack;
  21. public Form1()
  22. {
  23. InitializeComponent();
  24. try
  25. {
  26. _DisConnectCallBack = new fDisConnectCallBack(DisConnectCallBack);
  27. _ReConnectCallBack = new fHaveReConnectCallBack(ReConnectCallBack);
  28. NETClient.Init(_DisConnectCallBack, IntPtr.Zero, null);
  29. NETClient.SetAutoReconnect(_ReConnectCallBack, IntPtr.Zero);
  30. // _AnalyzerDataCallBack = new fAnalyzerDataCallBack(AnalyzerDataCallBack);
  31. }
  32. catch (Exception ex)
  33. {
  34. MessageBox.Show(ex.Message);
  35. // Process.GetCurrentProcess().Kill();
  36. return;
  37. }
  38. }
  39. void DisConnectCallBack(IntPtr lLoginID, IntPtr pchDVRIP, int nDVRPort, IntPtr dwUser)
  40. {
  41. this.BeginInvoke(new Action(() =>
  42. {
  43. this.Text = "FaceOpenDoorDemo(人脸开门Demo)---offline(离线)";
  44. }));
  45. }
  46. void ReConnectCallBack(IntPtr lLoginID, IntPtr pchDVRIP, int nDVRPort, IntPtr dwUser)
  47. {
  48. this.BeginInvoke(new Action(() =>
  49. {
  50. this.Text = "FaceOpenDoorDemo(人脸开门Demo)---online(在线)";
  51. }));
  52. }
  53. private void button1_Click(object sender, EventArgs e)
  54. {
  55. if (IntPtr.Zero == _LoginID)
  56. {
  57. ushort port = 0;
  58. try
  59. {
  60. port = Convert.ToUInt16(37777);
  61. }
  62. catch
  63. {
  64. MessageBox.Show("The port value must be 1 -65535(端口值必须是1-65535)");
  65. return;
  66. }
  67. _LoginID = NETClient.LoginWithHighLevelSecurity("192.168.184.202", port, "admin", "admin12345", EM_LOGIN_SPAC_CAP_TYPE.TCP, IntPtr.Zero, ref _DeviceInfo);
  68. if (IntPtr.Zero == _LoginID)
  69. {
  70. MessageBox.Show(NETClient.GetLastError());
  71. return;
  72. }
  73. for (int i = 0; i < _DeviceInfo.nChanNum; i++)
  74. {
  75. this.comboBox_channel.Items.Add(i + 1);
  76. }
  77. //某些型号的设备,比如“BSC”门禁主机,是没有通道的,也不支持监视和订阅
  78. if (this.comboBox_channel.Items.Count > 0)
  79. {
  80. this.comboBox_channel.SelectedIndex = 0;
  81. this.comboBox_channel.Enabled = true;
  82. }
  83. }
  84. else
  85. {
  86. NETClient.Logout(_LoginID);
  87. _LoginID = IntPtr.Zero;
  88. _AttachID = IntPtr.Zero;
  89. _PlayID = IntPtr.Zero;
  90. this.pictureBox1.Refresh();
  91. }
  92. }
  93. private void button2_Click(object sender, EventArgs e)
  94. {
  95. if (IntPtr.Zero == _PlayID)
  96. {
  97. _PlayID = NETClient.RealPlay(_LoginID, comboBox_channel.SelectedIndex, this.pictureBox1.Handle);
  98. if (IntPtr.Zero == _PlayID)
  99. {
  100. MessageBox.Show(NETClient.GetLastError());
  101. return;
  102. }
  103. bool ret = NETClient.RenderPrivateData(_PlayID, true);
  104. if (!ret)
  105. {
  106. MessageBox.Show(NETClient.GetLastError());
  107. return;
  108. }
  109. }
  110. else
  111. {
  112. NETClient.RenderPrivateData(_PlayID, false);
  113. NETClient.StopRealPlay(_PlayID);
  114. _PlayID = IntPtr.Zero;
  115. this.pictureBox1.Refresh();
  116. }
  117. }
  118. }
  119. }