private void buttonGet_Click(object sender, EventArgs e) { UInt32 dwRetLen = 0; IntPtr pSnapCfg = new IntPtr(); pSnapCfg = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)) * 32); bool bRet = DHClient.DHGetDevConfig(m_nLoginID, CONFIG_COMMAND.DH_DEV_SNAP_CFG, 0, pSnapCfg, (UInt32)Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)) * 32, ref dwRetLen, 1000); if (!bRet) { //AfxMessageBox(ConvertString("Get snap configure failed.")); MessageBox.Show("获取抓图配置失败!"); return; } else { for (int i = 0; i < 32; ++i) { m_stuSnapCfg[i] = (DHDEV_SNAP_CFG)Marshal.PtrToStructure((IntPtr)((UInt32)pSnapCfg + i * Marshal.SizeOf(typeof(DHDEV_SNAP_CFG))) , typeof(DHDEV_SNAP_CFG)); } } OnSelchangeComboChannel(null, null); }
private void Login_Click(object sender, EventArgs e) { if (!m_bInit) { MessageBox.Show("库初始化失败"); return; } //设备用户信息获得 NET_DEVICEINFO deviceInfo = new NET_DEVICEINFO(); int error = 0; m_nLoginID = DHClient.DHLogin(this.textBoxIP.Text.ToString(), ushort.Parse(this.textBoxPort.Text.ToString()), this.textBoxUser.Text.ToString(), this.textBoxPsw.Text.ToString(), out deviceInfo, out error); if (m_nLoginID > 0) { this.Login.Enabled = false; this.Logout.Enabled = true; m_nChannelNum = deviceInfo.byChanNum; for (int i = 0; i < m_nChannelNum; ++i) { this.comboBoxChannel.Items.Add(i.ToString()); } //query json ability. Int32 dwRetLen = 0; IntPtr pDevEnable = new IntPtr(); pDevEnable = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DH_DEV_ENABLE_INFO))); bool bRet = DHClient.DHQuerySystemInfo(m_nLoginID, DH_SYS_ABILITY.ABILITY_DEVALL_INFO, pDevEnable, Marshal.SizeOf(typeof(DH_DEV_ENABLE_INFO)), ref dwRetLen, 1000); if (bRet == false) { //MessageBox.Show(ConvertString("Query device ability failed.")); MessageBox.Show("查询设备能力失败"); return; } DH_DEV_ENABLE_INFO devEnable = new DH_DEV_ENABLE_INFO(); devEnable = (DH_DEV_ENABLE_INFO)Marshal.PtrToStructure(pDevEnable, typeof(DH_DEV_ENABLE_INFO)); m_bJSON = devEnable.IsFucEnable[(Int32)DH_FUN_SUPPORT.EN_JSON_CONFIG] > 0 ? true : false; if (m_bJSON == false) { int nRetLen = 0; IntPtr pStuSnapAttr = new IntPtr(); pStuSnapAttr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DH_SNAP_ATTR_EN))); bool nRet = DHClient.DHQueryDevState(m_nLoginID, (int)DHClient.DH_DEVSTATE_SNAP , pStuSnapAttr, Marshal.SizeOf(typeof(DH_SNAP_ATTR_EN)), ref nRetLen, 1000); if (nRet == false || nRetLen != Marshal.SizeOf(typeof(DH_SNAP_ATTR_EN))) { MessageBox.Show("获取抓图能力集失败!"); return; } else { m_stuSnapAttr = (DH_SNAP_ATTR_EN)Marshal.PtrToStructure(pStuSnapAttr, typeof(DH_SNAP_ATTR_EN)); } } else //json { InitSnapConfigExUI(0); } IntPtr pSnapCfg = new IntPtr(); pSnapCfg = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)) * 32); UInt32 dwRetConfig = 0; bRet = DHClient.DHGetDevConfig(m_nLoginID, CONFIG_COMMAND.DH_DEV_SNAP_CFG, -1, pSnapCfg, (UInt32)Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)) * 32, ref dwRetConfig, 1000); if (!bRet) { MessageBox.Show("获取抓图配置失败!"); return; } else { for (int i = 0; i < 32; ++i) { m_stuSnapCfg[i] = (DHDEV_SNAP_CFG)Marshal.PtrToStructure((IntPtr)((UInt32)pSnapCfg + i * Marshal.SizeOf(typeof(DHDEV_SNAP_CFG))) , typeof(DHDEV_SNAP_CFG)); } } if (this.comboBoxChannel.Items.Count > 0) { this.comboBoxChannel.SelectedIndex = 0; } this.buttonGet.Enabled = true; this.buttonSet.Enabled = true; this.buttonStart.Enabled = true; this.buttonStop.Enabled = true; } }