/// <summary> /// 录像 /// </summary> public void record(Panel panel) { if (m_mainForm.RecordPath.Length == 0) { MessageBox.Show("未设置录像路径"); return; } foreach (OneDialog dlg in m_dialogs) { if (dlg.panel == panel) { dlg.recording = !dlg.recording; if (dlg.recording) { try { //录像 int ret = BVCU.ManagedLayer_CuSetRecordStorageParam(m_bvsdkHandle, dlg.dialogHandle, Encoding.UTF8.GetBytes(m_mainForm.RecordPath), 3600); BVCU.FAILED(ret); } catch { MessageBox.Show("保存文件失败"); dlg.recording = false; } } else { BVCU.ManagedLayer_CuSetRecordStorageParam(m_bvsdkHandle, dlg.dialogHandle, Encoding.UTF8.GetBytes(""), 0); } break; } } }
public int openGpsDialog(Pu pu, int channelNo) { foreach (OneDialog dlg in m_gpsDialogs) { if (dlg.pu.id.Equals(pu.id, StringComparison.CurrentCultureIgnoreCase) && dlg.channelNo == channelNo) { LogHelper.LogHelper.RecordLog(51, string.Format("已经发送打开[{0}, {1}]Gps通道的命令", pu.puName, channelNo)); return(-1); } } IntPtr dialog = IntPtr.Zero; int ret = BVCU.ManagedLayer_CuOpenGpsDialog(m_bvsdkHandle, ref dialog, m_session.Handle, Encoding.UTF8.GetBytes(pu.id), channelNo, m_bvsdkEventHandler.gpsDialog_OnEvent, m_bvsdkEventHandler.gpsDialog_OnData); if (BVCU.BVCU_RESULT_S_OK == ret) { OneDialog dlg = new OneDialog(); dlg.dialogHandle = dialog; dlg.channelNo = channelNo; dlg.pu = pu; m_gpsDialogs.Add(dlg); LogHelper.LogHelper.RecordLog(3, string.Format("正在打开{0}, {1}的Gps通道...", pu.puName, channelNo)); return(0); } else { LogHelper.LogHelper.RecordLog(3, string.Format("打开{0}, {1}的Gps通道失败, 错误码:{2}", pu.puName, channelNo, ret)); } return(-1); }
void Server_ProcNotifyChannelInfo(IntPtr session, IntPtr ptPuId, IntPtr ptPuName, int iStatus, ref BVCU_PUOneChannelInfo channel, int iFinished) { LogHelper.LogHelper.RecordLog(100, "=========================================="); string puId = Marshal.PtrToStringAnsi(ptPuId, BVCU.BVCU_MAX_ID_LEN + 1).Split('\0')[0]; string puName = Marshal.PtrToStringAnsi(ptPuName, BVCU.BVCU_MAX_NAME_LEN + 1).Split('\0')[0]; bool bNeedClearGps = false; bool bNeedClearTsp = false; //如果是设备下线,清除列表中信息,清除接收数据信息 if (iStatus == BVCU.BVCU_ONLINE_STATUS_OFFLINE) { m_dialog.clearDialog(puId, channel.iChannelIndex); bNeedClearGps = m_dialog.clearGpsDialog(puId, channel.iChannelIndex); bNeedClearTsp = m_dialog.clearTspDialog(puId, channel.iChannelIndex); m_session.clearGpsDataList(puId, channel.iChannelIndex, bNeedClearGps | bNeedClearTsp); m_session.OnRemovePu(puId); } Channel chnl = new Channel(); getChannel(chnl, channel, iStatus); m_session.OnGetPu(puName, puId, chnl); if (BVCU.TRUE(iFinished)) { m_session.OnGetPuListFinished(); } return; }
/// <summary> /// 截图 /// </summary> public void capture(Panel panel) { if (m_mainForm.CapturePath.Length == 0) { MessageBox.Show("未设置截图路径"); return; } try { foreach (OneDialog dlg in m_dialogs) { if (dlg.panel == panel) { string path = m_mainForm.CapturePath + "\\" + dlg.timeStamp.Year + dlg.timeStamp.Month.ToString().PadLeft(2, '0') + dlg.timeStamp.Day.ToString().PadLeft(2, '0') + dlg.timeStamp.Hour.ToString().PadLeft(2, '0') + dlg.timeStamp.Minute.ToString().PadLeft(2, '0') + dlg.timeStamp.Second.ToString().PadLeft(2, '0') + dlg.timeStamp.Millisecond.ToString().PadLeft(3, '0') + ".jpg"; //截图 int ret = BVCU.ManagedLayer_CuSnapshot(m_bvsdkHandle, dlg.dialogHandle, Encoding.UTF8.GetBytes(path), 85); BVCU.FAILED(ret); break; } } } catch { MessageBox.Show("截图失败"); } }
/// <summary> /// 登录成功后调用;获取设备列表 /// </summary> void procOnLoginOk() { Console.WriteLine("登录服务器 {0} 成功", m_server.ip); releaseReloginTimer(); m_iLoginRetryCount = 0; m_bServerRetry = true; int result = 0; for (int i = 0; i < BVCU.FAIL_RETRY_TIMES; i++)//试BVCU.FAIL_RETRY_TIMES(=10)次-L { result = BVCU.ManagedLayer_CuGetPuList(m_bvsdkHandle, m_server.sessionHandle, m_bvsdkEventHandler.cmd_OnGetPuList); if (!BVCU.SUCCEEDED(result)) { Thread.Sleep(BVCU.FAIL_RETRY_INTERVAL); } else { Console.WriteLine("获取设备列表成功"); return; } } MessageBox.Show("获取设备列表失败"); }
void displayFont(IntPtr dialog, Int64 timeStamp) { OneDialog cuDlg = m_dialog.getDialog(dialog); if (null == cuDlg) { return; } if (cuDlg.panel != null) { AfterRenderIndex idx = getIdx(dialog); if (idx == null) { return; } cuDlg.panel.BeginInvoke(refreshAfterRenderIdx, new object[] { cuDlg, timeStamp }); BVCU.Color color = new BVCU.Color(0xFFFFFFFF); try { BVCU.BVDisplay_DisplayFont(idx.dispHandle, idx.index, ref idx.dispRect, ref color, cuDlg.timeStamp.ToString("yyyy'/'MM'/'dd HH:mm:ss")); } catch { } } }
Dialog m_dialog; // 全局Dialog类引用 public AfterRender(Dialog dlg) { m_dialog = dlg; afterRenderDisplayFont = new BVCU.DisplayFont(displayFont); BVCU.ManagedLayer_DispSetDisplayFontFunc(afterRenderDisplayFont); m_afterRenderList = new ArrayList(); refreshAfterRenderIdx = new DelegateCuDialogAndTimeStampIn(procRefreshAfterRenderIdx); createFontInDialog = new DelegateCuDialogIn(procCreateFontInDialog); }
void Cmd_OnGetPuList(IntPtr session, IntPtr ptPuId, IntPtr ptPuName, int iStatus, ref BVCU_PUOneChannelInfo channel, int iFinished) { Console.WriteLine("获取设备列表回调执行"); string puId = Marshal.PtrToStringAnsi(ptPuId, BVCU.BVCU_MAX_ID_LEN + 1).Split('\0')[0]; string puName = Marshal.PtrToStringAnsi(ptPuName, BVCU.BVCU_MAX_NAME_LEN + 1).Split('\0')[0]; Byte[] bpuid = new Byte[BVCU.BVCU_MAX_ID_LEN + 1]; Byte[] bpuname = new Byte[BVCU.BVCU_MAX_NAME_LEN + 1]; Marshal.Copy(ptPuId, bpuid, 0, BVCU.BVCU_MAX_ID_LEN + 1); Marshal.Copy(ptPuName, bpuname, 0, BVCU.BVCU_MAX_ID_LEN + 1); //设备名称 string spuid = System.Text.Encoding.UTF8.GetString(bpuid).Split('\0')[0]; //设备ID string spuname = System.Text.Encoding.UTF8.GetString(bpuname).Split('\0')[0]; //如果获取设备列表结束 if (BVCU.TRUE(iFinished)) { m_session.OnGetPuListFinished(); } //创建通道 Channel chnl = new Channel(); if (iStatus == BVCU.BVCU_ONLINE_STATUS_OFFLINE) { chnl.online = false; } else { chnl.online = true; } //填入通道信息 getChannel(chnl, channel, iStatus); //修改设备列表,添加设备或添加通道 m_session.OnGetPu(spuname, spuid, chnl); /*if (channel.szName.Equals("gps")) * { * chnl = new Session.Channel(); * channel.szName = "TSP"; * channel.iPTZIndex = 15; * channel.iMediaDir = 32; * channel.iChannelIndex = 65792; * if (iStatus == BVCU.BVCU_ONLINE_STATUS_OFFLINE) * { * chnl.online = false; * } * else * { * chnl.online = true; * } * getChannel(chnl, channel); * m_session.OnGetPu(puName, puId, chnl); * }*/ }
/// <summary> /// 设置当前窗口(panel)的播放音量 /// </summary> public void setVolume(Panel panel, int volume) { foreach (OneDialog dialog in m_dialogs) { if (dialog.panel == panel) { BVCU.ManagedLayer_CuPlayVolume(m_bvsdkHandle, dialog.dialogHandle, volume); break; } } }
/// <summary> /// 构造函数 /// </summary> /// <param name="mainform">主窗口</param> public BVCUSdkOperator(MainWinForm mainform) { m_mainForm = mainform; BVCU.FAILED(BVCU.ManagedLayer_CuInit(ref m_bvcuSdkHandle));//初始化库 m_eventHandler = new EventHandler(); m_session = new Session(m_bvcuSdkHandle, m_eventHandler, m_mainForm); m_dialog = new Dialog(m_bvcuSdkHandle, m_eventHandler, m_mainForm, m_session); m_eventHandler.init(m_bvcuSdkHandle, m_session, m_dialog); m_session.SetBVCUSdk(this); }
/// <summary> /// 关闭浏览对话框(Diglog) /// </summary> /// <param name="panel">需要关闭的浏览框对应的Panel</param> public void closeBrowse(Panel panel) { foreach (OneDialog dlg in m_dialogs) { if (dlg.panel == panel) { BVCU.ManagedLayer_CuCloseDialog(m_bvsdkHandle, dlg.dialogHandle); m_dialogs.Remove(dlg); break; } } }
void getChannel(Channel chnl, BVCU_PUOneChannelInfo channel) { chnl.channelName = channel.szName; BVCU.AVDirection avDir = BVCU.GetAVDirection(channel.iMediaDir); chnl.audioPlayback = avDir.audioRecv; chnl.speak = avDir.audioSnd; chnl.video = avDir.videoRecv; chnl.ptzIdx = channel.iPTZIndex; chnl.channelNo = channel.iChannelIndex; }
public void OnResizeDialog() { foreach (OneDialog dlg in m_dialogs) { BVRect rect = new BVRect(); rect.left = dlg.panel.DisplayRectangle.Left; rect.top = dlg.panel.DisplayRectangle.Top; rect.right = dlg.panel.DisplayRectangle.Right; rect.bottom = dlg.panel.DisplayRectangle.Bottom; BVCU.ManagedLayer_CuResizeDialogWindow(m_bvsdkHandle, dlg.dialogHandle, ref rect); } }
/// <summary> /// 打开对话(Dialog) /// </summary> /// <param name="pu"></param> /// <param name="channelNo"></param> /// <param name="panel"></param> public void openBrowse(Pu pu, int channelNo, Panel panel) { try { BVCU_DialogControlParam_Network net = new BVCU_DialogControlParam_Network(0, 5, 1, 3); BVRect dispRect = new BVRect(0, 0, panel.ClientRectangle.Height, panel.ClientRectangle.Width); OneDialog dlg = new OneDialog(); foreach (Channel channel in pu.channelList) { int volume = -1; if (channel.channelNo == channelNo) { if (channel.audioPlayback) { volume = 0; } //打开视屏浏览, 主要参数:sdkHandle、sessionHandle、puID、channelNo、显示区域的大小 int ret = BVCU.ManagedLayer_CuBrowsePu(m_bvsdkHandle, //sdk handle ref dlg.dialogHandle, //dialog handle m_session.Handle, //session handle Encoding.UTF8.GetBytes(pu.id), //pu id channelNo, //channel no panel.Handle, //pannel handle ref dispRect, //上下左右,矩形 volume, //音量 0, //single Rec File Sec Encoding.UTF8.GetBytes(""), //rec File Dir true, //videoTrans ref net, //network 时延 m_bvsdkEventHandler.dialog_OnDialogEvent, m_bvsdkEventHandler.dialog_OnStorageEvent); BVCU.FAILED(ret); LogHelper.LogHelper.RecordLog(4, string.Format("打开[{0}, {1}]的视屏预览通道", pu.puName, channelNo)); break; } } dlg.panel = panel; dlg.pu = pu; dlg.channelNo = channelNo; m_dialogs.Add(dlg); } catch { panel.ContextMenuStrip = null; MessageBox.Show("打开预览失败"); } }
public void closeGpsDialog(string puId, int channelNo) { foreach (OneDialog dlg in m_gpsDialogs) { if (dlg.pu.id.Equals(puId, StringComparison.CurrentCultureIgnoreCase) && dlg.channelNo == channelNo) { int iresult = BVCU.ManagedLayer_CuCloseDialog(m_bvsdkHandle, dlg.dialogHandle); if (0 == iresult) { m_gpsDialogs.Remove(dlg); } return; } } }
public void closeTspDialog(OneDialog tspDialog) { if (null == tspDialog) { return; } foreach (OneDialog dlg in m_tspDialogs) { if (dlg == tspDialog && dlg.dialogHandle != null) { BVCU.ManagedLayer_CuCloseDialog(m_bvsdkHandle, dlg.dialogHandle); m_tspDialogs.Remove(dlg); break; } } m_tspDialogs.Clear(); }
void procCreateFontInDialog(OneDialog dialog) { AfterRenderIndex idx = new AfterRenderIndex(); idx.type = INDEX_TYPE.FONT; idx.dispHandle = dialog.panel.Handle; idx.dialogHandle = dialog.dialogHandle; if (!BVCU.SUCCEEDED(BVCU.BVDisplay_CreateFont(idx.dispHandle, ref idx.index, 15, "Arial"))) { return; } BVCU.FontDisplayMode effect = new BVCU.FontDisplayMode(); effect.size = BVCU.FONT_DISPLAY_MODE_SIZE; effect.fontColor = new BVCU.Color(0xFFFFFFFF); effect.backColor = new BVCU.Color(0xFF000000); effect.effect = BVCU.BVDISPLAY_TEXT_EFFECT_OUTLINE; effect.effectSize = 1; BVCU.BVDisplay_SetFontDisplayMode(idx.dispHandle, idx.index, ref effect); m_afterRenderList.Add(idx); }
public void openTalkOnly(Pu pu, int channelNo, Panel panel) { try { BVCU_DialogControlParam_Network net = new BVCU_DialogControlParam_Network(0, 5, 1, 3); BVRect dispRect = new BVRect(0, 0, panel.ClientRectangle.Height, panel.ClientRectangle.Width); OneDialog dlg = new OneDialog(); foreach (Channel channel in pu.channelList) { int captureVolume = 50; int audioVolume = 50; if (channel.channelNo == channelNo) { int ret = BVCU.ManagedLayer_CuNewTalk(m_bvsdkHandle, ref dlg.dialogHandle, m_session.Handle, Encoding.UTF8.GetBytes(pu.id), channelNo, captureVolume, audioVolume, ref net, m_bvsdkEventHandler.dialog_OnDialogEvent, m_bvsdkEventHandler.dialog_OnStorageEvent); BVCU.FAILED(ret); LogHelper.LogHelper.RecordLog(4, string.Format("打开[{0}]对讲", pu.puName)); break; } } dlg.panel = panel; dlg.pu = pu; dlg.channelNo = channelNo; m_dialogs.Add(dlg); } catch { panel.ContextMenuStrip = null; MessageBox.Show("打开对讲失败"); } }
/// <summary> /// 视频预览 /// </summary> /// <example>adf</example> /// <param name="pu">要预览的设备</param> /// <param name="channelNo">通道号</param> /// <param name="control">在哪个控件上预览</param> public void PreviewVideo(Pu pu, int channelNo, Control control) { BVCU_DialogControlParam_Network net = new BVCU_DialogControlParam_Network(0, 5, 1, 3); OneDialog dlg = new OneDialog(); BVRect dispRect = new BVRect(0, 0, control.ClientRectangle.Height, control.ClientRectangle.Width); //打开视屏浏览 int ret = BVCU.ManagedLayer_CuBrowsePu(m_bvsdkHandle, //sdk handle ref dlg.dialogHandle, //dialog handle m_session.Handle, //session handle Encoding.UTF8.GetBytes(pu.id), //pu id channelNo, //channel no control.Handle, //pannel handle ref dispRect, //上下左右,矩形 0, //音量 0, //single Rec File Sec Encoding.UTF8.GetBytes(""), //rec File Dir true, //videoTrans ref net, //network 时延 m_bvsdkEventHandler.dialog_OnDialogEvent, m_bvsdkEventHandler.dialog_OnStorageEvent); }
/// <summary> /// 发送串口数据 /// </summary> public int SendTspData(string sendData) { if (0 == this.m_tspDialogs.Count) { LogHelper.LogHelper.RecordLog(58, "没有已打开的串口通道"); return(-1); } foreach (OneDialog tspDialog in this.m_tspDialogs) { //BVCU_RESULT_S_OK: 成功 //BVCU_RESULT_E_NOTEXIST: 会话不存在 //BVCU_RESULT_E_UNSUPPORTED: 不支持的操作 //BVCU_RESULT_E_FAILED或其他: 其他错误导致失败 //发送串口数据 int ret = BVCU.SendTspData(tspDialog.dialogHandle, Encoding.UTF8.GetBytes(sendData), sendData.Length + 1); if (BVCU.BVCU_RESULT_S_OK == ret) { LogHelper.LogHelper.RecordLog(0, "发送成功, 内容: " + sendData); } else if ((int)BVCU.BVCU_Result.BVCU_RESULT_E_NOTFOUND == ret) { LogHelper.LogHelper.RecordLog(100, "发送失败,会话不存在"); } else if ((int)BVCU.BVCU_Result.BVCU_RESULT_E_ALLOCMEMFAILED == ret) { LogHelper.LogHelper.RecordLog(100, string.Format("发送失败,错误码:{0}, 可能原因: 您打开的会话(Dialog)模式为只读, 请增加可写功能", ret)); } else { LogHelper.LogHelper.RecordLog(100, "其他错误, 错误码: " + ret); } } return(0); }
public void closeTspDialog(string puId, int channelNo) { //新增 foreach (OneDialog dlg in m_tspDialogs) { if (dlg.pu.id.Equals(puId, StringComparison.CurrentCultureIgnoreCase) && dlg.channelNo == channelNo) { BVCU.ManagedLayer_CuCloseDialog(m_bvsdkHandle, dlg.dialogHandle); for (int i = 0; i < this.m_tspDialogs.Count; i++) { OneDialog oneDialog = this.m_tspDialogs[i] as OneDialog; if (oneDialog.pu.id.Equals(puId) && oneDialog.channelNo.Equals(channelNo)) { this.m_tspDialogs.RemoveAt(i); this.TspStatusChange_OnEvent(); break; } } return; } } }
public void login(string ip, int port, string usrName, string psw) { m_server.ip = ip; m_server.port = port; m_server.usrName = usrName; m_server.psw = psw; m_server.ukeyid = ""; m_server.ukeycode = ""; try { //封装 int ret = BVCU.ManagedLayer_CuLogin(m_bvsdkHandle, ref m_server.sessionHandle, Encoding.UTF8.GetBytes(ip), port, Encoding.UTF8.GetBytes(usrName), Encoding.UTF8.GetBytes(psw), SERVER_TIME_OUT_SECOND, m_bvsdkEventHandler.server_OnEvent, m_bvsdkEventHandler.server_ProcChannelInfo); BVCU.FAILED(ret); } catch { MessageBox.Show("登录失败"); } }
private void procRelogin() { try { //封装 int ret = BVCU.ManagedLayer_CuLogin(m_bvsdkHandle, ref m_server.sessionHandle, Encoding.UTF8.GetBytes(m_server.ip), m_server.port, Encoding.UTF8.GetBytes(m_server.usrName), Encoding.UTF8.GetBytes(m_server.psw), SERVER_TIME_OUT_SECOND, m_bvsdkEventHandler.server_OnEvent, m_bvsdkEventHandler.server_ProcChannelInfo); m_iLoginRetryCount++; Console.WriteLine("服务器断线重连执行第{0}次", m_iLoginRetryCount); if (m_iLoginRetryCount >= m_ServerRetryTimes) { Console.WriteLine("注销断线重连timer"); releaseReloginTimer(); return; } } catch { MessageBox.Show("登录失败"); } }
public int openTspDialog(Pu pu, int channelNo) { //查询tsp通道列表,如果已存在该通道,则返回 foreach (OneDialog dlg in m_tspDialogs) { if (dlg.pu.id.Equals(pu.id, StringComparison.CurrentCultureIgnoreCase) && dlg.channelNo == channelNo) { LogHelper.LogHelper.RecordLog(51, string.Format("已经发送打开[{0}, {1}]串口通道的命令", pu.puName, channelNo)); return(-1); } } IntPtr dialog = IntPtr.Zero; //打开TSP通道 int ret = BVCU.ManagedLayer_CuOpenTspDialog(m_bvsdkHandle, ref dialog, m_session.Handle, Encoding.UTF8.GetBytes(pu.id), channelNo, m_bvsdkEventHandler.tspDialog_OnEvent, m_bvsdkEventHandler.tspDialog_OnData); //如果打开TSP通道成功,则在TSP通道列表中加入该通道 if (BVCU.BVCU_RESULT_S_OK == ret) { OneDialog dlg = new OneDialog(); dlg.dialogHandle = dialog; dlg.channelNo = channelNo; dlg.pu = pu; m_tspDialogs.Add(dlg); LogHelper.LogHelper.RecordLog(0, string.Format("正在打开设备:{0}, 通道:{1}的串口", pu.puName, channelNo)); return(0); } else { string errorMsg = string.Format("打开{0}的{1}串口失败(错误码:{2})", pu.puName, channelNo, ret); MessageBox.Show(errorMsg); LogHelper.LogHelper.RecordLog(100, errorMsg); } return(-1); }
/// <summary> /// 停止使用库 /// </summary> public void Dispose() { BVCU.ManagedLayer_CuRelease(m_bvcuSdkHandle); }
public void logout() { BVCU.ManagedLayer_CuLogout(m_bvsdkHandle, m_server.sessionHandle); }
/// <summary> /// 初始化全局变量 /// </summary> /// <param name="bvcuSdkHandle"></param> /// <param name="session"></param> /// <param name="dialog"></param> public void init(IntPtr bvcuSdkHandle, Session session, Dialog dialog) { m_session = session; m_dialog = dialog; BVCU.ManagedLayer_CuSetPuControlResultProcFunc(bvcuSdkHandle, onControlResult); }