I trying to produce a little program to configurate my external modem
(USR 56K).
First I create a file with CreateFile() function, then I used
WriteFile() function to send the configuration strings to modem.
For test I sent a string like "ATDT 9092" to put the modem to dial to
the number 9092, but the ligths on the modem blink but modem does not make
the call...
Using HYPERTERMINAL, this work fine.
What is wrong?
I put the program below if someone can help me I will be grateful.
hCom = CreateFile( pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0, // comm devices must be opened w/exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
if (hCom == INVALID_HANDLE_VALUE) {
// Handle the error.
printf ("CreateFile failed with error %d.\n", GetLastError());
return (1);
}
// We will build on the current configuration, and skip setting the size
// of the input and output buffers with SetupComm.
fSuccess = GetCommState(hCom, &dcb);
if (!fSuccess) {
// Handle the error.
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
}
// Fill in the DCB: baud=57,600 bps, 8 data bits, no parity, and 1 stop
bit.
dcb.BaudRate = CBR_57600; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit
fSuccess = SetCommState(hCom, &dcb);
if (!fSuccess) {
// Handle the error.
printf ("SetCommState failed with error %d.\n", GetLastError());
return (3);
}
Hi people,
I trying to produce a little program to configurate my external modem
(USR 56K).
First I create a file with CreateFile() function, then I used
WriteFile() function to send the configuration strings to modem.
For test I sent a string like "ATDT 9092" to put the modem to dial to
the number 9092, but the ligths on the modem blink but modem does not make
the call...
Using HYPERTERMINAL, this work fine.
What is wrong?
I put the program below if someone can help me I will be grateful.
Thanks in advance
Evandro
---------- program -------------------------
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <string>
int main(int argc, char *argv[])
{
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
LPCVOID buffer;
char *pcCommPort = "COM2";
using namespace std;
hCom = CreateFile( pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0, // comm devices must be opened w/exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
if (hCom == INVALID_HANDLE_VALUE) {
// Handle the error.
printf ("CreateFile failed with error %d.\n", GetLastError());
return (1);
}
// We will build on the current configuration, and skip setting the size
// of the input and output buffers with SetupComm.
fSuccess = GetCommState(hCom, &dcb);
if (!fSuccess) {
// Handle the error.
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
}
// Fill in the DCB: baud=57,600 bps, 8 data bits, no parity, and 1 stop
bit.
dcb.BaudRate = CBR_57600; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit
fSuccess = SetCommState(hCom, &dcb);
if (!fSuccess) {
// Handle the error.
printf ("SetCommState failed with error %d.\n", GetLastError());
return (3);
}
string codigo = "ATDT 9092\n";
DWORD nBytes;
string lida = "1234567890123456789012345678901";
if (WriteFile(hCom, &codigo, 10, &nBytes, NULL))
cout << "Foram escritos " << nBytes << " Bytes" << endl;
if (ReadFile(hCom, &lida, 10, &nBytes, NULL))
cout << "String lida -> " << lida << " Bytes lidos " << nBytes << endl;
system("PAUSE");
return (0);
}