Solved

PROGRAMMING A MODEM

Posted on 2000-03-19
8
243 Views
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..

~Brian
0
Comment
Question by:bmuita
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 22

Accepted Solution

by:
cookre earned 100 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.





0
 
LVL 22

Expert Comment

by:cookre
ID: 2633548
Some examples:

Dialing:
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?
0
 
LVL 32

Expert Comment

by:jhance
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.
0
Technology Partners: 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!

 
LVL 1

Expert Comment

by:mahno
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;
  }

  PurgeComm(*hCom, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);

  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,
  mahno

0
 
LVL 1

Expert Comment

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

0
 

Author Comment

by:bmuita
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 ??
0
 
LVL 22

Expert Comment

by:cookre
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.
0
 

Author Comment

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

~Brian
0

Featured Post

Industry Leaders: 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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

691 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