Click here to Skip to main content
13,192,426 members (47,996 online)
Click here to Skip to main content
Add your own
alternative version


80 bookmarked
Posted 30 Oct 2004

How to establish communication between mobile phone and PC

, 30 Oct 2004
Rate this:
Please Sign up or sign in to vote.
This article deals with building a communication link between your mobile and your PC. It also deals with the ways to execute commands on your mobile phone interpreter from your PC.


The article provides a step by step tutorial about the method to connect your mobile phone to your PC using serial communication. It describes the methods to execute phone specific commands via your PC.

PC and mobile phone communication can be established by three ways:

  1. serial port (requires a data cable).
  2. infra red port (requires infrared port on your mobile and PC).
  3. Bluetooth (requires Bluetooth wireless connector).

(Note: I have just worked on serial port and infrared.)


Initialize and open port:

/* portNm =COM1,COM2 etc which ever COM port your phone is connected */

bool OpenPort( char *portNm )  
if( portNm != NULL ) // check to if port exists
/* hComm is handle that makes a buffer file pointin to your
   COM port for read and write of port data */

    hComm = CreateFile( portNm,GENERIC_READ | GENERIC_WRITE, 

    if (hComm == INVALID_HANDLE_VALUE)
        //error occured alert user about error            
        return false;
            // port opened successfully alert user
       return true;

      // specified port missing alert user
          return false;


Write To Port:

BOOL WriteABuffer(char * lpBuf, DWORD dwToWrite)
   OVERLAPPED osWrite = {0};
   DWORD dwWritten;
   BOOL fRes;

   // Issue write.
   if (!WriteFile(hComm, lpBuf, dwToWrite, &dwWritten, NULL)) 
      if (GetLastError() != ERROR_IO_PENDING) 
      {  // WriteFile failed, but it isn't delayed. Report error and abort.
          fRes = FALSE;
         // Write is pending.

         if (!GetOverlappedResult(hComm, &osWrite, &dwWritten, TRUE))
             fRes = FALSE;}
         {  // Write operation completed successfully.

             fRes = TRUE;}
      // WriteFile completed immediately.

      fRes = TRUE;
   return fRes;

Read Port:

void ReadPort()

    DWORD dwRead;        
    char  chRead[250];  

// remember to adjust 250 according to the total data read
         char *count = NULL;
/* flush the old values and fill with some arbitary symbol 
   thats most unlikely to appear in your data to know
   the end point after reading */


    Sleep( 5L);

    ReadFile(hComm, chRead, 250, &dwRead, NULL); 

/* now chRead contains data . you can manipulate
   it accoring to your needs now. */


Special setting:

After you call OpenPort, you must assign the DCB and connection timeout to the port. DCB is used to adjust communication settings of the port. You must set your port according to your needs depending upon your communication requirement.

Connection timeouts are used to assign the time for which port must forcibly stop reading data from your mobile phone to prevent abnormality in case of very long data.

if(OpenPort("COM4"))  // opens COM4 port
  DCB dcb
        dcb.fOutxCtsFlow = false;    // Disable CTS monitoring
        dcb.fOutxDsrFlow = false;    // Disable DSR monitoring
    dcb.fDtrControl = DTR_CONTROL_DISABLE;    // Disable DTR monitoring
    dcb.fOutX = false;        // Disable XON/XOFF for transmission
    dcb.fInX = false;        // Disable XON/XOFF for receiving
    dcb.fRtsControl = RTS_CONTROL_DISABLE;    // Disable RTS (Ready To Send)

   COMMTIMEOUTS timeouts;

    timeouts.ReadIntervalTimeout = 20; 
    timeouts.ReadTotalTimeoutMultiplier = 10;
    timeouts.ReadTotalTimeoutConstant = 100;
    timeouts.WriteTotalTimeoutMultiplier = 10;
    timeouts.WriteTotalTimeoutConstant = 100;

    if (!SetCommTimeouts(hComm, &timeouts))
      // error with time outs .alert user and exit


The above piece of code can be used to establish effective communication between a PC and a mobile phone.

You can issue phone specific commands to the phone interpreter which will do the processing and will return data on same port after processing. Hayes AT commands can be used with most of the phones (these are phone specific, so please check for the compatibility of these commands with your phone ). Nokia AT command set is available at Nokia official website.

AT commands can be used to perform various functions like sending/receiving SMS to your PC connected to mobile phone, synchronizing the mobile phone book, changing phone settings, and lots more.

Hope the article proves to be useful, and for any other query, you can always contact me at


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States

Some projects of interest completed :

1> AUTOMATED SMS RESPONSE SYSTEM : A complete software in VC++ . Replies(sending an SMS via mobile phone connected at serial port) automatically to the user who queries(received as SMS on mobile phone connected at serial port) by searching the database and sending back the appropriate reply.User can query from anywhere in the world.Can be used for various concepts like query airline reservations status,movie tickets,weather reports etc.

2> SMART HOME - THORUGH SMS : The concept of SMART HOME implemented through SMS. Automatically swicthes off/on any electric equipment connected to PC(designed a hardware relay circuit for that) just by sending an SMS from anywhere to the mobile phone connected to your PC

For any kind of help or guidance plz free to contact me at

You may also be interested in...


Comments and Discussions

Generalhelp me on how to access information from the server using mobile phones Pin
kamyuk8-Mar-10 21:44
memberkamyuk8-Mar-10 21:44 
Generalplease help me in this project Pin
arivu_web18-Feb-09 15:52
memberarivu_web18-Feb-09 15:52 
Generalproblem in reading in data from mobile through serial com Pin
manju23reddy4-Sep-08 20:07
membermanju23reddy4-Sep-08 20:07 
Generalhelpme in sms bluetooth Pin
mohammed qaid29-Apr-08 7:37
membermohammed qaid29-Apr-08 7:37 
QuestionError in code Pin
D. PAUL20-Nov-07 22:10
memberD. PAUL20-Nov-07 22:10 
GeneralFor Project Pin
Nkeyur29-Jun-07 8:33
memberNkeyur29-Jun-07 8:33 
GeneralAT command help! Pin
Leo_133121-Jun-07 3:28
memberLeo_133121-Jun-07 3:28 
Questionpleas help me Pin
waseem_brhoom12312-May-07 5:58
memberwaseem_brhoom12312-May-07 5:58 
QuestionMY project iscontrolling home via sms [modified] Pin
naveed_kaan1-May-07 9:29
membernaveed_kaan1-May-07 9:29 
Generalhelp me please!!!!! Pin
dinhtrungac17-Apr-07 22:26
memberdinhtrungac17-Apr-07 22:26 
Generalmy project is smart house through sms message Pin
Member #38374371-Mar-07 15:38
memberMember #38374371-Mar-07 15:38 
Generalhelp me Pin
Nkeyur29-Jun-07 8:53
memberNkeyur29-Jun-07 8:53 
Generalcommunication b/w mobile n pc thru sms Pin
sushant_8630-Jan-07 4:36
membersushant_8630-Jan-07 4:36 
GeneralSending SMS's using this code Pin
xaml.net13-Jan-07 2:25
memberxaml.net13-Jan-07 2:25 
Generalhelp, for code in C, for mobile to PC communication Pin
sadafp30-Jul-06 7:16
membersadafp30-Jul-06 7:16 
QuestionHelp in communication b/w mobile n PC Pin
Nauman Rahim26-Jul-06 20:08
memberNauman Rahim26-Jul-06 20:08 
AnswerRe: Help in communication b/w mobile n PC Pin
sadafp30-Jul-06 7:18
membersadafp30-Jul-06 7:18 
QuestionRe: Help in communication b/w mobile n PC Pin
smah8020-Dec-06 1:27
membersmah8020-Dec-06 1:27 
AnswerRe: Help in communication b/w mobile n PC Pin
gururaghu124-Feb-07 2:00
membergururaghu124-Feb-07 2:00 
GeneralHelp in communication b/w mobile n PC Pin
Nkeyur29-Jun-07 8:43
memberNkeyur29-Jun-07 8:43 
QuestionHow to detect the IR port Pin
rahul_s9996-Apr-06 14:00
memberrahul_s9996-Apr-06 14:00 
Generaldatabase access from a PC using a smartphone or pda or pocket PC via bluetooth Pin
nishitkumar3-Apr-06 23:43
membernishitkumar3-Apr-06 23:43 
Generalcommunication using data cable Pin
BHARATH RAJ M N4-Mar-06 16:38
memberBHARATH RAJ M N4-Mar-06 16:38 
QuestionHow to detect an incomming call on Smart Phones Pin
Zubair Mindfire4-Mar-06 0:22
memberZubair Mindfire4-Mar-06 0:22 
Questionhelp needed in project Pin
ashish_raghu28-Feb-06 22:05
memberashish_raghu28-Feb-06 22:05 
Generalinfo required Pin
adithya K.N23-Feb-06 22:44
memberadithya K.N23-Feb-06 22:44 
Generalmobile to PC WIRELESS communication Pin
Anonymous16-Oct-05 9:38
sussAnonymous16-Oct-05 9:38 
Generalmobile to PC WIRELESS communication Pin
Anonymous16-Oct-05 9:38
sussAnonymous16-Oct-05 9:38 
QuestionHow to Hook and run my code at startup for Mobile series 60 Pin
Girishmk27-Apr-05 9:06
memberGirishmk27-Apr-05 9:06 
Generaltransfer data using IStream IR Pin
riki_risnandar24-Dec-04 0:42
memberriki_risnandar24-Dec-04 0:42 
GeneralRe: transfer data using IStream IR Pin
nitzbajaj24-Dec-04 9:00
membernitzbajaj24-Dec-04 9:00 
Generalvbcode for mobile-pc communication Pin
sithan19-Dec-04 16:30
susssithan19-Dec-04 16:30 
GeneralRe: vbcode for mobile-pc communication Pin
nitzbajaj20-Dec-04 10:58
membernitzbajaj20-Dec-04 10:58 
GeneralRe: vbcode for mobile-pc communication Pin
roufi25-Mar-06 21:12
memberroufi25-Mar-06 21:12 
GeneralRe: vbcode for mobile-pc communication Pin
rakesh364bits27-Nov-06 6:22
memberrakesh364bits27-Nov-06 6:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171017.2 | Last Updated 31 Oct 2004
Article Copyright 2004 by nitzbajaj
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid