Solved

PROGRAMMING A MODEM

Posted on 2000-03-19
8
200 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Expert Comment

by:mahno
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

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

0
 

Author Comment

by:bmuita
Comment Utility
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
Comment Utility
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
Comment Utility
I did just as you said, send the commands in ascii followed by a carriage
return and it work. Thanks.

~Brian
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now