Results 1 to 3 of 3

Thread: Modem Fun, Hayes AT Commands

  1. #1
    Senior Member tampabay420's Avatar
    Join Date
    Aug 2002

    Post Modem Fun, Hayes AT Commands

    Another Cool ‘newbie’ project...

    Hayes AT Commands and how they can easily be implemented into your code, giving your application the ability to command the modem with very little effort. You, of course, must have a Hayes compatible modem and be connected to a phone line. Now- lets start...

    Opening a "COM": When attempting to access the modem, you must first open a "COM" this depends on how you have your modem set up. You may be on "COM1" or "COM4" , etc... it all depends on your settings. Make sure you open the right "COM" or your commands will be ignored. Here is an example (in BASIC) of how one would open "COM" for output...

    'BASIC Source Code
    Open "COM3" for Output as #1
    Print #1, "ATDT 555-1234"
    Print #1, "ATZ"
    Close #1

    The previous code opens "COM3" for output. Prints "AT" , this tells the modem that it is a command. The "D" is for Dial and the "T" for tone. "Z" resets the modem.

    After you call a number you can read data from the COM using “Input #1, Var”, Where Var is the variable the data is stored. If the value of Var is null or 0 then there is nothing to talk to, or handshake… If you do get data , probably something like “OK, Connected at 9600” then there is another computer on the other end.

    This is again a small Tutorial for Newbies. You can useany language you want to implement the AT Commands (I used BASIC, but you can do this with anything from C to Perl.) I hope this can be a fun project for any newbie/non-newbie with a small bit programming knowledge and a few hours to mess with their modem … Positive AntiPoints are greatly appreciated!

    Here is a small list of AT Commands... And the syntax to use them:

    > The command text should start with "AT" or "at", except for the commands "A/" and "+++". Keep the Case the same; "At" or "aT" wont work.

    > Several commands can be given in one command line. I wouldn’t do this, just to make things simple. But please- experiment...

    > The commands can be given in upper or lower case. I like Upper case.

    > A command text should contain less than 40 characters. If len(CMD$) > 40 then Exit Sub

    > Commands and command texts must be terminated with an <ENTER> or Carriage return [Char$(13)], except +++ and A/

    > A telephone number can exist of following characters:
    1 2 3 4 5 6 7 8 9 * = , ; # + > . All other characters are ignored (spaces, underscores, etc...)

    > After the command "ATZ" (Modem Reset) has been issued, a pause of two-three seconds should be respected before entering the next command.

    I have included a few commands in the zip file...
    yeah, I\'m gonna need that by friday...

  2. #2
    It's a gas!
    Join Date
    Jul 2002
    Nice tut, pity about this:

    Positive AntiPoints are greatly appreciated!
    Tut tut, shouldnt you know better than to ask for AP's, it does nothing but get you negged my friend!


  3. #3
    Senior Member
    Join Date
    Jun 2002
    this works in C++ also, simpley create a filestream to the correct COM port.
    you should always leave a suitable timeout so that the modem doesn't get confused. ie, has time to dial the number before hanging up.
    #include <fstream>
    #include <time.h> //for sleep function to give a nice timeout
    void main() {
    int phonenumber = 1234555 ;
    ostream modem("COM1:") ; //opens the stream
    modem << "ATZ\n" ; //reset modem
    modem.flush() ; //flush the buffer
    modem << "ATH1\n" ; //take modem off-hook (picking phone up)
    modem.flush() ;
    modem << "ATC\n" ; //turn off modem carrier
    modem.flush() ;
    modem << "ATDT" << phoneNumber << "\n" ; //dial number
    modem.flush() ;
    Sleep(100) ;
    modem << "ATH0\n" ; //back on-hook
    modem.flush() ;
    Hmm...theres something a little peculiar here. Oh i see what it is! the sentence is talking about itself! do you see that? what do you mean? sentences can\'t talk! No, but they REFER to things, and this one refers directly-unambigeously-unmistakably-to the very sentence which it is!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts