Page 215 - PDA Robotics Using Your Personal Digital Assistant to Control Your Robot
P. 215

PDA 09  5/27/03  8:50 AM  Page 191
                                   }
                                   return TRUE; Chapter 9 / PDA Robot Software for Pocket PC 2002
                                 }
                                 //
                                 // StartApplication sets the connection parameters and
                                 // calls ConnectSocket. If the connection fails ensure
                                 // that the Control Center (which acts as the Server )
                                 // is running.
                                 //
                                 BOOL CPDABotDlg::StartApplication()
                                 {
                                   m_strHandle="7";
                                   m_hostname.GetWindowText(m_strServer);
                                   m_nChannel=7;

                                   if (ConnectSocket(m_strHandle, m_strServer, m_nChannel))
                                        return TRUE;
                                   else
                                   {
                                      this->m_status_window.SetWindowText( (LPCTSTR) CString("Connection Failed ") );
                                      return FALSE;
                                   }
                                 }
                                 //
                                 // ReadPDAData() Is called when the CESocket signals that
                                 // data has arrived from the Command Center. The data is
                                 // a string indicating that the connection was successful
                                 // or a Motion command that will be relayed to PDA Robots
                                 // body.
                                 //
                                 void CPDABotDlg::ReadPDAData()
                                 {


                                   CString status_message;
                                   char szMessage[512];
                                   static int initialized;
                                   u_long numbytes;
                                   int ret;
                                   //
                                   // Ensure that we won't be blocked waiting here on the call
                                   // to read the data.
                                   //

                                   ret = ioctlsocket ((SOCKET) m_pSocket, FIONREAD, &numbytes);
                                   if( (ret == 0) && (numbytes > 0) )

                                                                                               191
   210   211   212   213   214   215   216   217   218   219   220