Solved

PROGRAMMING A MODEM

Posted on 2000-03-19
8
221 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
  • 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

776 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