Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Modem Communication ! Urgent

Posted on 1998-07-07
8
Medium Priority
?
243 Views
Last Modified: 2013-11-19
I have to develop an application using MFC & VC++ & Windows APIs  for communicating with the modem .If anybody has an
idea about this , please reply back with a detailed  explanation .
                   Thank you ,
                        sankar
0
Comment
Question by:sankar012898
[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
  • 4
  • 3
8 Comments
 

Author Comment

by:sankar012898
ID: 1318822
Edited text of question
0
 

Author Comment

by:sankar012898
ID: 1318823
Edited text of question
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1318824
For Win32?
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 4

Expert Comment

by:piano_boxer
ID: 1318825
Here is some code for opening any comport and setup parameters.
nPort: 0=COM1, 1=COM2....

*************

HANDLE OpenCommPort(int nPort, int nBaudrateIdx)
{

    HANDLE hPort;
    CString strPort;
    if(nPort<10)
        strPort.Format(_T("COM%d"), nPort);
    else
        strPort.Format(_T("\\\\.\\COM%d"), nPort);

    // Open COM1.....COMx
    hPort = CreateFile(strPort,GENERIC_READ|GENERIC_WRITE,
        0,    /* comm devices must be opened w/exclusive-access */
        NULL, /* no security attrs */
        OPEN_EXISTING, /* comm devices must use OPEN_EXISTING */
        0,
        NULL  /* hTemplate must be NULL for comm devices */
        );
    if(hOPSPort == INVALID_HANDLE_VALUE)
        return NULL;

    // Setup timeout values for reading and writing to the port
    COMMTIMEOUTS ctmo;
    ctmo.ReadIntervalTimeout = 100;
    ctmo.ReadTotalTimeoutMultiplier = 1;
    ctmo.ReadTotalTimeoutConstant = 2000;
    ctmo.WriteTotalTimeoutMultiplier = 1;
    ctmo.WriteTotalTimeoutConstant = 1000;
    SetCommTimeouts(hPort, &ctmo);

    const int br[] = { 300, 1200, 2400, 4800, 9600, 14400, 19200 };

    // Setup port to use CTS/RTS hardware flow control with 8 databits
    // 1 stopbit and no parity.

    DCB dcb;
    ZeroMemory(&dcb, sizeof(dcb));
    dcb.DCBlength = sizeof(DCB);
    dcb.BaudRate = br[nBaudrateIdx];
    dcb.fBinary = TRUE;
    dcb.fParity = 0;
    dcb.fOutxCtsFlow = 1;
    dcb.ByteSize = 8;
    dcb.Parity = NOPARITY;
    dcb.StopBits = 0;
    dcb.fDtrControl = DTR_CONTROL_ENABLE;
    dcb.fRtsControl = RTS_CONTROL_ENABLE;
    dcb.fAbortOnError = FALSE;
    if(!SetCommState(hPort, &dcb))
    {
        CloseHandle(hPort);
        hPort = INVALID_HANDLE_VALUE;
        return NULL;
    }

    return hPort;
}

********

To read and write to the port, just use the normal ReadFile()/WriteFile() functions

Here is an example of how to reset the modem:

BOOL ResetModem(HANDLE hPort)
{
    CString sCmd = _T("Z\n");

    DWORD dwIOLen;
    if(WriteFile(hPort, sCmd, sCmd.GetLength(), &dwIoSize, NULL))
    {
        return TRUE;
    }

    return FALSE;
}

Off-cause you would want to check the responses from the modem when sending
commands or dialing but that is just basic Win32 IO.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1318826
Please refer to online manual about the following functions.
GetCommState
SetCommState
SetupComm
CreateFile

There is an example on the VC5 CD: \Devstudio\Vc\Samples\Sdk\Win32\Comm
Theses sites can also give you some help.

http://www.qfax.com/
http://www.goodnet.com/~esnible/winsock.html 
 
0
 

Author Comment

by:sankar012898
ID: 1318827
hi piano_boxer & trestan,
              Thanks for your reply . I understood your  code .
 Infact I have  programmed the COM port myself in a similar way  for communicating  with Barcode readers and printers but I  wanted  to  know  how to  dial a  telephone number by a
program  when the modem is connected to a com port and
 also how to send  data over telephone wires .
0
 
LVL 4

Accepted Solution

by:
piano_boxer earned 400 total points
ID: 1318828
All commands is sent to the modem using the AT prefix:

1. Initialize moden (
    SEND: ATZ\n    (Or whatever appropriate)
    WAIT: OK, ERROR, (Timeout)

2. Dial phone number
    SEND: ATDT12345678\n (12345678 is the number to call)
    WAIT: CONNECT  (Modem connected OK. Can be followed by connect speed)
          ERROR\r\n    (Error in command)
          NO CARRIER\r\n, NO ANSWER\r\n (No reply from other modem)
          BUSY\r\n     (Line is busy)



2a.  Is CONNECT is the response from dialog then the modem will switch to datamode and you can send/receive data.

3. Disconnect (There are two methods):

    Method 1:   Lower the DTR hardware line
                (EscapeCommFunction(hPort, CLRDTR));

    Method 2:   Send + (plus character) three times with a small
                delay in between. The modem will the switch to
                command mode. Send ATH0\n to hang up.

0
 

Author Comment

by:sankar012898
ID: 1318829
Hi piano_boxer,
         Thanks  for your  answer .
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

705 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