Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

PROGRAMMING A MODEM

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
bmuita
Asked:
bmuita
  • 3
  • 2
  • 2
  • +1
1 Solution
 
cookreCommented:
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
 
cookreCommented:
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
 
jhanceCommented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
mahnoCommented:
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
 
mahnoCommented:
upss.. change:
char *str = "ati\n";
to:
char *str = "ats0=1\n";

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

~Brian
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now