/// <summary> /// 初始化函数 /// </summary> /// <param name="strServerIP">视频IP</param> /// <param name="iChannel">通道号</param> /// <param name="strUserName">用户名</param> /// <param name="strPsw">密码</param> /// <param name="strPath">抓图存储路径 如:\\LoadWeightPic\\FrontImage.jpg</param> public void Initialize(string strServerIP, int iChannel, string strUserName, string strPsw, string strPath) { try { if (IsLogin) { disConnect = new fDisConnect(DisConnectEvent); DHClient.DHInit(disConnect, IntPtr.Zero); DHClient.DHSetEncoding(LANGUAGE_ENCODING.gb2312); deviceInfo = new NET_DEVICEINFO(); int iLoginError = 0; iLogin = DHClient.DHLogin(strServerIP, ushort.Parse("37777"), strUserName, strPsw, out deviceInfo, out iLoginError); IsLogin = false; } _strPath = strPath; _strServerIP = strServerIP; _iChannel = iChannel; iRealPlay = DHClient.DHRealPlay(iLogin, _iChannel, this.Pic.Handle); } catch (Exception ex) { Log.WriteLog("大华视频显示控件-初始化:", ex); } }
/// <summary> /// 添加设备2处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddDevice2_Click(object sender, EventArgs e) { frm_AddDevice fAddDev = new frm_AddDevice(); fAddDev.ShowDialog(); try { if (fAddDev.blnOKEnter == true) { //设备用户信息获得 deviceInfo = new NET_DEVICEINFO(); int error = 0; //设备2登录:注意登录ID pLoginID2 = DHClient.DHLogin(fAddDev.cmbDevIP.Text.ToString(), ushort.Parse(fAddDev.txtDevProt.Text.ToString()), fAddDev.txtName.Text.ToString(), fAddDev.txtPassword.Text.ToString(), out deviceInfo, out error); //是否登录成功判断 if (pLoginID2 != 0) { MessageBox.Show("设备2登录成功!", "提示"); } else { MessageBox.Show("设备2登录失败!", "提示"); } } } catch { } }
private void login(int cantidadVentanas) { //this.initPantallas(cantidadVentanas); //this.inicializarVentanas(cantidadVentanas); int error = 0; if (pLoginID == 0) { deviceInfo = new NET_DEVICEINFO(); pLoginID = DHClient.DHLogin(this.ip, this.port, this.user, this.pass, out deviceInfo, out error); } if (pLoginID != 0) { this.startButtons(false); pRealPlayHandle = new int[deviceInfo.byChanNum]; cantidadCamaras = deviceInfo.byChanNum; comboBoxCamaras.Items.Clear(); for (int i = 0; i < cantidadCamaras; i++) { comboBoxCamaras.Items.Add((i + 1).ToString()); } //this.play(this.channel); comboBoxCamaras.SelectedIndex = this.channel; comboBoxVentanas.SelectedIndex = this.getIndexCantidadVentanas(cantidadVentanas); realPlay(); } else { /*btnStartRealPlay.Enabled = false; * btnLogin.Enabled = true; * btnLogout.Enabled = false;*/ this.startButtons(true); if (DHClient.LastOperationInfo.errCode == "-2147483548") { MessageBox.Show("Error de conexion a la camara: Password incorrecto!", pMsgTitle); } else if (DHClient.LastOperationInfo.errCode == "-2147483547") { MessageBox.Show("Error de conexion a la camara: Usuario incorrecto!", pMsgTitle); } else if (DHClient.LastOperationInfo.errCode == "-2147483541") { MessageBox.Show("Error de conexion a la camara! No fue posible conectar a la IP o puerto especificado", pMsgTitle); } else { MessageBox.Show("Error de conexion a la camara:" + DHClient.LastOperationInfo.errCode, pMsgTitle); } Application.Exit(); } }
/// <summary> /// [设备用户登录]按钮按下 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUserLogin_Click(object sender, EventArgs e) { frm_AddDevice fAddDev = new frm_AddDevice(); fAddDev.ShowDialog(); //DHClient.DHSetShowException(true); try { if (fAddDev.blnOKEnter == true) { //设备用户信息获得 deviceInfo = new NET_DEVICEINFO(); int error = 0; pLoginID = DHClient.DHLogin(fAddDev.cmbDevIP.Text.ToString(), ushort.Parse(fAddDev.txtDevProt.Text.ToString()), fAddDev.txtName.Text.ToString(), fAddDev.txtPassword.Text.ToString(), out deviceInfo, out error); if (pLoginID != 0) { pPlayBackHandle = new int[deviceInfo.byChanNum]; //画面按钮有效性控制 pRealPlayHandle = null; btnRealPlay.Text = StringUtil.ConvertString("实时监视开始"); btnUserLogin.Enabled = false; btnRealPlay.Enabled = true; btnPlayBackByTime.Enabled = true; gpbPlayBackControl.Enabled = false; btnUserLogout.Enabled = true; gpbPTZControl.Enabled = false; btnPlayByRecordFile.Enabled = true; cmbChannelSelect.Items.Clear(); for (int i = 0; i < deviceInfo.byChanNum; i++) { cmbChannelSelect.Items.Add(i.ToString()); } } else { MessageBox.Show(DHClient.LastOperationInfo.ToString(pErrInfoFormatStyle), pMsgTitle); btnUserLogin_Click(null, null); } } } catch { //报最后一次操作的错误信息 MessageBox.Show(DHClient.LastOperationInfo.ToString(pErrInfoFormatStyle), pMsgTitle); btnUserLogin_Click(null, null); } }
/// <summary> /// 用户登录按钮按下处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUserLogin_Click(object sender, EventArgs e) { string strBtn = btnUserLogin.Text; if (strBtn == Utility.StringUtil.ConvertString("设备用户登录")) { frm_AddDevice fLogin = new frm_AddDevice(); fLogin.ShowDialog(); if (fLogin.blnOKEnter == true) { //设备用户信息获得 deviceInfo = new NET_DEVICEINFO(); int error = 0; //设备用户登录 pLoginID = DHClient.DHLogin(fLogin.cmbDevIP.Text.ToString(), ushort.Parse(fLogin.txtDevProt.Text.ToString()), fLogin.txtName.Text.ToString(), fLogin.txtPassword.Text.ToString(), out deviceInfo, out error); if (pLoginID != 0) { strUserName = fLogin.txtDevName.Text; btnUserLogin.BackColor = Color.Yellow; btnUserLogin.Text = StringUtil.ConvertString("设备用户注销"); grbMain.Enabled = true; } else { //报最后一次操作的错误信息 MessageUtil.ShowMsgBox(StringUtil.ConvertString(DHClient.LastOperationInfo.errMessage, "ErrorMessage"), StringUtil.ConvertString(pMsgTitle)); } } } else if (strBtn == Utility.StringUtil.ConvertString("设备用户注销")) { bool result = DHClient.DHLogout(pLoginID); if (result == false) { //报最后一次操作的错误信息 MessageUtil.ShowMsgBox(StringUtil.ConvertString(DHClient.LastOperationInfo.errMessage, "ErrorMessage"), StringUtil.ConvertString(pMsgTitle)); } btnUserLogin.BackColor = Color.Transparent; btnUserLogin.Text = StringUtil.ConvertString("设备用户登录"); grbMain.Enabled = false; Utility.StringUtil.InitControlText(this); } }
public bool Init(CameraData _cameraData) { cameraData = _cameraData; server.start(Convert.ToInt32(cameraData.Code)); disConnect = new fDisConnect(DisConnectEvent); DHClient.DHInit(disConnect, IntPtr.Zero); DHClient.DHSetEncoding((int)LANGUAGE_ENCODING.gb2312);//字符编码格式设置,默认为gb2312字符编码,如果为其他字符编码请设置 pLoginID = DHClient.DHLogin(cameraData.IP, (ushort)cameraData.Port, cameraData.UserName, cameraData.Pwd, out deviceInfo, out error); // cameraData.control.Text = pLoginID + ""; if (pLoginID != 0) { // (cameraData.control as UserControl).Text = pLoginID.ToString(); pPlayBackHandle = new int[deviceInfo.byChanNum]; //画面按钮有效性控制 pRealPlayHandle = null; //for (int i = 0; i < deviceInfo.byChanNum; i++) //{ // cmbChannelSelect.Items.Add(i.ToString()); // //cmbChannelSelect.Items.Add((i+1).ToString()); //} NET_SDK_CLIENTINFO lsc = new NET_SDK_CLIENTINFO(); lsc.lChannel = deviceInfo.byChanNum; //预览的通道 lsc.streamType = 1; // 码流 lsc.hPlayWnd = cameraData.Handle; //pictureBox.Handle lLiveHandle = (IntPtr)DHClient.DHRealPlay(pLoginID, 0, lsc.hPlayWnd); //ID 通道 ,Picture句柄 IntPtr userdata = (IntPtr)Convert.ToInt32(_cameraData.Code); DHClient.DHSetRealDataCallBack((int)lLiveHandle, fd, userdata); // DHPlay.PLAY_OpenStream(tongdao, IntPtr.Zero, 0, (UInt32)900 * 1024); //播放的部分 //bool b2 = DHPlay.DHPlayControl(PLAY_COMMAND.OpenStream, tongdao, IntPtr.Zero, 0, 900 * 1024); //DHPlay.DHSetStreamOpenMode(tongdao, PLAY_MODE.STREAME_FILE); //DHPlay.DHPlayControl(0, tongdao, _cameraData.control.Handle); return(true); } else { return(false); } }
/// <summary> /// 初始化设备 /// </summary> private bool Init() { //初始化SDK if (initialized == false) { //DHClient.DHInit(disConnect, IntPtr.Zero); //DHClient.DHSetAutoReconnect(onlineMsg, IntPtr.Zero); //initialized = true; //这里不直接使用DHClient初始化,是因为DHClient的disConnect和onlineMsg只支持一个事件回调, //所以这里使用管理器的事件处理,在管理器中使用DHClient初始化 DaHuaSDKManager.GetInstance().DisConnectEventHandle -= disConnect; DaHuaSDKManager.GetInstance().DisConnectEventHandle += disConnect; DaHuaSDKManager.GetInstance().OnlineMsgEventHandle -= onlineMsg; DaHuaSDKManager.GetInstance().OnlineMsgEventHandle += onlineMsg; DaHuaSDKManager.GetInstance().InitSDK(); initialized = true; } if (initialized == false) { return(false); } //登入设备 if (m_nLoginID == 0) { NET_DEVICEINFO deviceInfo = new NET_DEVICEINFO(); int error = 0; m_nLoginID = DHClient.DHLogin(VideoSource.MediaSource, (ushort)VideoSource.StreamPort , VideoSource.UserName, VideoSource.Password, out deviceInfo, out error); } if (m_nLoginID == 0) { return(false); } return(true); }
private void ConnectAllDevices() { while (true) { foreach (CarPlateDevice device in _Devices) { //登入设备 if (device.m_nLoginID == 0 && device.VideoSource != null) { NET_DEVICEINFO deviceInfo = new NET_DEVICEINFO(); int error = 0; device.m_nLoginID = DHClient.DHLogin(device.IP, (ushort)device.VideoSource.StreamPort , device.VideoSource.UserName, device.VideoSource.Password, out deviceInfo, out error); if (device.m_nLoginID != 0) { //订阅事件 device.m_nRealLoadPic = DHClient.DHRealLoadPicture(device.m_nLoginID, device.VideoID, EventIvs.EVENT_IVS_ALL, anaCallback, 0); device.State = 1; } } } Action action = delegate() { ShowItemsOnGrid(_Devices); }; if (this.InvokeRequired) { this.Invoke(action); } else { action(); } Thread.Sleep(30 * 1000); } }
//摄像头视频显示 private void RealPlay() { try { disConnect = new fDisConnect(DisConnectEvent); DHClient.DHInit(disConnect, IntPtr.Zero); DHClient.DHSetEncoding(LANGUAGE_ENCODING.gb2312);//字符编码格式设置,默认为gb2312字符编码,如果为其他字符编码请设置 pRealPlayHandle = null; deviceInfo = new NET_DEVICEINFO(); int error = 0; pLoginID = DHClient.DHLogin(Program.g_localVedioIp, ushort.Parse(Program.g_localVedioPort), Program.g_localVadioUsername, Program.g_localVadioPassword, out deviceInfo, out error); if (pLoginID != 0) { pPlayBackHandle = new int[deviceInfo.byChanNum]; //画面按钮有效性控制 pRealPlayHandle = null; pRealPlayHandle = new int[deviceInfo.byChanNum]; for (int i = 0; i < deviceInfo.byChanNum; i++) { switch (i) { case 0: //通道0的实时监视 pictureBox17.Invoke((MethodInvoker) delegate { pRealPlayHandle[i] = DHClient.DHRealPlay(pLoginID, i, pictureBox17.Handle); }); break; case 1: //通道1的实时监视 pictureBox18.Invoke((MethodInvoker) delegate { pRealPlayHandle[i] = DHClient.DHRealPlay(pLoginID, i, pictureBox18.Handle); }); break; case 2: //通道2的实时监视 pictureBox19.Invoke((MethodInvoker) delegate { pRealPlayHandle[i] = DHClient.DHRealPlay(pLoginID, i, pictureBox19.Handle); }); break; case 3: //通道3的实时监视 pictureBox20.Invoke((MethodInvoker) delegate { pRealPlayHandle[i] = DHClient.DHRealPlay(pLoginID, i, pictureBox20.Handle); }); break; case 4: //通道4的实时监视 pictureBox21.Invoke((MethodInvoker) delegate { pRealPlayHandle[i] = DHClient.DHRealPlay(pLoginID, i, pictureBox21.Handle); }); break; } } } } catch (Exception vedioError) { Program.WriteLog("调用摄像头异常:" + vedioError.ToString()); } }
private void SingleVideoDisplayForm_Load(object sender, EventArgs e) { picRealPlay1.Visible = false; picRealPlay2.Visible = false; picRealPlay3.Visible = false; picRealPlay4.Visible = false; picRealPlay5.Visible = false; picRealPlay6.Visible = false; switch (b) { case 0: groupBox1.Text = "一号电机视频监控"; break; case 1: groupBox1.Text = "二号电机视频监控"; break; case 2: groupBox1.Text = "三号电机视频监控"; break; case 3: groupBox1.Text = "控制室视频监控"; break; case 4: groupBox1.Text = "过道视频监控"; break; default: break; } int[] pPlayBackHandle; NET_DEVICEINFO deviceInfo; fDisConnect disConnect; disConnect = new fDisConnect(DisConnectEvent); //DHClient.initialized = false; DHClient.DHInit(disConnect, IntPtr.Zero); DHClient.DHSetEncoding(LANGUAGE_ENCODING.gb2312);//字符编码格式设置,默认为gb2312字符编码,如果为其他字符编码请设置 deviceInfo = new NET_DEVICEINFO(); int error = 0; pLoginID = DHClient.DHLogin(IP, Port, Username, Password, out deviceInfo, out error); if (pLoginID != 0) { pPlayBackHandle = new int[5]; //画面按钮有效性控制 btnPlayByRecordFile.Enabled = true; RealPlay(true, b); } else { MessageBox.Show(DHClient.LastOperationInfo.ToString(pErrInfoFormatStyle), pMsgTitle); } gpbPlayBackControl.Enabled = false; picRealPlay6.VisibleChanged += new EventHandler((o, j) => { if (picRealPlay6.Visible == false) { gpbPlayBackControl.Enabled = false; btnPlayBackByTime.Enabled = true; btnPlayByRecordFile.Enabled = true; } else {//如果回放激活 gpbPlayBackControl.Enabled = true; } }); }
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; } }