Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modem Programming

Status
Not open for further replies.

MacrosTheBlack

Programmer
Oct 9, 2003
3
GB
I'm writting an application to be used in windows 2000 and windows XP which programs up modems by sending them AT commands.

I've opened the connection to com1 fine but how ever i try to send the commands down i get errors.

If my serial port is defined as 'hCom' how can I send down commands like ATS0=1 ????
 
I am using modems on serial port too. I open the port as a file and writes it as a file.
As i understand it, your problem is not the port but the modem. To send 'ATS0=1' (Autoanswer on first ring) send the string "ATS0=1\r\n" to the modem, this should give back a "OK\r\n".
I open and closes the COM-port like this:
HANDLE __fastcall TForm1::Open_Com_Port(void)
{
DCB Comm_Port_DCB;
HANDLE COM_Handle;
char COM_Name[10];
Get_COM_Name(COM_Name);
if(Comm_Handle == INVALID_HANDLE_VALUE)
{ // It is closed
COM_Handle = CreateFile(COM_Name,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if(COM_Handle != INVALID_HANDLE_VALUE)
{ // Was closed, is now opened
COMM_Select->Enabled = false;
COMM_Select->Update();
GetCommTimeouts(COM_Handle,&Time_Out_Old);
Time_Out_New.ReadTotalTimeoutConstant = 20;
Time_Out_New.ReadTotalTimeoutMultiplier = 0;
Time_Out_New.WriteTotalTimeoutConstant = 0;
Time_Out_New.WriteTotalTimeoutMultiplier = 0;
SetCommTimeouts(COM_Handle,&Time_Out_New);
Comm_Port_DCB.DCBlength = sizeof(DCB);
GetCommState(COM_Handle,&Comm_Port_DCB);
BuildCommDCB("9600,n,8,1",&Comm_Port_DCB);
SetCommState(COM_Handle,&Comm_Port_DCB);
return(COM_Handle);
}
else
{
return(INVALID_HANDLE_VALUE);
}
}
else
{
return(Comm_Handle);
}
}

void __fastcall TForm1::Close_Com_Port(void)
{
COMM_Select->Enabled = true;
ButtonConnect->Enabled = true;
if(Comm_Handle != INVALID_HANDLE_VALUE)
{ // Is open, close it now
PurgeComm(Comm_Handle,PURGE_RXABORT);
SetCommTimeouts(Comm_Handle,&Time_Out_Old);
CloseHandle(Comm_Handle);
}
Comm_Handle = INVALID_HANDLE_VALUE;
GetStatistic->Enabled = false;
ButtonCodes->Enabled = false;
}

To write/read the port:
WriteFile(Comm_Handle,&BufferToSend,&Did_Write,0);
ReadFile(Comm_Handle,InBuff,sizeof(InBuff)-1,&BytesRead,NULL);


Totte
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top