// GoGoDlg.cpp : implementation file // #include "stdafx.h" #include "GoGo.h" #include "GoGoDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define PORT_CMD 10000 DWORD gdwTimeout = 4000; void GetChecksum(char inbuf[], char csbuf[]); ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CGoGoDlg dialog CGoGoDlg::CGoGoDlg(CWnd* pParent /*=NULL*/) : CDialog(CGoGoDlg::IDD, pParent) { //{{AFX_DATA_INIT(CGoGoDlg) m_status = _T(""); m_send = _T(""); m_send_hex = _T(""); m_receive = _T(""); m_receive_hex = _T(""); m_term = -1; m_send_cmd = _T(""); m_send_cmd_ack = _T(""); m_port_no = 0; m_com_status = _T(""); m_gateway = _T(""); m_mac = _T(""); m_mask = _T(""); m_fw_ver = _T(""); m_os_ver = _T(""); m_ip = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1); } void CGoGoDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CGoGoDlg) DDX_Control(pDX, IDC_B_SEND, m_btnSend); DDX_Control(pDX, IDC_btnConnect, m_connect); DDX_Control(pDX, IDC_btnDisconnect, m_disconnect); DDX_Text(pDX, IDC_EDIT3, m_status); DDX_Text(pDX, IDC_SEND, m_send); DDX_Text(pDX, IDC_EDIT2, m_send_hex); DDX_Text(pDX, IDC_receive, m_receive); DDX_Text(pDX, IDC_receive_hex, m_receive_hex); DDX_Radio(pDX, IDC_NONE, m_term); DDX_Text(pDX, IDC_SEND_CMD, m_send_cmd); DDX_Text(pDX, IDC_SEND_CMD_ACK, m_send_cmd_ack); DDX_CBIndex(pDX, IDC_COMBO_PORT, m_port_no); DDX_Text(pDX, IDC_E_COM_STATUS, m_com_status); DDX_Text(pDX, IDC_E_GATEWAY, m_gateway); DDX_Text(pDX, IDC_E_MAC, m_mac); DDX_Text(pDX, IDC_E_MASK, m_mask); DDX_Text(pDX, IDC_E_FW_VERSION, m_fw_ver); DDX_Text(pDX, IDC_E_OS_VER, m_os_ver); DDX_Text(pDX, IDC_eIP, m_ip); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CGoGoDlg, CDialog) //{{AFX_MSG_MAP(CGoGoDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_EN_CHANGE(IDC_SEND, OnChangeSend) ON_WM_TIMER() ON_EN_CHANGE(IDC_receive, OnChangereceive) ON_BN_CLICKED(IDC_RESET_RECEIVE, OnResetReceive) ON_BN_CLICKED(IDC_B_SEND, OnBSend) ON_CBN_SELCHANGE(IDC_COMBO_PORT, OnSelchangeComboPort) ON_BN_CLICKED(IDC_B_NET_SET, OnBNetSet) ON_BN_CLICKED(IDC_B_COM_SET, OnBComSet) ON_BN_CLICKED(IDC_B_SET_GATEWAY, OnBSetGateway) ON_BN_CLICKED(IDC_B_SET_MASK, OnBSetMask) ON_BN_CLICKED(IDC_CloseBtn, OnCloseBtn) ON_BN_CLICKED(IDC_btnSendCmd, OnbtnSendCmd) ON_BN_CLICKED(IDC_btnClearCmd, OnbtnClearCmd) ON_BN_CLICKED(IDC_btnConnect, OnbtnConnect) ON_BN_CLICKED(IDC_btnDisconnect, OnbtnDisconnect) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CGoGoDlg message handlers BOOL CGoGoDlg::OnInitDialog() { TRACE( "OnInitDialog\n" ); CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here bConnect=FALSE; m_disconnect.EnableWindow(FALSE); //m_connect.SetButtonStyle( BS_DEFPUSHBUTTON ); m_ip="192.168.255.1"; m_term=1; m_port_no=0; m_gateway="N/A"; m_mask="N/A"; m_mac="N/A"; m_com_status="N/A"; m_fw_ver="N/A"; m_os_ver="N/A"; UpdateData(FALSE); SetTimer(1,100,NULL); CEdit* pStatus=(CEdit*)GetDlgItem(IDC_EDIT3); pStatus->LineLength(10); //((CButton*) GetDlgItem(IDC_CR))->SetCheck(1); //((CButton*) GetDlgItem(IDC_NONE))->SetCheck(0); AfxSocketInit(NULL); return TRUE; // return TRUE unless you set the focus to a control } void CGoGoDlg::OnSysCommand(UINT nID, LPARAM lParam) { TRACE( "OnSysCommand\n" ); if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CGoGoDlg::OnPaint() { TRACE( "OnPaint\n" ); if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CGoGoDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CGoGoDlg::OnChangeSend() { TRACE( "OnChangeSend\n" ); // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // TODO: Add your control notification handler code here CString tmp; LPSTR tmp1; UpdateData(); m_send_hex=""; UINT len=m_send.GetLength(); tmp1=m_send.GetBuffer(len); for(UINT i=0;i0){ if ( 0x0D == lpBuf[len-1] ) lpBuf[len-1] = 0; else lpBuf[len] = 0; m_send_cmd_ack+=lpBuf; UpdateData(FALSE); } else if(len==SOCKET_ERROR){ // error } len = 0; int iSelect = m_port_no; if ( 0 == m_port_io ) // No Port I/O, so 0 ==> Port 1 iSelect++; if ( m_is8000 && iSelect >= 2 ) // is 8000, so 2 ==> Port3, 3 ==> Port 4 iSelect++; switch( iSelect ){ case 0: len=sockIO.Receive(lpBuf,2048,NULL); break; case 1: len=sock1.Receive(lpBuf,2048,NULL); break; case 2: len=sock2.Receive(lpBuf,2048,NULL); break; case 3: len=sock3.Receive(lpBuf,2048,NULL); break; case 4: len=sock4.Receive(lpBuf,2048,NULL); break; case 5: len=sock5.Receive(lpBuf,2048,NULL); break; case 6: len=sock6.Receive(lpBuf,2048,NULL); break; case 7: len=sock7.Receive(lpBuf,2048,NULL); break; case 8: len=sock8.Receive(lpBuf,2048,NULL); break; case 9: len=sock9.Receive(lpBuf,2048,NULL); break; case 10: len=sock10.Receive(lpBuf,2048,NULL); break; case 11: len=sock11.Receive(lpBuf,2048,NULL); break; case 12: len=sock12.Receive(lpBuf,2048,NULL); break; } if(len>0){ if ( 0x0D == lpBuf[len-1] ) lpBuf[len-1] = 0; else lpBuf[len] = 0; m_receive+=lpBuf; UpdateData(FALSE); OnChangereceive(); } else if(len==SOCKET_ERROR){ // error } } CDialog::OnTimer(nIDEvent); } void CGoGoDlg::OnChangereceive() { TRACE( "OnCbangeReceive\n" ); // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // TODO: Add your control notification handler code here CString tmp; LPSTR tmp1; m_receive_hex=""; UINT len=m_receive.GetLength(); tmp1=m_receive.GetBuffer(len); for(UINT i=0;iGetWindowText(str); m_receive = ""; m_receive_hex = ""; UpdateData(FALSE); if(str=="None"){ str_send=m_send; } else if(str=="CR"){ str_send=m_send+"\r"; len++; } else if(str=="LF"){ str_send=m_send+"\n"; len++; } else if(str=="CR_LF"){ str_send=m_send+"\r\n"; len=len+2; } else if(str=="LF_CR"){ str_send=m_send+"\n\r"; len=len+2; } else if(str=="CS_CR"){ char csbuf[3]; GetChecksum( m_send.GetBuffer(2048), csbuf ); str_send=m_send + csbuf + "\r"; len=len+3; } int iSelect = m_port_no; if ( 0 == m_port_io ) // Doesn't support Port I/O, so 0 ==> Port 1 iSelect++; if ( m_is8000 && iSelect >= 2 ) // is 8000, so 2 ==> Port 3, 3 ==> Port 4 iSelect++; switch( iSelect ){ case 0: sockIO.Send(str_send.GetBuffer(len),len,0); break; case 1: sock1.Send(str_send.GetBuffer(len),len,0); break; case 2: sock2.Send(str_send.GetBuffer(len),len,0); break; case 3: sock3.Send(str_send.GetBuffer(len),len,0); break; case 4: sock4.Send(str_send.GetBuffer(len),len,0); break; case 5: sock5.Send(str_send.GetBuffer(len),len,0); break; case 6: sock6.Send(str_send.GetBuffer(len),len,0); break; case 7: sock7.Send(str_send.GetBuffer(len),len,0); break; case 8: sock8.Send(str_send.GetBuffer(len),len,0); break; case 9: sock9.Send(str_send.GetBuffer(len),len,0); break; case 10: sock10.Send(str_send.GetBuffer(len),len,0); break; case 11: sock11.Send(str_send.GetBuffer(len),len,0); break; case 12: sock12.Send(str_send.GetBuffer(len),len,0); break; } } void CGoGoDlg::ShowError() { TRACE( "ShowError\n" ); CString sError; CString sTitle; int rc=GetLastError( ); switch(rc) { // Create Error case WSANOTINITIALISED: sTitle="Create Sock Error"; sError="A successful AfxSocketInit must occur before using this API"; break; case WSAENETDOWN: sTitle="Create Sock Error"; sError="The Windows Sockets implementation detected that the network subsystem failed."; break; case WSAEAFNOSUPPORT: sTitle="Create Sock Error"; sError="The specified address family is not supported"; break; case WSAEINPROGRESS: sTitle="Create Sock Error"; sError="A blocking Windows Sockets operation is in progress"; break; case WSAEMFILE: sTitle="Create Sock Error"; sError="No more file descriptors are available"; break; case WSAENOBUFS: sTitle="Create Sock Error"; sError="No buffer space is available. The socket cannot be created"; break; case WSAEPROTONOSUPPORT: sTitle="Create Sock Error"; sError="The specified port is not supported"; break; case WSAEPROTOTYPE: sTitle="Create Sock Error"; sError="The specified port is the wrong type for this socket"; break; case WSAESOCKTNOSUPPORT: sTitle="Create Sock Error"; sError="The specified socket type is not supported in this address family"; break; // Connect Error case WSAEADDRINUSE: sTitle="Create Sock Error"; sError="The specified address is already in use"; break; case WSAEADDRNOTAVAIL: sTitle="Create Sock Error"; sError="The specified address is not available from the local machine"; break; case WSAECONNREFUSED: sTitle="Create Sock Error"; sError="The attempt to connect was rejected"; break; case WSAEDESTADDRREQ: sTitle="Create Sock Error"; sError="A destination address is required"; break; case WSAEFAULT: sTitle="Create Sock Error"; sError="The nSockAddrLen argument is incorrect"; break; case WSAEINVAL: sTitle="Create Sock Error"; sError="Invalid host address"; break; case WSAEISCONN: sTitle="Create Sock Error"; sError="The socket is already connected"; break; case WSAENETUNREACH: sTitle="Create Sock Error"; sError="The network cannot be reached from this host at this time"; break; case WSAENOTSOCK: sTitle="Create Sock Error"; sError="The descriptor is not a socket"; break; case WSAETIMEDOUT: sTitle="Create Sock Error"; sError="Attempt to connect timed out without establishing a connection"; break; /* case WSAEWOULDBLOCK: sTitle="Create Sock Error"; sError="The socket is marked as nonblocking and the connection cannot be completed immediately"; break; */ default: return; } MessageBox(sError,sTitle); } void CGoGoDlg::OnSelchangeComboPort() { TRACE( "OnSelChangeComboPort\n" ); // TODO: Add your control notification handler code here UpdateData(); m_receive=""; m_receive_hex=""; m_send=""; m_send_hex=""; char buf[20]; int iSelect = m_port_no; if ( 0 == m_port_io ) // Doesn't support Port I/O, so 0 ==> Port 1 iSelect++; if ( m_is8000 && iSelect >= 2 ) // is 8000, so 2 ==> Port 3, 3 ==> Port 4 iSelect++; //sprintf(buf,"16%d", iSelect); if ( iSelect <= 9 ) sprintf(buf, "16%d", iSelect); else sprintf(buf, "16%c", iSelect - 10 + 'A'); if ( 0 == m_port_no && 1 == m_port_io ) // Select port_io m_com_status = "N/A"; else (SendReceiveCmd(buf,buf,gdwTimeout)==0)? m_com_status=buf : m_com_status="N/A"; UpdateData(FALSE); } void CGoGoDlg::AddPortSelect() { TRACE( "AddPortSelect\n" ); CComboBox* pPort=(CComboBox*)GetDlgItem(IDC_COMBO_PORT); if ( m_port_io ) pPort->AddString("Port7000"); TCHAR szBuffer[20]; for(int i=0;iAddString(szBuffer); } } void CGoGoDlg::ResetPortCombo() { TRACE( "ResetPortCombo\n" ); CComboBox* pPort=(CComboBox*)GetDlgItem(IDC_COMBO_PORT); pPort->ResetContent(); } void CGoGoDlg::OnBNetSet() { TRACE( "OnBNetSet\n" ); // TODO: Add your control notification handler code here NetSet dlg; dlg.m_set_ip=m_ip; if(bConnect==FALSE){ AfxMessageBox("Connect at first..."); return; } if(dlg.DoModal()==IDOK){ CString cmd; char buf[80]; m_ip = dlg.m_set_ip; YenModifyFormat(&(dlg.m_set_ip)); cmd="08"+dlg.m_set_ip+"\r"; SendReceiveCmd(cmd.GetBuffer(cmd.GetLength()),buf,0); OnbtnDisconnect(); AfxMessageBox("Setting has changed, please reconnect.."); YenClearStatus(); } } void CGoGoDlg::OnBComSet() { TRACE( "OnBComSet\n" ); // TODO: Add your control notification handler code here CComSet dlg; if(bConnect==FALSE){ AfxMessageBox("Connect at first..."); return; } if(dlg.DoModal()==IDOK){ char buf[40]; char rep[40]; char *par; CString str; int iSelect = m_port_no; if ( 0 == m_port_io ) // Doesn't support Port I/O, so 0 ==> Port 1 iSelect++; if ( m_is8000 && iSelect >= 2 ) // is 8000, so 2 ==> Port 3, 3 ==> Port 4 iSelect++; // Set Baud by Xserver Protocol 06 //sprintf(buf,"06%1d%s",iSelect,dlg.m_baud.GetBuffer(10)); if ( iSelect <= 9 ) sprintf(buf,"06%1d%s", iSelect, dlg.m_baud.GetBuffer(10)); else sprintf(buf,"06%1c%s", iSelect-10+'A', dlg.m_baud.GetBuffer(10)); SendReceiveCmd(buf,rep,gdwTimeout); // Set LineControl by Xserver Protocol 07 par=dlg.m_parity.GetBuffer(5); //sprintf(buf,"07%1d%s%c%s\r",iSelect, dlg.m_databit.GetBuffer(1), // par[0], dlg.m_stopbit.GetBuffer(1)); if ( iSelect <= 9 ) sprintf(buf,"07%1d%s%c%s\r", iSelect, dlg.m_databit.GetBuffer(1), par[0], dlg.m_stopbit.GetBuffer(1)); else sprintf(buf,"07%1c%s%c%s\r", iSelect-10+'A', dlg.m_databit.GetBuffer(1), par[0], dlg.m_stopbit.GetBuffer(1)); SendReceiveCmd(buf,rep,gdwTimeout); // Get Com Status //sprintf(buf,"16%1d",iSelect); if ( iSelect <= 9 ) sprintf(buf,"16%1d",iSelect); else sprintf(buf,"16%1c",iSelect-10+'A'); SendReceiveCmd(buf,rep,gdwTimeout); m_com_status=rep; UpdateData(FALSE); } } int CGoGoDlg::Get7188EStatus() { TRACE( "Get7188EStatus\n" ); char rep[40]; //Sleep(1); (SendReceiveCmd("13\r", rep,gdwTimeout)==0)?m_gateway=rep :m_gateway="N/A"; //Sleep(1); (SendReceiveCmd("15\r", rep,gdwTimeout)==0)?m_mask=rep :m_mask ="N/A"; //Sleep(1); (SendReceiveCmd("21\r", rep,gdwTimeout)==0)?m_mac=rep :m_mac ="N/A"; //Sleep(1); (SendReceiveCmd("01\r", rep,gdwTimeout)==0)?m_fw_ver=rep :m_fw_ver ="N/A"; //Sleep(1); (SendReceiveCmd("22\r", rep,gdwTimeout)==0)?m_os_ver=rep :m_os_ver ="N/A"; //Sleep(1); if ( 1 == m_port_io && 0 == m_port_no ) // select port_io m_com_status = "N/A"; else (SendReceiveCmd("161\r",rep,gdwTimeout)==0)?m_com_status=rep:m_com_status="N/A"; return 0; } int CGoGoDlg::SendReceiveCmd(char *cmd, char *response, DWORD timeout) { TRACE( "SendReceiveCmd\n" ); char RetString[2048]; int len=0; DWORD start; response[0] = 0; len=sock.Receive(RetString,sizeof(RetString),NULL); sock.Send(cmd,strlen(cmd),0); Sleep(1); start=GetTickCount(); while(1){ if(GetTickCount()>start+timeout) return -1; //timeout len=sock.Receive(RetString,sizeof(RetString),NULL); if(len>0){ if ( 0x0D == RetString[len-1] ) RetString[len-1] = 0; else RetString[len] = 0; strcpy(response,RetString); return 0; // catch data } Sleep(1); } } int CGoGoDlg::YenModifyFormat(CString *str) { TRACE( "YenModifyformat\n" ); char tmp[4][4]; char tmp1[20]; char buf[20]; UINT j=0,k=0; strcpy(tmp1,str->GetBuffer(20)); for(UINT i=0;i>4; high=(char)(chksum&0x0f); if (high>=10) ascii=high-10+'A'; else ascii=high+'0'; csbuf[0]=ascii; if (low>=10) ascii=low-10+'A'; else ascii=low+'0'; csbuf[1]=ascii; csbuf[2]=0; } void CGoGoDlg::OnCloseBtn() { TRACE( "OnCloseBtn\n" ); // TODO: Add your control notification handler code here KillTimer(1); if(bConnect==TRUE){ sock.Close(); if ( m_port_io == 1 ) sockIO.Close(); if ( m_port_count >= 1 ) sock1.Close(); if ( m_port_count >= 2 && !m_is8000 ) // Not 8000 sock2.Close(); if ( m_port_count >= 3 ) sock3.Close(); if ( m_port_count >= 4 ) sock4.Close(); if ( m_port_count >= 5 ) sock5.Close(); if ( m_port_count >= 6 ) sock6.Close(); if ( m_port_count >= 7 ) sock7.Close(); if ( m_port_count >= 8 ) sock8.Close(); if ( m_port_count >= 9 ) sock9.Close(); if ( m_port_count >= 10 ) sock10.Close(); if ( m_port_count >= 11) sock11.Close(); if ( m_port_count >= 12 ) sock12.Close(); } CGoGoDlg::OnOK(); } void CGoGoDlg::OnbtnSendCmd() { TRACE( "OnBtnSendCmd\n" ); // TODO: Add your control notification handler code here int len; UpdateData(TRUE); len=m_send_cmd.GetLength(); if(len==0)return; m_send_cmd_ack=""; UpdateData(FALSE); CString str; CString str_send; str_send=m_send_cmd; sock.Send(str_send.GetBuffer(len),len,0); } void CGoGoDlg::OnbtnClearCmd() { TRACE( "OnbtnClearCmd\n" ); // TODO: Add your control notification handler code here m_send_cmd_ack=""; UpdateData(FALSE); } void CGoGoDlg::OnbtnConnect() { TRACE( "OnConnect\n" ); // TODO: Add your control notification handler code here if(bConnect==TRUE) return; bConnect=TRUE; UpdateData(TRUE); // Create Sock sock.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); DWORD StartTime; StartTime=GetTickCount(); again: // Connect Sock sock.Connect( m_ip.GetBuffer(20),PORT_CMD ); Sleep(1000); sock.Send("10\r",3,0); Sleep(1000); char lpBuf[256]; int len; m_port_count = 0; m_port_io = 0; m_is8000 = 0; len=sock.Receive(lpBuf,256,NULL); if(len>0){ if ( 0x0D == lpBuf[len-1] ) lpBuf[len-1] = 0; else lpBuf[len] = 0; m_status=lpBuf; if ( lpBuf[0] == '7' && lpBuf[1] == '1' && lpBuf[2] == '8' && lpBuf[3] == '8' && lpBuf[4] == 'E' ) { if ( lpBuf[5] == 'A' ) { // 7188EA m_port_count=2; m_port_io =1; } else if ( lpBuf[5] == 'A' ) // 7188EX m_port_count=2; else // 7188En m_port_count = lpBuf[5] - '0'; } if ( lpBuf[0] == '8' && lpBuf[2] == '3' ) { // 8x3x m_port_io = 1; m_is8000=1; if ( lpBuf[3] == '0' ) // 8x30 m_port_count = 3; else // 8x31 m_port_count = 4; if ( lpBuf[4] == '-' ) { // with 8412 m_port_count = atoi( &(lpBuf[5]) ); } } // Port I/O if ( m_port_io == 1 ) { sockIO.Create(0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sockIO.Connect(m_ip.GetBuffer(20),PORT_CMD - 1); } // Port 1 if ( m_port_count >= 1 ) { sock1.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock1.Connect( m_ip.GetBuffer(20),PORT_CMD + 1); } // Port 2 if ( m_port_count >= 2 && !m_is8000) { sock2.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock2.Connect( m_ip.GetBuffer(20),PORT_CMD + 2); } // Port 3 if ( m_port_count >= 3 ) { sock3.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock3.Connect( m_ip.GetBuffer(20),PORT_CMD + 3); } // Port 4 if ( m_port_count >= 4 ) { sock4.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock4.Connect( m_ip.GetBuffer(20),PORT_CMD + 4); } // Port 5 if ( m_port_count >= 5 ) { sock5.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock5.Connect( m_ip.GetBuffer(20),PORT_CMD + 5); } // Port 6 if ( m_port_count >= 6 ) { sock6.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock6.Connect( m_ip.GetBuffer(20),PORT_CMD + 6); } // Port 7 if ( m_port_count >= 7 ) { sock7.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock7.Connect( m_ip.GetBuffer(20),PORT_CMD + 7); } // Port 8 if ( m_port_count >= 8 ) { sock8.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock8.Connect( m_ip.GetBuffer(20),PORT_CMD + 8); } // Port 9 if ( m_port_count >= 9 ) { sock9.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock9.Connect( m_ip.GetBuffer(20),PORT_CMD + 9); } // Port 10 if ( m_port_count >= 10 ) { sock10.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock10.Connect( m_ip.GetBuffer(20),PORT_CMD + 10); } // Port 11 if ( m_port_count >= 11 ) { sock11.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock11.Connect( m_ip.GetBuffer(20),PORT_CMD + 11); } // Port 12 if ( m_port_count >= 12 ) { sock12.Create( 0,SOCK_STREAM,FD_CONNECT|FD_CLOSE|FD_WRITE); sock12.Connect( m_ip.GetBuffer(20),PORT_CMD + 12); } if (0 != m_port_count || 0 != m_port_io) AddPortSelect(); m_status+=" is connected"; m_port_no = 0; //if ( 1 == m_port_io ) // m_port_no=0; // Port I/O //else // m_port_no=1; // Port 1 Get7188EStatus(); } else{ if(GetTickCount()<(StartTime+5000))goto again; //m_status="7188e doesn't exist."; m_status="Connection timeout..."; } m_connect.EnableWindow(FALSE); m_disconnect.EnableWindow(TRUE); UpdateData(FALSE); } void CGoGoDlg::OnbtnDisconnect() { TRACE( "OnDisconnect\n" ); // TODO: Add your control notification handler code here if(bConnect==FALSE)return; bConnect=FALSE; m_status="Disconnect..."; UpdateData(FALSE); sock.Close(); // port I/O if ( m_port_io == 1 ) sockIO.Close(); // port 1 if ( m_port_count >= 1 ) sock1.Close(); // port 2 if ( m_port_count >= 2 && !m_is8000 ) sock2.Close(); // port 3 if ( m_port_count >= 3 ) sock3.Close(); // port 4 if ( m_port_count >= 4 ) sock4.Close(); // port 5 if ( m_port_count >= 5 ) sock5.Close(); // port 6 if ( m_port_count >= 6 ) sock6.Close(); // port 7 if ( m_port_count >= 7 ) sock7.Close(); // port 8 if ( m_port_count >= 8 ) sock8.Close(); // port 9 if ( m_port_count >= 9 ) sock9.Close(); // port 10 if ( m_port_count >= 10 ) sock10.Close(); // port 11 if ( m_port_count >= 11 ) sock11.Close(); // port 12 if ( m_port_count >= 12 ) sock12.Close(); ResetPortCombo(); m_connect.EnableWindow(TRUE); m_disconnect.EnableWindow(FALSE); }