MBASEAPI void MIRACLEEXPORT _logDebug(LPCTSTR msg) { if(!initlog) logInit(); FILE *f = fopen(strDebugFile,"a+t"); if (f!=NULL) { try { CTime Time = CTime::GetCurrentTime(); CString TimeStr = Time.Format("%d/%m/%Y-%H:%M:%S:"); fprintf(f,"%s%s \n",TimeStr,msg); } catch(...) { TRACE0("Error on Log."); ASSERT(FALSE); } fclose(f); } TRACE0(msg);TRACE("\n"); if(gwndDebug != NULL) { if((gwndDebug->GetSafeHwnd() != NULL) && ::IsWindow(gwndDebug->GetSafeHwnd())) { try { CString str = msg; str.Replace(_T("\n"), _T("\r\n")); if(str.Find('\n')<0) str +="\r\n"; CString strWndText; gwndDebug->GetWindowText(strWndText); strWndText += str; gwndDebug->SetWindowText(strWndText); CEdit e; CRuntimeClass *r = e.GetRuntimeClass(); if(gwndDebug->IsKindOf(r)) { CEdit *wndEdit = (CEdit*) gwndDebug; wndEdit->LineScroll(-wndEdit->GetLineCount()); wndEdit->LineScroll(wndEdit->GetLineCount()-4); } //gwndDebug->SendMessage(EM_SCROLLCARET); } catch (...) { //16/11/10 Tarihinde eklendi progrma çýkýþýnda hata vermeyi engellemek için. gwndDebug = NULL; } } } }
static void appendSent(CString s) { currView->m_ReceiveValue += s; currView->UpdateData(FALSE); CEdit *myEdit = (CEdit *)currView->GetDlgItem(IDC_EDRECDATAVALUE); myEdit->LineScroll(myEdit->GetLineCount()); }
void CMyCommView::OnCheckSum() { m_CheckDataStyle = CDSSUM; m_CheckData.SetWindowText(_T("累加和")); CString mystr = DoGetReciveSelected(); mystr.TrimLeft(); mystr.TrimRight(); if (mystr == "") return; char data[512]; int len=DoStr2Hex(mystr,data); unsigned char *ptemp=(unsigned char*)((LPCTSTR)data); byte a = DoCheckSum(ptemp,len); CString myvalue; myvalue.Format("%x",a); myvalue.MakeUpper(); if (m_ReceiveValue=="") m_ReceiveValue = myvalue; else m_ReceiveValue += "\r\n" + myvalue; UpdateData(FALSE); if(!m_IsShowValueWindow) OnBtvisiblevalue(); CEdit *myEdit = (CEdit *)GetDlgItem(IDC_EDRECDATAVALUE); myEdit->LineScroll(myEdit->GetLineCount()); }
void CMyCommView::OnCheckCrc() { // TODO: Add your command handler code here m_CheckDataStyle = CDSCRC; m_CheckData.SetWindowText(_T("CRC")); CString mystr = DoGetReciveSelected(); mystr.TrimLeft(); mystr.TrimRight(); if (mystr == "") return; char data[512]; int len=DoStr2Hex(mystr,data); unsigned char *ptemp=(unsigned char*)((LPCTSTR)data); unsigned short cc=DoCreateCRC(ptemp,len); unsigned short hightbit=cc/256; unsigned short lowbit = cc-hightbit*256; CString strHighBit; strHighBit.Format("%02x",hightbit); CString strLowBit; strLowBit.Format("%02x",lowbit); if (m_ReceiveValue=="") m_ReceiveValue = strLowBit + ' ' + strHighBit; else m_ReceiveValue += "\r\n" + strLowBit + ' ' + strHighBit; UpdateData(FALSE); if(!m_IsShowValueWindow) OnBtvisiblevalue(); CEdit *myEdit = (CEdit *)GetDlgItem(IDC_EDRECDATAVALUE); myEdit->LineScroll(myEdit->GetLineCount()); }
//Thread safe way to update the load log void CLoadLTADlg::UpdateLoadLog() { CString sTextToAdd; g_LoadLogPipeCS.Lock(INFINITE); sTextToAdd = sm_sLoadLogPipe; sm_sLoadLogPipe = ""; g_LoadLogPipeCS.Unlock(); if(!sTextToAdd.IsEmpty()) { CString sLogText; CEdit* pEdit = ((CEdit*)GetDlgItem(IDC_LOADLOG)); pEdit->GetWindowText(sLogText); sLogText += sTextToAdd; pEdit->SetWindowText(sLogText); pEdit->LineScroll(pEdit->GetLineCount()); } }
void CyuchuandemoDlg::WriteLog(int hd,CString WriteLog) { CEdit *pEdit; pEdit = (CEdit *)GetDlgItem(IDC_EDITLOG); int nLen=0; nLen = pEdit->GetWindowTextLength (); pEdit->SetFocus (); pEdit->SetSel(nLen, nLen); if (hd==DAS_OK) WriteLog=WriteLog+" 数据接收正常"; else if (hd==Comm_Init_Err) WriteLog=WriteLog+" 错误原因:串口初始化错误!"; else if (hd==CommPort_Err) WriteLog=WriteLog+" 错误原因:端口错误!"; else if (hd==CommPort_Err) WriteLog=WriteLog+" 错误原因:端口错误!"; else if (hd==Chksum_Err) WriteLog=WriteLog+" 错误原因:通讯数据效验错误!"; else if (hd==Rev_Data_Err) WriteLog=WriteLog+" 错误原因:接收数据失败!"; else if (hd==TIME_OUT_Err) WriteLog=WriteLog+" 错误原因:通讯超时错误!"; else if (hd==Para_Err) WriteLog=WriteLog+" 错误原因:参数错误!"; else if (hd==Send_Data_Err) WriteLog=WriteLog+" 错误原因:发送数据失败!"; else if (hd==Get_status_Err) WriteLog=WriteLog+" 错误原因:接收状态位错误!"; else if ((hd==No_Data_Return)||(hd==No_BIN_Files)||(hd==Read_Files_ERR)) WriteLog=WriteLog+" 错误原因:没有数据返回!"; else if (hd==CRC_ERR) WriteLog=WriteLog+" 错误原因:CRC效验错误!"; else if (hd==Rev_LEN_Err) WriteLog=WriteLog+" 错误原因:接收长度溢出!"; else if (hd==Password_Err) WriteLog=WriteLog+" 错误原因:授权密码错误!"; else if (hd==Password_Para_Err) WriteLog=WriteLog+" 错误原因:密码格式错误!"; else if (hd==Encrypt_Err) WriteLog=WriteLog+" 错误原因:数据加密错误!"; else if (hd==Wrong_DEV_Err) WriteLog=WriteLog+" 错误原因:设备物理ID号不符!"; else if (hd==No_Record_Err) WriteLog=WriteLog+" 错误原因:没有流水!"; else WriteLog=WriteLog+" "; WriteLog = WriteLog+"\r\n"; pEdit->ReplaceSel (WriteLog); nLen = pEdit->GetLineCount(); //pEdit->LineScroll(nLen, nLen); //pEdit->SendMessage(WM_VSCROLL, MAKEWPARAM(SB_BOTTOM,0),0); if( nLen >= 150 ) { pEdit->SetWindowText(""); } }
// @pymethod int|PyCEdit|GetLineCount|Gets the number of lines in an edit control. static PyObject * PyCEdit_get_line_count(PyObject *self, PyObject *args) { CHECK_NO_ARGS(args); CEdit *pEdit = GetEditCtrl(self); if (!pEdit ) return NULL; GUI_BGN_SAVE; int rc = pEdit->GetLineCount(); GUI_END_SAVE; return Py_BuildValue("i", rc); // @pyseemfc CEdit|GetLineCount // @rdesc The number of lines in the buffer. If the control is empty, the return value is 1. }
/** * Gets change directory info from previous lines, feature only * for cmdl and compiler tab, all other tabs return sFile unchanged. * * @param iLine: zero based line index from where to * search cd [path] commands backward until * first line or cd <fullpath> or special cd $(prjdir) * is found * @param editCtrl: holds the text data * @param sFile: in/out. gets updated to point to final path * @param (HACK) pMsgFrame: CMsgFrame, used to check if cmdl, compiler tab * @param (HACK) pDoc: CMsgDoc, used to check if cmdl, compiler tab * may still be a (project) relative path on exit. * @see - */ static void GetCDInfo(int iLine, CEdit& editCtrl, CString& sFile, CMsgFrame* pMsgFrame, CMsgDoc* pDoc) { int nLen; const TCHAR* pszDir; TCHAR buffer[2*MAX_PATH]; if(FC_StringIsAbsPath(sFile)) return; if(iLine >= editCtrl.GetLineCount()) return; //feature only for compiler tab (HACK): ASSERT (pMsgFrame != NULL); if (!pMsgFrame) return; int iIndex=-1; pMsgFrame->m_tabWnd.GetActiveTab(iIndex); if(!pDoc || iIndex<0 || iIndex >= pDoc->m_arrMsgData.GetSize()) { ASSERT (!"bad pDoc, iIndex"); return; } MSG_VIEWER_TYPE msgTyp = pDoc->m_arrMsgData[iIndex].m_MsgViewerType; if(msgTyp != MSG_CmdLineMsgViewer && msgTyp != MSG_CompileMsgViewer) return; while(iLine>=0) { nLen = editCtrl.GetLine(iLine, buffer, FC_ARRAY_LEN(buffer)-10); iLine--; if(nLen<=0) continue; buffer[nLen] = 0;//<-needed ? FC_StringTrim(buffer); if((pszDir = IsLineCDInfo(buffer)) != NULL) { if(!*pszDir) break;//cd $(prjdir): don't prepend default prj dir as an abs path to sFile //all other rel or abs cd commands must be prepended: sFile.Insert(0, '\\'); sFile.Insert(0, pszDir); //if is abs must stop here: if(FC_StringIsAbsPath(pszDir)) break; } } }
void CSmartCommunicationDlg::AddString(CString csAppend,bool bFlag) { if( m_check_stop.GetCheck()) return ; if( csAppend.IsEmpty() ) return ; CEdit *pEdit; pEdit = (CEdit *)GetDlgItem(IDC_EDIT1); int nLen=0; nLen = pEdit->GetWindowTextLength (); pEdit->SetFocus (); pEdit->SetSel(nLen, nLen); csAppend = csAppend+"\r\n"; pEdit->ReplaceSel (csAppend); nLen = pEdit->GetLineCount(); if( nLen >= 150 ) { pEdit->SetWindowText(""); } }
void CAgentMonitorDlg::ReportMessageWrite(LPCTSTR pMsg) { CString s, sLog; CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT2); pEdit->GetWindowText(sLog); if (sLog.IsEmpty()) { s = pMsg; } else { s.Format(_T("\r\n%s"), pMsg); } sLog += s; pEdit->SetWindowText(sLog); pEdit->LineScroll(pEdit->GetLineCount()); }
void CLogView::showlog(WPARAM wParam, LPARAM lParam) { UINT nlength = (UINT)wParam; CString log =(char*)lParam; char tmpstr[100]; CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT1); UpdateData(TRUE); m_log+=log; if (m_log.GetLength()>2048) { m_log = m_log.Right(1024);//先去掉512字节 UpdateData(FALSE); pEdit->GetLine(0,tmpstr,100); int nlength = strlen(tmpstr); //得到可能乱码的长度 m_log = m_log.Right(1024-nlength);//去掉nlength长度 } UpdateData(FALSE); pEdit->LineScroll(pEdit->GetLineCount(),0); delete (char*)lParam; lParam =NULL; }
void CControllerMFC_V6Dlg::OnOK() { // TODO: 在此添加控件通知处理程序代码 //获得EDIT CEdit* pBoxOne; pBoxOne = (CEdit*) GetDlgItem(IDC_EDIT1); pBoxOne->SetWindowText( _T("") ); MSG message; CString strTemp; CString strInfo; HRESULT hr; // Now we will intilize COM hr = CoInitialize(0); if (!SUCCEEDED(hr)) { ::MessageBox (NULL,(LPCTSTR)("初始化Com失败"),"",0); return; //出错 } IWComm_Serial *wserial; //创建串口通信COM对象 hr = CoCreateInstance( CLSID_CWComm_Serial, NULL, CLSCTX_INPROC_SERVER, IID_IWComm_Serial, (void**) &wserial); if(!SUCCEEDED(hr)) { ::MessageBox (NULL,(LPCTSTR)("创建WComm_Serial失败"),"",0); return; //出错 } while (true) { bStopRun = false; __int64 lngRet; long lngRetSerial; BSTR bstrT; //中间变量 BSTR bstrFrame; //通信返回的数据 BSTR bstrCmd; //发送的指令帧 long controllerSN; //控制器序列号 BSTR bstrComPort; //通信串口号 //刷卡记录变量 __int64 cardId; //卡号 __int64 status; //状态 BSTR bstrSwipeDate; //日期时间 CString strRunDetail; //运行信息 IWCOMM_OPERATEPtr wudp(__uuidof(WComm_Operate)); //创建.NET 通信对象 ((CWnd*)GetDlgItem(IDC_EDITSN))->GetWindowText(strTemp); controllerSN = _ttol((LPCTSTR)strTemp); //测试使用的控制器 ((CWnd*)GetDlgItem(IDC_EDITSERIALPORT))->GetWindowText(strTemp); bstrComPort = strTemp.AllocSysString(); //使用的通信端口 strTemp.Format("%d",controllerSN); strInfo = "控制器通信-" + strTemp + "-" + CString(bstrComPort) ; pBoxOne->SetWindowText( strInfo); //读取运行状态信息 bstrT = BSTR(L"811000000000"); bstrCmd = wudp -> CreateBstrCommand(controllerSN, bstrT); //生成指令帧 wserial->serial_comm(bstrCmd, bstrComPort,&bstrFrame); //发送指令, 并获取返回信息 wserial -> get_ErrCode((long*)&lngRetSerial); if (( ERROR_SUCCESS != lngRetSerial)||(CString(bstrFrame)=="" ) ) { strInfo = strInfo + char(13) + char(10) + "出错处理: 读取运行信息失败" ; pBoxOne->SetWindowText(strInfo ); break; } //数据处理 strInfo = strInfo + char(13) + char(10) + "读取运行信息成功"; //对运行信息的详细分析 strRunDetail = "" ; strTemp.Format("%ld",wudp->GetSNFromRunInfo(bstrFrame) ); strRunDetail = strRunDetail + char(13) + char(10) + "设备序列号S/N: " + char(9) + strTemp; bstrT = wudp->GetClockTimeFromRunInfo(bstrFrame); strRunDetail = strRunDetail + char(13) + char(10) + "设备时钟: " + char(9) + CString(bstrT); strTemp.Format("%ld",wudp->GetCardRecordCountFromRunInfo(bstrFrame) ); strRunDetail = strRunDetail + char(13) + char(10) + "刷卡记录数: " + char(9) + strTemp; strTemp.Format("%ld",wudp->GetPrivilegeNumFromRunInfo(bstrFrame) ); strRunDetail = strRunDetail + char(13) + char(10) + "权限数: " + char(9) + strTemp; strRunDetail = strRunDetail + char(13) + char(10) + char(13) + char(10) + "最近的一条刷卡记录: " + char(9) ; bstrSwipeDate = wudp->GetSwipeDateFromRunInfo(bstrFrame, &cardId, &status) ; if (CString((bstrSwipeDate)) != "" ) { strTemp.Format( "%ld",cardId); strRunDetail = strRunDetail + char(13) + char(10) + "卡号: " + strTemp ; strTemp.Format( "%ld",status); strRunDetail = strRunDetail + char(9) + " 状态:" + char(9) + strTemp ; bstrT = wudp->NumToStrHex(status,1); strRunDetail = strRunDetail + "(" + CString(bstrT) + ")" ; strRunDetail = strRunDetail + char(9) + "时间:" + char(9) + CString(bstrSwipeDate) ; } strRunDetail = strRunDetail + char(13) + char(10) ; //门磁按钮状态 //Bit位 7 6 5 4 3 2 1 0 //说明 门磁4 门磁3 门磁2 门磁1 按钮4 按钮3 按钮2 按钮1 strRunDetail = strRunDetail + char(13) + char(10) + "门磁状态 1号门磁 2号门磁 3号门磁 4号门磁" ; strRunDetail = strRunDetail + char(13) + char(10) ; strRunDetail = strRunDetail + " "; lngRet = wudp->GetDoorStatusFromRunInfo(bstrFrame, 1); if (lngRet == 1) { strRunDetail = strRunDetail + " 开 "; } else { strRunDetail = strRunDetail + " 关 "; } lngRet = wudp->GetDoorStatusFromRunInfo(bstrFrame, 2); if (lngRet == 1) { strRunDetail = strRunDetail + " 开 "; } else { strRunDetail = strRunDetail + " 关 "; } lngRet = wudp->GetDoorStatusFromRunInfo(bstrFrame, 3); if (lngRet == 1) { strRunDetail = strRunDetail + " 开 "; } else { strRunDetail = strRunDetail + " 关 "; } lngRet = wudp->GetDoorStatusFromRunInfo(bstrFrame, 4); if (lngRet == 1) { strRunDetail = strRunDetail + " 开 "; } else { strRunDetail = strRunDetail + " 关 "; } strRunDetail = strRunDetail + char(13) + char(10); //按钮状态 //Bit位 7 6 5 4 3 2 1 0 //说明 门磁4 门磁3 门磁2 门磁1 按钮4 按钮3 按钮2 按钮1 strRunDetail = strRunDetail + "按钮状态 1号按钮 2号按钮 3号按钮 4号按钮"; strRunDetail = strRunDetail + char(13) + char(10) ; strRunDetail = strRunDetail + " "; lngRet = wudp->GetButtonStatusFromRunInfo(bstrFrame, 1); if (lngRet == 1) { strRunDetail = strRunDetail + " 松开 "; } else { strRunDetail = strRunDetail + " 按下 "; } lngRet = wudp->GetButtonStatusFromRunInfo(bstrFrame, 2); if (lngRet == 1) { strRunDetail = strRunDetail + " 松开 "; } else { strRunDetail = strRunDetail + " 按下 "; } lngRet = wudp->GetButtonStatusFromRunInfo(bstrFrame, 3); if (lngRet == 1) { strRunDetail = strRunDetail + " 松开 "; } else { strRunDetail = strRunDetail + " 按下 "; } lngRet = wudp->GetButtonStatusFromRunInfo(bstrFrame, 4); if (lngRet == 1) { strRunDetail = strRunDetail + " 松开 "; } else { strRunDetail = strRunDetail + " 按下 "; } strRunDetail = strRunDetail + char(13) + char(10) + "故障状态:" + char(9); lngRet = wudp->GetErrorNoFromRunInfo(bstrFrame); if (lngRet== 0) { strRunDetail = strRunDetail + " 无故障 " ; } else { strRunDetail = strRunDetail + " 有故障 " ; if ((lngRet & 1) > 0) { strRunDetail = strRunDetail + char(13) + char(10) + " " + char(9) + "系统故障1" ; } if ((lngRet & 2) > 0) { strRunDetail = strRunDetail + char(13) + char(10) + " " + char(9) + "系统故障2"; } if ((lngRet & 4) > 0) { strRunDetail = strRunDetail + char(13) + char(10) + " " + char(9) + "系统故障3[设备时钟有故障], 请校正时钟处理"; } if ((lngRet & 8) > 0) { strRunDetail = strRunDetail + char(13) + char(10) + " " + char(9) + "系统故障4"; } } strInfo = strInfo + strRunDetail; pBoxOne->SetWindowText(strInfo ); //校准控制器时间 bstrCmd = wudp -> CreateBstrCommandOfAdjustClockByPCTime(controllerSN); //生成指令帧 wserial->serial_comm(bstrCmd, bstrComPort,&bstrFrame); //发送指令, 并获取返回信息 wserial -> get_ErrCode((long*)&lngRetSerial); if (( ERROR_SUCCESS != lngRetSerial)||(CString(bstrFrame)=="" )) { strInfo = strInfo + char(13) + char(10) + "校准控制器时间出错" ; pBoxOne->SetWindowText(strInfo ); break; } else { strInfo = strInfo + char(13) + char(10) + "校准控制器时间成功" ; pBoxOne->SetWindowText(strInfo ); } //远程开1号门 bstrCmd = wudp ->CreateBstrCommand(controllerSN, A2BSTR("9D1001")) ; //生成指令帧 wserial->serial_comm(bstrCmd, bstrComPort,&bstrFrame); //发送指令, 并获取返回信息 wserial -> get_ErrCode((long*)&lngRetSerial); if (( ERROR_SUCCESS != lngRetSerial)||(CString(bstrFrame)=="" )) { //没有收到数据, //失败处理代码... (查ErrCode针对性分析处理) strInfo = strInfo + char(13) + char(10) + "远程开门失败" ; pBoxOne->SetWindowText(strInfo ); break; } else { strInfo = strInfo + char(13) + char(10) + "远程开门成功" ; pBoxOne->SetWindowText(strInfo ); } UpdateWindow(); //刷新窗口 //提取记录 long recIndex; recIndex = 1; while(true) { if (bStopRun) { break; } bstrT = wudp->NumToStrHex(recIndex, 4); strTemp = "8D10" + CString(bstrT); bstrCmd = wudp ->CreateBstrCommand(controllerSN, A2BSTR(strTemp)) ; //生成指令帧 wserial->serial_comm(bstrCmd, bstrComPort,&bstrFrame); //发送指令, 并获取返回信息 wserial->get_ErrCode((long*)&lngRetSerial); if (( ERROR_SUCCESS != lngRetSerial)||(CString(bstrFrame)=="" ) ) { //没有收到数据, //失败处理代码... (查ErrCode针对性分析处理) //用户可考虑重试 strInfo = strInfo + char(13) + char(10) + "提取记录出错" ; pBoxOne->SetWindowText(strInfo ); break; } else { bstrSwipeDate = wudp->GetSwipeDateFromRunInfo(bstrFrame, &cardId, &status) ; if (CString((bstrSwipeDate)) != "" ) { strRunDetail = ""; strTemp.Format( "%ld",cardId); strRunDetail = strRunDetail + "卡号: " + strTemp ; strTemp.Format( "%ld",status); strRunDetail = strRunDetail + char(9) + " 状态:" + char(9) + strTemp ; bstrT = wudp->NumToStrHex(status,1); strRunDetail = strRunDetail + "(" + CString(bstrT) + ")" ; strRunDetail = strRunDetail + char(9) + "时间:" + char(9) + CString(bstrSwipeDate) ; strInfo = strInfo + char(13) + char(10) + strRunDetail ; recIndex = recIndex + 1; //下一条记录 pBoxOne->SetWindowText(strInfo ); pBoxOne->LineScroll(pBoxOne->GetLineCount()); //显示最后一行 } else { strTemp.Format("%ld", (recIndex-1)); strInfo = strInfo + char(13) + char(10) + "提取记录完成. 总共提取记录数 =" + strTemp; pBoxOne->SetWindowText(strInfo ); pBoxOne->LineScroll(pBoxOne->GetLineCount()); //显示最后一行 break; } } if(::PeekMessage (&message,NULL,0,0,PM_REMOVE)){ //响应其他事件 如Exit按钮操作 ::TranslateMessage (&message); ::DispatchMessage (&message); } } if (( ERROR_SUCCESS != lngRetSerial)||(CString(bstrFrame)=="" ) ) { break; //出错 退出 } //删除已提取的记录 if (recIndex > 1) //只有提取了记录才进行删除 { strTemp.Format("%ld", (recIndex-1)); strTemp = "是否删除控制器上已提取的记录: " + strTemp; if (::MessageBox(NULL,(LPCTSTR)strTemp,"删除",MB_YESNO ) == IDYES) { bstrT = wudp->NumToStrHex(recIndex-1, 4); strTemp = "8E10" + CString(bstrT); bstrCmd = wudp ->CreateBstrCommand(controllerSN, A2BSTR(strTemp)) ; //生成指令帧 wserial->serial_comm(bstrCmd, bstrComPort,&bstrFrame); //发送指令, 并获取返回信息 wserial -> get_ErrCode((long*)&lngRetSerial); if (( ERROR_SUCCESS != lngRetSerial)||(CString(bstrFrame)=="" ) ) { //没有收到数据, //失败处理代码... (查ErrCode针对性分析处理) //用户可考虑重试 strInfo = strInfo + char(13) + char(10) + "删除记录失败" ; pBoxOne->SetWindowText(strInfo ); break; } else { strInfo = strInfo + char(13) + char(10) + "删除记录成功"; pBoxOne->SetWindowText(strInfo ); } } } //发送权限操作(1.先清空权限) bstrCmd = wudp ->CreateBstrCommand(controllerSN, A2BSTR("9310")) ; //生成指令帧 wserial->serial_comm(bstrCmd, bstrComPort,&bstrFrame); //发送指令, 并获取返回信息 wserial -> get_ErrCode((long*)&lngRetSerial); if (( ERROR_SUCCESS != lngRetSerial)||(CString(bstrFrame)=="" ) ) { //没有收到数据, //失败处理代码... (查ErrCode针对性分析处理) //用户可考虑重试 strInfo = strInfo + char(13) + char(10) + "清空权限失败" ; pBoxOne->SetWindowText(strInfo ); break; } else { strInfo = strInfo + char(13) + char(10) + "清空权限成功" ; pBoxOne->SetWindowText(strInfo ); } //发送权限操作(2.再添加权限) //权限格式: 卡号(2)+区号(1)+门号(1)+卡起始年月日(2)+卡截止年月日(2)+ 控制时段索引号(1)+密码(3)+备用(4,用0填充) //发送权限按: 先发1号门(卡号小的先发), 再发2号门(卡号小的先发) //此案例中权限设为: 卡有效期从(2007-8-14 到2020-12-31), 采用默认时段1(任意时间有效), 缺省密码(1234), 备用值以00填充 //以三个卡: 07217564 [9C4448],342681[B9A603],25409969[F126FE]为例,分别可以通过控制器的2个门。 //实际使用按需修改 //!!!!!!!注意: 此处卡号已直接按从小到大排列赋值了. 实际使用中要用算法实现排序 long cardno[3]; long privilegeIndex; long doorIndex; long cardIndex; CString privilege; cardno[0] = 342681 ; cardno[1] = 7217564; cardno[2] = 25409969; privilegeIndex = 1 ; for( doorIndex = 0;doorIndex<=1; doorIndex++) { for(cardIndex = 0; cardIndex <= 2; cardIndex++) { privilege = ""; bstrT = wudp->CardToStrHex(cardno[cardIndex]); privilege = privilege + CString(bstrT); //卡号 bstrT = wudp->NumToStrHex(doorIndex + 1, 1); privilege = privilege + CString(bstrT) ; //门号 bstrT = wudp->MSDateYmdToWCDateYmd(A2BSTR("2007-8-14")) ;//有效起始日期 privilege = privilege + CString(bstrT); bstrT = wudp->MSDateYmdToWCDateYmd(A2BSTR("2020-12-31"));//有效截止日期 privilege = privilege + CString(bstrT) ; bstrT = wudp->NumToStrHex(1, 1) ; //时段索引号 privilege = privilege + CString(bstrT) ; bstrT = wudp->NumToStrHex(123456, 3) ; //用户密码 privilege = privilege + CString(bstrT) ; bstrT = wudp->NumToStrHex(0, 4) ; //备用4字节(用0填充) privilege = privilege + CString(bstrT) ; if (lstrlen(privilege) != (16 * 2)) { //生成的权限不符合要求, 请查一下上一指令中写入的每个参数是否正确 strInfo = strInfo + char(13) + char(10) + "生成的权限不符合要求: 添加权限失败" ; pBoxOne->SetWindowText(strInfo ); break;; } bstrT = wudp->NumToStrHex(privilegeIndex, 2) ; //权限索引号 strTemp = "9B10" + CString(bstrT) + privilege; bstrCmd = wudp->CreateBstrCommand(controllerSN, A2BSTR(strTemp)) ; //生成指令帧 wserial->serial_comm(bstrCmd, bstrComPort,&bstrFrame); //发送指令, 并获取返回信息 wserial -> get_ErrCode((long*)&lngRetSerial); if (( ERROR_SUCCESS != lngRetSerial)||(CString(bstrFrame)=="" )) { //没有收到数据, //失败处理代码... (查ErrCode针对性分析处理) //用户可考虑重试 strInfo = strInfo + char(13) + char(10) + "添加权限失败" ; pBoxOne->SetWindowText(strInfo ); break; } else { privilegeIndex = privilegeIndex + 1; } if(::PeekMessage (&message,NULL,0,0,PM_REMOVE)){ //响应其他事件 如Exit按钮操作 ::TranslateMessage (&message); ::DispatchMessage (&message); } } } strTemp.Format("%ld", privilegeIndex-1 ); strInfo = strInfo + char(13) + char(10) + "添加权限数 = " + strTemp ; pBoxOne->SetWindowText(strInfo ); //发送控制时段 //发送要设定的时段 [注意0,1时段为系统固定化,更改是无效的, 所以设定的时段一般从2开始] //此案例设定时段2: 从2007-8-1到2007-12-31日 // 星期1到5允许在7:30-12:30, 13:30-17:30, 19:00-21:00通过, 其他时间不允许 CString timeseg; timeseg = ""; bstrT = wudp->NumToStrHex(0x1F, 1); timeseg = timeseg + CString(bstrT) ; //星期控制 bstrT = wudp->NumToStrHex(0x00, 1); timeseg = timeseg + CString(bstrT) ; // 下一链接时段(0--表示无) bstrT = wudp->NumToStrHex(0x00, 2); timeseg = timeseg + CString(bstrT) ; // 保留2字节(0填充) bstrT = wudp->MSDateHmsToWCDateHms(A2BSTR("7:30:00")); timeseg = timeseg + CString(bstrT) ; // 起始时分秒1 bstrT = wudp->MSDateHmsToWCDateHms(A2BSTR("12:30:00")); timeseg = timeseg + CString(bstrT) ; // 终止时分秒1 bstrT = wudp->MSDateHmsToWCDateHms(A2BSTR("13:30:00")); timeseg = timeseg + CString(bstrT) ; // 起始时分秒2 bstrT = wudp->MSDateHmsToWCDateHms(A2BSTR("17:30:00")); timeseg = timeseg + CString(bstrT) ; // 终止时分秒2 bstrT = wudp->MSDateHmsToWCDateHms(A2BSTR("19:00:00")); timeseg = timeseg + CString(bstrT) ; // 起始时分秒3 bstrT = wudp->MSDateHmsToWCDateHms(A2BSTR("21:00:00")); timeseg = timeseg + CString(bstrT) ; // 终止时分秒3 bstrT = wudp->MSDateYmdToWCDateYmd(A2BSTR("2007-8-1")); timeseg = timeseg + CString(bstrT) ; // 起始日期 bstrT = wudp->MSDateYmdToWCDateYmd(A2BSTR("2007-12-31")); timeseg = timeseg + CString(bstrT) ; // 终止日期 bstrT = wudp->NumToStrHex(0x00, 4); timeseg = timeseg + CString(bstrT) ; // 保留4字节(0填充) if (lstrlen(timeseg) != (24 * 2)) { //生成的时段不符合要求, 请查一下上一指令中写入的每个参数是否正确 strInfo = strInfo + char(13) + char(10) + "生成的时段不符合要求: 修改时段失败" ; pBoxOne->SetWindowText(strInfo ); break;; } bstrT = wudp->NumToStrHex(2, 2) ; //时段索引号2 strTemp = "9710" + CString(bstrT) + timeseg; bstrCmd = wudp->CreateBstrCommand(controllerSN, A2BSTR(strTemp)) ; //生成指令帧 wserial->serial_comm(bstrCmd, bstrComPort,&bstrFrame); //发送指令, 并获取返回信息 wserial -> get_ErrCode((long*)&lngRetSerial); if (( ERROR_SUCCESS != lngRetSerial)||(CString(bstrFrame)=="" ) ) { //没有收到数据, //失败处理代码... (查ErrCode针对性分析处理) //用户可考虑重试 strInfo = strInfo + char(13) + char(10) + "添加时段失败" ; pBoxOne->SetWindowText(strInfo ); break; } else { strInfo = strInfo + char(13) + char(10) + "添加时段成功" ; pBoxOne->SetWindowText(strInfo ); } //实时监控 // 读取运行状态是实现监控的关键指令。 在进行监控时, 先读取最新记录索引位的记录. 读取到最新的记录, 同时可以获取到刷卡记录数。 // 这时就可以用读取到刷卡记录数加1填充到要读取的最新记录索引位上,去读取运行状态, 以便获取下一个记录。 // 如果读取到了新的刷卡记录, 就可以将索引位增1, 否则保持索引位不变。 这样就可以实现数据的实时监控。 // 遇到通信不上的处理,这时可对串口通信采取超时400-500毫秒作为出错,可重试一次,再接收不到数据, 可认为设备与PC机间的不能通信。 __int64 watchIndex; long recCnt; watchIndex = 0 ; //缺省从0, 表示先提取最近一个记录 recCnt = 0 ; //监控记录计数 strInfo = strInfo + char(13) + char(10) + "开始实时监控......(请刷卡3次)" ; pBoxOne->SetWindowText(strInfo ); UpdateWindow(); //刷新窗口 pBoxOne->LineScroll(pBoxOne->GetLineCount()); //显示最后一行 while (recCnt < 3) //测试中 读到3个就停止 { if (bStopRun) { break; } bstrT = wudp->NumToStrHex(watchIndex, 3) ; //表示第watchIndex个记录, 如果是0则取最新一条记录 strTemp = "8110" + CString(bstrT); bstrCmd = wudp->CreateBstrCommand(controllerSN, A2BSTR(strTemp)) ; //生成指令帧 wserial->serial_comm(bstrCmd, bstrComPort,&bstrFrame); //发送指令, 并获取返回信息 wserial -> get_ErrCode((long*)&lngRetSerial); if (( ERROR_SUCCESS != lngRetSerial)||(CString(bstrFrame)=="" ) ) { //没有收到数据, //失败处理代码... (查ErrCode针对性分析处理) //用户可考虑重试 strInfo = strInfo + char(13) + char(10) + "实时监控失败" ; pBoxOne->SetWindowText(strInfo ); break; } else { bstrSwipeDate = wudp->GetSwipeDateFromRunInfo(bstrFrame, &cardId, &status) ; if (CString(bstrSwipeDate) != "" ) { strRunDetail=""; strTemp.Format( "%ld",cardId); strRunDetail = strRunDetail + "卡号: " + strTemp ; strTemp.Format( "%ld",status); strRunDetail = strRunDetail + char(9) + " 状态:" + char(9) + strTemp ; bstrT = wudp->NumToStrHex(status,1); strRunDetail = strRunDetail + "(" + CString(bstrT) + ")" ; strRunDetail = strRunDetail + char(9) + "时间:" + char(9) + CString((bstrSwipeDate)) ; strInfo = strInfo + char(13) + char(10) + strRunDetail ; pBoxOne->SetWindowText(strInfo ); recIndex = recIndex + 1; //下一条记录 UpdateWindow(); //刷新窗口 if (watchIndex == 0) //如果收到第一条记录 { watchIndex = wudp->GetCardRecordCountFromRunInfo(bstrFrame); watchIndex = watchIndex + 1; //指向(总记录数+1), 也就是下次刷卡的存储索引位 } else { watchIndex = watchIndex + 1 ; //指向下一个记录位 } recCnt = recCnt + 1; //记录计数 } pBoxOne->LineScroll(pBoxOne->GetLineCount()); //显示最后一行 } } if(::PeekMessage (&message,NULL,0,0,PM_REMOVE)){ //响应其他事件 如Exit按钮操作 ::TranslateMessage (&message); ::DispatchMessage (&message); } } strInfo = strInfo + char(13) + char(10) + "已停止实时监控" ; pBoxOne->SetWindowText(strInfo ); pBoxOne->LineScroll(pBoxOne->GetLineCount()); //显示最后一行 //释放资源 wudp -> Release(); wserial->Release(); break; } // Uninitialize COM CoUninitialize(); }