Thread: [Dev-C++] Modem Configuration
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Evandro H. R. <ero...@ro...> - 2002-09-11 16:13:40
|
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 mak=
e
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 H. Rodrigues
Ind=FAstrias ROMI S/A - Brazil
Quality Assurance Dep F14-07
Phone: 55-19-455-9529
Fax: 55-19-455-9084
email: ero...@ro...
---------- 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 =3D "COM2";
using namespace std;
hCom =3D CreateFile( pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0, // comm devices must be opened w/exclusive-acc=
ess
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTIN=
G
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
if (hCom =3D=3D 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 siz=
e
// of the input and output buffers with SetupComm.
fSuccess =3D GetCommState(hCom, &dcb);
if (!fSuccess) {
// Handle the error.
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
}
// Fill in the DCB: baud=3D57,600 bps, 8 data bits, no parity, and 1 st=
op
bit.
dcb.BaudRate =3D CBR_57600; // set the baud rate
dcb.ByteSize =3D 8; // data size, xmit, and rcv
dcb.Parity =3D NOPARITY; // no parity bit
dcb.StopBits =3D ONESTOPBIT; // one stop bit
fSuccess =3D SetCommState(hCom, &dcb);
if (!fSuccess) {
// Handle the error.
printf ("SetCommState failed with error %d.\n", GetLastError());
return (3);
}
string codigo =3D "ATDT 9092\n";
DWORD nBytes;
string lida =3D "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 << end=
l;
system("PAUSE");
return (0);
}
|
|
From: Evandro H. R. <ero...@ro...> - 2002-09-12 11:54:35
|
I found the problem...
In the line where is write: string codigo =3D "ATDT 9092\n";
Needs to be: char[] =3D "ATDT 9092\r\f";
The problem was the "\n" in the end of string, it is need to be "\r\f" th=
en
the modem knows that needs to execute the string.
Thanks
Evandro
----- Original Message -----
From: "Evandro Humberto Rodrigues" <ero...@ro...>
To: <Dev...@li...>
Sent: Wednesday, September 11, 2002 1:13 PM
Subject: [Dev-C++] Modem Configuration
> Hi people,
>
> I trying to produce a little program to configurate my external mod=
em
> (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 m=
ake
> 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 H. Rodrigues
> Ind=FAstrias ROMI S/A - Brazil
> Quality Assurance Dep F14-07
> Phone: 55-19-455-9529
> Fax: 55-19-455-9084
> email: ero...@ro...
>
> ---------- 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 =3D "COM2";
>
> using namespace std;
>
> hCom =3D 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_EXIST=
ING
> 0, // not overlapped I/O
> NULL // hTemplate must be NULL for comm devices
> );
>
> if (hCom =3D=3D 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 s=
ize
> // of the input and output buffers with SetupComm.
>
> fSuccess =3D GetCommState(hCom, &dcb);
>
> if (!fSuccess) {
> // Handle the error.
> printf ("GetCommState failed with error %d.\n", GetLastError());
> return (2);
> }
>
> // Fill in the DCB: baud=3D57,600 bps, 8 data bits, no parity, and 1 =
stop
> bit.
>
> dcb.BaudRate =3D CBR_57600; // set the baud rate
> dcb.ByteSize =3D 8; // data size, xmit, and rcv
> dcb.Parity =3D NOPARITY; // no parity bit
> dcb.StopBits =3D ONESTOPBIT; // one stop bit
>
> fSuccess =3D SetCommState(hCom, &dcb);
>
> if (!fSuccess) {
> // Handle the error.
> printf ("SetCommState failed with error %d.\n", GetLastError());
> return (3);
> }
>
> string codigo =3D "ATDT 9092\n";
> DWORD nBytes;
> string lida =3D "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);
> }
>
>
>
> -------------------------------------------------------
> In remembrance
> www.osdn.com/911/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Abhijit S. <mu...@gm...> - 2002-09-13 14:03:27
|
----- Original Message -----
From: "Evandro Humberto Rodrigues" <ero...@ro...>
To: <Dev...@li...>
Sent: Wednesday, September 11, 2002 9:43 PM
Subject: [Dev-C++] Modem Configuration
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.
---------- 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);
}
-------------------------------------------------------
I don't know much about what you're doing, but I think you should try
replacing this line:
if (WriteFile(hCom, &codigo, 10, &nBytes, NULL))
with
if (WriteFile(hCom, codigo.c_str(), codigo.size(), &nBytes, NULL))
because you're passing the address of the class instance in the first case,
and it's different from the contents of the buffer. Same thing with
ReadFile... you can't use `string's. Try replacing the usage of the string
class with normal ASCIIZ buffers... it should work then.
There's also some incorrect usage of namespace stuff that might work in this
version of GCC, but not in all ANSI compilers... I think Ioannis will be
happy to point them out if you want... :)
HTH.
___________________________________________________________
Abhijit Shylanath
E-mail: mu...@gm... || ibr...@bi...
Web-site: http://mudeth.tripod.com/
|
|
From: PhrostByte <Phr...@so...> - 2002-09-13 15:09:43
|
Okay, I'm new to directories in C - I just found out how to open/list them basically. I looked in the glibc manual (a lifesaver, that is!!) and came across S_ISDIR() but that doesn't seem to work for me. I'm trying to tell the difference between folder and file so I don't crash by fopen()ing a folder. Can somebody please help? Thanks in advance |