// RemoteSerialConfig.cpp : implementation file // #include "stdafx.h" #include "StoneU_HC_OCX.h" #include "RemoteSerialConfig.h" #include "RemoteParamsCfg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif CRemoteSerialConfig *pSerialCFG; extern CRemoteParamsCfg *m_pRemoteParam; ///////////////////////////////////////////////////////////////////////////// // CRemoteSerialConfig dialog void CALLBACK fSerialDataCallBack(LONG lSerialHandle,char *pRecvDataBuffer,DWORD dwBufSize,DWORD dwUser) { char pRecv[1024]; CString csTemp; sprintf(pRecv, pRecvDataBuffer, dwBufSize); csTemp.Format("%s", pRecv); TRACE("232 csTemp = %s", csTemp); } CRemoteSerialConfig::CRemoteSerialConfig(CWnd* pParent /*=NULL*/) : CDialog(CRemoteSerialConfig::IDD, pParent) { //{{AFX_DATA_INIT(CRemoteSerialConfig) m_decodeaddr = 0; m_IpMask = _T(""); m_LocalIp = _T(""); m_Psw = _T(""); m_RemoteIp = _T(""); m_Telephone = _T(""); m_UserName = _T(""); m_bSjjm = FALSE; m_bHuibo = FALSE; m_VerifyPSW = _T(""); //}}AFX_DATA_INIT } void CRemoteSerialConfig::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRemoteSerialConfig) DDX_Control(pDX, IDC_HBMODE, m_HBModeCtrl); DDX_Control(pDX, IDC_PPPMODE, m_PPPModeCtrl); DDX_Control(pDX, IDC_COPY485CFG, m_copy485cfgctrl); DDX_Control(pDX, IDC_STOPBIT232, m_stopbit232); DDX_Control(pDX, IDC_STOPBIT485, m_stopbit485); DDX_Control(pDX, IDC_OPERATEMODE, m_operatemode); DDX_Control(pDX, IDC_FLOW485, m_flow485); DDX_Control(pDX, IDC_FLOW232, m_flow232); DDX_Control(pDX, IDC_DATABIT485, m_databit485); DDX_Control(pDX, IDC_DATABIT232, m_databit232); DDX_Control(pDX, IDC_COMBODECODETYPE, m_decodetypectrl); DDX_Control(pDX, IDC_COMBOCHANNEL, m_channelctrl); DDX_Control(pDX, IDC_CHECKBIT485, m_checkbit485); DDX_Control(pDX, IDC_CHECKBIT232, m_checkbit232); DDX_Control(pDX, IDC_BAUD485, m_baud485); DDX_Control(pDX, IDC_BAUD232, m_baud232); DDX_Text(pDX, IDC_EDITDECODEADDRESS, m_decodeaddr); DDX_Text(pDX, IDC_EDITIPMASK, m_IpMask); DDX_Text(pDX, IDC_EDITLOCALIP, m_LocalIp); DDX_Text(pDX, IDC_EDITPSW, m_Psw); DDX_Text(pDX, IDC_EDITREMOTEIP, m_RemoteIp); DDX_Text(pDX, IDC_EDITTELEPHONE, m_Telephone); DDX_Text(pDX, IDC_EDITUSERNAME, m_UserName); DDX_Check(pDX, IDC_SJJM, m_bSjjm); DDX_Check(pDX, IDC_HUIBO, m_bHuibo); DDX_Text(pDX, IDC_EDITVERIFYPSW, m_VerifyPSW); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CRemoteSerialConfig, CDialog) //{{AFX_MSG_MAP(CRemoteSerialConfig) ON_BN_CLICKED(IDC_485OK, On485ok) ON_BN_CLICKED(IDC_BUT485COPY, OnBut485copy) ON_CBN_SELCHANGE(IDC_COMBOCHANNEL, OnSelchangeCombochannel) ON_BN_CLICKED(IDSERIALOK, OnSerialok) ON_BN_CLICKED(IDEXIT, OnExit) ON_CBN_SELCHANGE(IDC_OPERATEMODE, OnSelchangeOperatemode) ON_WM_TIMER() //cHn delete ON_BN_CLICKED(IDC_BUTTON3, OnButton1) //cHn delete ON_BN_CLICKED(IDC_BUTTON4, OnButton2) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRemoteSerialConfig message handlers BOOL CRemoteSerialConfig::CheckPara() { CString sTemp; char cTemp[100]; m_nChanSel = 0; m_lSerial = -1; m_nCopyChanNum = -1; m_copy485cfgctrl.ResetContent(); m_channelctrl.ResetContent(); sTemp.Format(_T("全部通道")); m_copy485cfgctrl.AddString(sTemp); bSetSerialParams = FALSE; bGet232Serial = FALSE; TRACE("\nm_iChannelnumber = %d\n", m_iChannelnumber); for(int i=0; iEnableWindow(TRUE); GetDlgItem(IDC_BUT485COPY)->EnableWindow(TRUE); GetDlgItem(IDC_485OK)->EnableWindow(TRUE); } if(m_bConnectServer) { if(!NET_DVR_GetDVRConfig(m_lServerID, NET_DVR_GET_RS232CFG, 0, &rs232cfg, sizeof(NET_DVR_RS232CFG), &dwReturned)) { sTemp.Format("获取232串口参数失败!: NET_DVR_GET_RS232CFG = %d \n", NET_DVR_GetLastError()); MessageBox(sTemp, "温馨提示", MB_ICONINFORMATION); } else { m_baud232.SetCurSel(rs232cfg.dwBaudRate); m_databit232.SetCurSel(rs232cfg.byDataBit); m_stopbit232.SetCurSel(rs232cfg.byStopBit); m_checkbit232.SetCurSel(rs232cfg.byParity); m_flow232.SetCurSel(rs232cfg.byFlowcontrol); m_operatemode.SetCurSel(rs232cfg.dwWorkMode); if(rs232cfg.dwWorkMode == 0) { /* GetDlgItem(IDC_BUTTONSTART)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTONSTOP)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTONSEND)->EnableWindow(FALSE); GetDlgItem(IDC_EDITSEND)->EnableWindow(FALSE); */ m_PPPModeCtrl.SetCurSel(rs232cfg.struPPPConfig.byPPPMode); m_HBModeCtrl.SetCurSel(rs232cfg.struPPPConfig.byRedialMode); m_bHuibo = rs232cfg.struPPPConfig.byRedial; m_bSjjm = rs232cfg.struPPPConfig.byDataEncrypt; ZeroMemory(cTemp, 100); memcpy(cTemp, rs232cfg.struPPPConfig.sUsername, NAME_LEN); m_UserName.Format("%s", cTemp); ZeroMemory(cTemp, 100); memcpy(cTemp, rs232cfg.struPPPConfig.sPassword, PASSWD_LEN); m_Psw.Format("%s", cTemp); ZeroMemory(cTemp, 100); memcpy(cTemp, rs232cfg.struPPPConfig.sPassword, PASSWD_LEN); m_VerifyPSW.Format("%s", cTemp); m_RemoteIp = rs232cfg.struPPPConfig.sRemoteIP; m_LocalIp = rs232cfg.struPPPConfig.sLocalIP; m_IpMask = rs232cfg.struPPPConfig.sLocalIPMask; ZeroMemory(cTemp, 100); memcpy(cTemp, rs232cfg.struPPPConfig.sTelephoneNumber, PHONENUMBER_LEN); m_Telephone.Format("%s", cTemp); } else if(rs232cfg.dwWorkMode == 1) { /* GetDlgItem(IDC_BUTTONSTART)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTONSTOP)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTONSEND)->EnableWindow(FALSE); GetDlgItem(IDC_EDITSEND)->EnableWindow(FALSE); */ GetDlgItem(IDC_PPPMODE)->EnableWindow(FALSE); GetDlgItem(IDC_HBMODE)->EnableWindow(FALSE); GetDlgItem(IDC_EDITUSERNAME)->EnableWindow(FALSE); GetDlgItem(IDC_EDITPSW)->EnableWindow(FALSE); GetDlgItem(IDC_EDITVERIFYPSW)->EnableWindow(FALSE); GetDlgItem(IDC_EDITREMOTEIP)->EnableWindow(FALSE); GetDlgItem(IDC_EDITLOCALIP)->EnableWindow(FALSE); GetDlgItem(IDC_EDITIPMASK)->EnableWindow(FALSE); GetDlgItem(IDC_EDITTELEPHONE)->EnableWindow(FALSE); GetDlgItem(IDC_SJJM)->EnableWindow(FALSE); GetDlgItem(IDC_HUIBO)->EnableWindow(FALSE); } else if(rs232cfg.dwWorkMode == 2) { GetDlgItem(IDC_PPPMODE)->EnableWindow(FALSE); GetDlgItem(IDC_HBMODE)->EnableWindow(FALSE); GetDlgItem(IDC_EDITUSERNAME)->EnableWindow(FALSE); GetDlgItem(IDC_EDITPSW)->EnableWindow(FALSE); GetDlgItem(IDC_EDITVERIFYPSW)->EnableWindow(FALSE); GetDlgItem(IDC_EDITREMOTEIP)->EnableWindow(FALSE); GetDlgItem(IDC_EDITLOCALIP)->EnableWindow(FALSE); GetDlgItem(IDC_EDITIPMASK)->EnableWindow(FALSE); GetDlgItem(IDC_EDITTELEPHONE)->EnableWindow(FALSE); GetDlgItem(IDC_SJJM)->EnableWindow(FALSE); GetDlgItem(IDC_HUIBO)->EnableWindow(FALSE); } bGet232Serial = TRUE; GetDlgItem(IDSERIALOK)->EnableWindow(TRUE); } } m_channelctrl.SetCurSel(m_nChanSel); m_copy485cfgctrl.SetCurSel(m_nChanSel); pSerialCFG = this; UpdateData(FALSE); return TRUE; } BOOL CRemoteSerialConfig::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here CRect rc(0, 0, 0, 0); GetParent()->GetClientRect(&rc); ((CTabCtrl*)GetParent())->AdjustRect(FALSE, &rc); MoveWindow(&rc); if(m_pRemoteParam->m_dvrSelect != -1) CheckPara(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CRemoteSerialConfig::On485ok() { if(m_pRemoteParam->m_dvrSelect == -1) return; // TODO: Add your control notification handler code here UpdateData(TRUE); m_nChanSel = m_channelctrl.GetCurSel(); if(bGet485Serial[m_nChanSel]) { decodercfg[m_nChanSel].dwBaudRate = m_baud485.GetCurSel(); decodercfg[m_nChanSel].byDataBit = m_databit485.GetCurSel(); decodercfg[m_nChanSel].byStopBit = m_stopbit485.GetCurSel(); decodercfg[m_nChanSel].byParity = m_checkbit485.GetCurSel(); decodercfg[m_nChanSel].byFlowcontrol = m_flow485.GetCurSel(); decodercfg[m_nChanSel].wDecoderType = m_decodetypectrl.GetCurSel(); decodercfg[m_nChanSel].wDecoderAddress = m_decodeaddr; TRACE("m_nChanSel = %d m_decodeaddr = %d", m_nChanSel, m_decodeaddr); bSetSerialParams = TRUE; } } void CRemoteSerialConfig::OnBut485copy() { // TODO: Add your control notification handler code here UpdateData(TRUE); m_nCopyChanNum = m_copy485cfgctrl.GetCurSel() - 1; if(m_nCopyChanNum == m_nChanSel) return; if(m_nCopyChanNum == -1) { for(int i=0; iEnableWindow(TRUE); //bGet485Serial[m_nChanSel] = TRUE; // } UpdateData(FALSE); } void CRemoteSerialConfig::OnSerialok() { if(m_pRemoteParam->m_dvrSelect == -1) return; // TODO: Add your control notification handler code here UpdateData(TRUE); if(bGet232Serial) { rs232cfg.dwBaudRate = m_baud232.GetCurSel(); rs232cfg.byDataBit = m_databit232.GetCurSel(); rs232cfg.byStopBit = m_stopbit232.GetCurSel(); rs232cfg.byParity = m_checkbit232.GetCurSel(); rs232cfg.byFlowcontrol = m_flow232.GetCurSel(); rs232cfg.dwWorkMode = m_operatemode.GetCurSel(); int OperateSel = 0; OperateSel = m_operatemode.GetCurSel(); if(OperateSel == 0) { if(m_VerifyPSW != m_Psw) { MessageBox("密码校验不正确!", "温馨提示", MB_ICONINFORMATION); return ; } rs232cfg.struPPPConfig.byPPPMode = m_PPPModeCtrl.GetCurSel(); rs232cfg.struPPPConfig.byRedialMode = m_HBModeCtrl.GetCurSel(); rs232cfg.struPPPConfig.byRedial = (BYTE)m_bHuibo; rs232cfg.struPPPConfig.byDataEncrypt = (BYTE)m_bSjjm; memcpy(rs232cfg.struPPPConfig.sUsername,m_UserName,NAME_LEN); memcpy(rs232cfg.struPPPConfig.sPassword, m_Psw, PASSWD_LEN); memcpy(rs232cfg.struPPPConfig.sRemoteIP, m_RemoteIp, 16); memcpy(rs232cfg.struPPPConfig.sLocalIP, m_LocalIp, 16); memcpy(rs232cfg.struPPPConfig.sLocalIPMask, m_IpMask, 16); memcpy(rs232cfg.struPPPConfig.sTelephoneNumber, m_Telephone, PHONENUMBER_LEN); } } bSetSerialParams = TRUE; } void CRemoteSerialConfig::OnExit() { // TODO: Add your control notification handler code here bSetSerialParams = FALSE; } void CRemoteSerialConfig::OnCancel() { // TODO: Add extra cleanup here // CDialog::OnCancel(); } void CRemoteSerialConfig::OnSelchangeOperatemode() { // TODO: Add your control notification handler code here char cTemp[100]; UpdateData(TRUE); int OperateSel = 0; OperateSel = m_operatemode.GetCurSel(); if(OperateSel == 0) { /* GetDlgItem(IDC_BUTTONSTART)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTONSTOP)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTONSEND)->EnableWindow(FALSE); GetDlgItem(IDC_EDITSEND)->EnableWindow(FALSE); */ GetDlgItem(IDC_PPPMODE)->EnableWindow(TRUE); GetDlgItem(IDC_HBMODE)->EnableWindow(TRUE); GetDlgItem(IDC_EDITUSERNAME)->EnableWindow(TRUE); GetDlgItem(IDC_EDITPSW)->EnableWindow(TRUE); GetDlgItem(IDC_EDITVERIFYPSW)->EnableWindow(TRUE); GetDlgItem(IDC_EDITREMOTEIP)->EnableWindow(TRUE); GetDlgItem(IDC_EDITLOCALIP)->EnableWindow(TRUE); GetDlgItem(IDC_EDITIPMASK)->EnableWindow(TRUE); GetDlgItem(IDC_EDITTELEPHONE)->EnableWindow(TRUE); GetDlgItem(IDC_SJJM)->EnableWindow(TRUE); GetDlgItem(IDC_HUIBO)->EnableWindow(TRUE); m_PPPModeCtrl.SetCurSel(rs232cfg.struPPPConfig.byPPPMode); m_HBModeCtrl.SetCurSel(rs232cfg.struPPPConfig.byRedialMode); m_bHuibo = rs232cfg.struPPPConfig.byRedial; m_bSjjm = rs232cfg.struPPPConfig.byDataEncrypt; ZeroMemory(cTemp, 100); memcpy(cTemp, rs232cfg.struPPPConfig.sUsername, NAME_LEN); m_UserName.Format("%s", cTemp); ZeroMemory(cTemp, 100); memcpy(cTemp, rs232cfg.struPPPConfig.sPassword, PASSWD_LEN); m_Psw.Format("%s", cTemp); ZeroMemory(cTemp, 100); memcpy(cTemp, rs232cfg.struPPPConfig.sPassword, PASSWD_LEN); m_VerifyPSW.Format("%s", cTemp); m_RemoteIp = rs232cfg.struPPPConfig.sRemoteIP; m_LocalIp = rs232cfg.struPPPConfig.sLocalIP; m_IpMask = rs232cfg.struPPPConfig.sLocalIPMask; ZeroMemory(cTemp, 100); memcpy(cTemp, rs232cfg.struPPPConfig.sTelephoneNumber, PHONENUMBER_LEN); m_Telephone.Format("%s", cTemp); } else if(OperateSel == 1) { /* GetDlgItem(IDC_BUTTONSTART)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTONSTOP)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTONSEND)->EnableWindow(FALSE); GetDlgItem(IDC_EDITSEND)->EnableWindow(FALSE); */ GetDlgItem(IDC_PPPMODE)->EnableWindow(FALSE); GetDlgItem(IDC_HBMODE)->EnableWindow(FALSE); GetDlgItem(IDC_EDITUSERNAME)->EnableWindow(FALSE); GetDlgItem(IDC_EDITPSW)->EnableWindow(FALSE); GetDlgItem(IDC_EDITVERIFYPSW)->EnableWindow(FALSE); GetDlgItem(IDC_EDITREMOTEIP)->EnableWindow(FALSE); GetDlgItem(IDC_EDITLOCALIP)->EnableWindow(FALSE); GetDlgItem(IDC_EDITIPMASK)->EnableWindow(FALSE); GetDlgItem(IDC_EDITTELEPHONE)->EnableWindow(FALSE); GetDlgItem(IDC_SJJM)->EnableWindow(FALSE); GetDlgItem(IDC_HUIBO)->EnableWindow(FALSE); } else if(OperateSel == 2) { /* GetDlgItem(IDC_BUTTONSTART)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTONSTOP)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTONSEND)->EnableWindow(TRUE); GetDlgItem(IDC_EDITSEND)->EnableWindow(TRUE); */ GetDlgItem(IDC_PPPMODE)->EnableWindow(FALSE); GetDlgItem(IDC_HBMODE)->EnableWindow(FALSE); GetDlgItem(IDC_EDITUSERNAME)->EnableWindow(FALSE); GetDlgItem(IDC_EDITPSW)->EnableWindow(FALSE); GetDlgItem(IDC_EDITVERIFYPSW)->EnableWindow(FALSE); GetDlgItem(IDC_EDITREMOTEIP)->EnableWindow(FALSE); GetDlgItem(IDC_EDITLOCALIP)->EnableWindow(FALSE); GetDlgItem(IDC_EDITIPMASK)->EnableWindow(FALSE); GetDlgItem(IDC_EDITTELEPHONE)->EnableWindow(FALSE); GetDlgItem(IDC_SJJM)->EnableWindow(FALSE); GetDlgItem(IDC_HUIBO)->EnableWindow(FALSE); } } void CRemoteSerialConfig::OnButton1() { // TODO: Add your control notification handler code here if(m_lSerial >= 0) { NET_DVR_SerialStop(m_lSerial); m_lSerial = -1; } //1-232 2-485 m_lSerial = NET_DVR_SerialStart(m_lServerID, 1, fSerialDataCallBack, 0); if(m_lSerial < 0) { MessageBox("建立透明通道失败!", "温馨提示", MB_ICONINFORMATION); } else { SetTimer(SERIAL_TIMER,1000,NULL); } } void CRemoteSerialConfig::OnButton2() { // TODO: Add your control notification handler code here if(m_lSerial >= 0) { KillTimer(SERIAL_TIMER); Sleep(500); NET_DVR_SerialStop(m_lSerial); m_lSerial = -1; } TRACE("OnButtonstop!"); } int val = 0; void CRemoteSerialConfig::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default if(nIDEvent == SERIAL_TIMER) { char buf[10]; char *pTemp = buf; val++; if(val >= 1000) val = 1; sprintf(pTemp, "%4d", val); if(m_lSerial >= 0) { NET_DVR_SerialSend(m_lSerial, 1, pTemp, sizeof(pTemp)); } } CDialog::OnTimer(nIDEvent); }