Example #1
0
        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);
        }