Posted on 2000-03-19
Medium Priority
Last Modified: 2010-04-02
I know how to access the ports and all but the thing that I need to know is how to send commands to the modem eg dial, answer etc etc. Most of the manual I have picked up just tell me the commands are AT ATA ATD but that isn't much help..

Question by:bmuita
  • 3
  • 2
  • 2
  • +1
LVL 22

Accepted Solution

cookre earned 400 total points
ID: 2633523
All you need to do is send the commands in ASCII as documented to the port (followed by a CR(0x0d)), then keep reading the port waiting for the response.  If a command calls for a numeric value, send the ASCII digits, not binary (usually).

When reading the resonse, you'll need to include a timeout test and you'll probably want to do two or three retries on timed-out of failed commands.

To simplify coding, you may want to write a generic command sender with a return of the response from the modem or a time-out flag.

LVL 22

Expert Comment

ID: 2633548
Some examples:

send 'atdt5551212<cr>' (quotes not included and <cr> is 0x0d)

then wait for your desired timeout period looking for some response from the modem (CONNECTED, BUSY, etc).

Set modem's after dial carrier wait timeout:
send 'ats7=45<cr>'

Was this the sort of thing you were looking for?
LVL 32

Expert Comment

ID: 2633622
Is this a Windows app?  

If so, I'd suggest you abandon this altogether and look at using TAPI to do this job.  TAPI "knows" how to dial any modem which has been configured into Windows, even it it's not a Hayes/AT type modem.  There is also a lot more to running a modem than just getting it to dial.  Again, TAPI includes complete call and line management.

There is a lot of TAPI information in the Windows SDK but I'd suggest you pickup a copy of Chris Sells' "Windows Telephony Programming" book.  It covers TAPI from start to finish and is the best and fastest way to get started.

There is also a significant amount of TAPI information a www.codeguru.com.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Expert Comment

ID: 2635141
Hi bmuita,

U need to open com port as file:

  *hCom = CreateFile("COM1",       /*port name*/
    GENERIC_READ | GENERIC_WRITE,   /*access mode*/
    0,                              /*share mode: must be opened w/exclusive-access*/
    NULL,                           /*no security attrs*/
    OPEN_EXISTING,                  /*must use OPEN_EXISTING*/
    0,                              /*not overlapped I/O*/
    NULL                            /*hTemplate must be NULL for comm*/

setup port:
  if (!SetupComm(*hCom, COM_IN_QUEUE_SIZE, COM_OUT_QUEUE_SIZE))      {
        return 0;


  dcb.DCBlength = sizeof(DCB);
  GetCommState(*hCom, &dcb);

  dcb.BaudRate          = COMSPEED;
  dcb.ByteSize          = 8;
  dcb.Parity            = NOPARITY;
  dcb.StopBits          = ONESTOPBIT;
  dcb.fParity           = TRUE;
  dcb.fInX=dcb.fOutX    = 0;

  dcb.fRtsControl       = RTS_CONTROL_HANDSHAKE;
  dcb.fDtrControl       = DTR_CONTROL_ENABLE;
  dcb.fBinary           = TRUE;

  dcb.fDsrSensitivity   = TRUE;
  dcb.fOutxCtsFlow      = TRUE;
  dcb.fOutxDsrFlow      = TRUE;

  if (!SetCommState(*hCom, &dcb))      {
        DbgOutStr("can't set DCB");
        return 0;

  Timeouts.ReadIntervalTimeout          = MAXDWORD;
  Timeouts.ReadTotalTimeoutMultiplier   = 0; /*MAXDWORD*/
  Timeouts.ReadTotalTimeoutConstant     = 1000; /*100*/
  Timeouts.WriteTotalTimeoutMultiplier  = 0;
  Timeouts.WriteTotalTimeoutConstant    = 1000;

  if (!SetCommTimeouts(*hCom, &Timeouts)) {
        return 0;

....and work with it:

WriteFile(hCom, str, strlen(str), &res, NULL)

res = ReadFile(hCom, str, PORT_MAX_READ, len, NULL);

for example if wont to set autoanswer mode, try this:

/*put to port*/
char *str = "ati\n";
WriteFile(hCom, str, strlen(str), &res, NULL);

/*get response from port U can using ReadFile()*/

hope this helps,


Expert Comment

ID: 2635146
upss.. change:
char *str = "ati\n";
char *str = "ats0=1\n";


Author Comment

ID: 2654776
Sorry to reject your answer Mahno but Cookre gave me the correct solution first so the points got to him ... but one more thing how do I find the irq of the serial port I wish to work with is it in the segment 0x40 or something ??
LVL 22

Expert Comment

ID: 2655277
These are configurable, so you will need to double check, but the defaults are:

COM1: port 3f8, irq 4
COM2: port 2f8, irq 3

Segment 40 is a general BIOS & DOS storage.  The only items there dealing with serial I/O are at 0040:0000 throuth 0040:0007 and are the I/O addresses of up to 4 comm adapters and are used by int14h.

I took some dumps and, sure enough, 0040:0000,0001 had f8,03 (com1 port) and 0040:0002,0003 had f8,02 (com2 port).

One can safely then assume that 0040:0000-0007 are populated by CMOS setup or any piece of software that let's you change port addresses.

Author Comment

ID: 2656119
I did just as you said, send the commands in ascii followed by a carriage
return and it work. Thanks.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question