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