Unable to send AT commands to the COM3 port. plz help.
-
OK is nothing but response from the modem. what is not working then for you???:confused:
Regards, Sandip.
-
my code is as follows ...
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
TCHAR *pcCommPort = TEXT("COM3");
char DataBuffer[] = "AT+FCLASS=8";
DWORD dwBytesToWrite = (DWORD)strlen(DataBuffer);
char Data2[]="ATDW2289759";DWORD dwBytesWritten = 0; DWORD dwBytesRead = 0; char ReadBuffer\[BUFFER\_SIZE\] = {0};
hCom = CreateFile( pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // default security attributes
OPEN_EXISTING, // 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);
}// Build on the current configuration, and skip setting the size
// of the input and output buffers with SetupComm.// SecureZeroMemory(&dcb, sizeof(DCB));
dcb.DCBlength = sizeof(DCB);
fSuccess = GetCommState(hCom, &dcb);if (!fSuccess)
{
// Handle the error.
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
}dcb.BaudRate = CBR\_2400; // 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);
}_tprintf (TEXT("Serial port %s successfully reconfigured.\n"),pcCommPort);
//WriteFile(hCom,"AT+FCLASS=8",sizeof("AT+FCLASS=8"),&len,0);
if( FALSE == WriteFile(hCom, // open file handle
DataBuffer + dwBytesWritten, // start of data to write
dwBytesToWrite - dwBytesWritten, // number of bytes to write
&dwBytesWritten, // number of bytes that were written
NULL)) // no overlapped structure
printf("Could not write %s to file (error %d)\n",DataBuffer, GetLastError());
else
_tprintf(TEXT("Wrote %d bytes successfully.\n"), dwBytesWritten);
if( FALSE == ReadFile(hCom, ReadBuffer, BUFFER_SIZE-2, &dwBytesRead,See documentation for SetCommTimeouts. After that verify your AT command string. As debugging tool, I would turn on modem speaker if you have one. Also verify that COM3 is valid and unused by other application. " When reading from a communications device, the behavior of ReadFile is governed by the current communication time-outs as set and retrieved using the SetCommTimeouts and GetCommTimeouts functions. Unpredictable results can occur if you fail to set the time-out values. For more information about communication time-outs, see COMMTIMEOUTS. "
-
See documentation for SetCommTimeouts. After that verify your AT command string. As debugging tool, I would turn on modem speaker if you have one. Also verify that COM3 is valid and unused by other application. " When reading from a communications device, the behavior of ReadFile is governed by the current communication time-outs as set and retrieved using the SetCommTimeouts and GetCommTimeouts functions. Unpredictable results can occur if you fail to set the time-out values. For more information about communication time-outs, see COMMTIMEOUTS. "
-
Does this command work in HyperTerminal BTW:this link explains the AT commands might help you.. Modem commands[^]
Regards, Sandip.
-
SandipG :) wrote:
Does this command work in HyperTerminal
yes ... the number is getting dialed thro' HyperTerminal ... it is working perfectly there ...
Apurv
-
SandipG :) wrote:
Does this command work in HyperTerminal
yes ... the number is getting dialed thro' HyperTerminal ... it is working perfectly there ...
Apurv
-
in the HyperTerminal, when the command ATDW2289759 is given the response is VCON, but in my code the response is OK
Apurv
-
there is a while loop as follows :
while(1)
{
if(kbhit())
{
key=getch();
if(key=='x')
{
CloseHandle(hCom);
exit(0);
}
switch(key)
{
case '1':
// code to issue command ATDW2289759\r\n
}
}
}Apurv