views:

2946

answers:

4

I'm trying to get CellID using AT commands, but I dont get any response from the modem, mine code looks like below, I send AT+CCED command, but never get any response.

HANDLE hCom;
char * xpos;
char rsltstr[5];
DWORD returnValue;
DWORD LAC;
DWORD CellId;
int bufpos;
DCB dcb;
COMMTIMEOUTS to;
DWORD nWritten;
DWORD event;
DWORD nRead;
char outbuf[20], buf[256];

hCom = CreateFile(L"\\\.\\COM9:",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if (hCom==NULL || hCom==INVALID_HANDLE_VALUE)
{
 TCHAR szBuf[80];
 DWORD dw = GetLastError();

 // get the most uptodate cells
 _stprintf(szBuf, TEXT("CreateFile failed with error %d."), dw);

 MessageBox(0, szBuf, TEXT("Error"), MB_OK);

 hCom= NULL;
 return -1;
}

if (!GetCommState(hCom, &dcb))
{
 return -2;
}

dcb.BaudRate= CBR_115200;
dcb.ByteSize= 8;
dcb.fParity= false;
dcb.StopBits= ONESTOPBIT;

if (!SetCommState(hCom, &dcb))
{
 return -3;
}

if (!EscapeCommFunction(hCom, SETDTR))
{
 return -4;
}

if (!GetCommTimeouts(hCom, &to))
{
 return -6;
}
to.ReadIntervalTimeout= 0;
to.ReadTotalTimeoutConstant= 200;
to.ReadTotalTimeoutMultiplier= 0;
to.WriteTotalTimeoutConstant= 20000;
to.WriteTotalTimeoutMultiplier= 0;
if (!SetCommTimeouts(hCom, &to))
{
 return -7;
}

if (!SetCommMask(hCom, EV_RXCHAR))
{
 return -8;
} 

bufpos = 0;

strcpy(outbuf,"AT+CCED=0,5\r"); 

if (!WriteFile(hCom, outbuf, strlen(outbuf), &nWritten, NULL))
{
 return -10;
}

if (nWritten != strlen(outbuf))
{
 return -11;
}

if (!WaitCommEvent(hCom, &event, NULL))
{
 return -12;
}

while(1)
{
 if (!ReadFile(hCom, buf+bufpos, 256 - bufpos, &nRead, NULL))
 {
  return -13;
 }

 if (nRead == 0) // <---- it alweys break here
  break;


 bufpos += nRead;


 if (bufpos >= 256)
  break;


}
+1  A: 

I don't know anything about using the AT commands to get the cell id but you can use the RIL interface to get the cell id. It may be simpler than using the AT commands (unless you are trying to get it remotely?)

http://msdn.microsoft.com/en-us/library/ms890075.aspx

You use the RIL_GetCellTowerInfo function to get the current cell tower id.

Shane Powell
+1  A: 

my problem is that on some devicec RIL iterface methods returns E_NOTIMPL and nothing works, so I tought that I could directly tolk with mobile modem with AT commands.

Does anyone have solution to such a problem, I'm fighting with it for over a week now.

michael
I have the exact same challenge. My HTC Diamond does not respond to RIL_GetCellTowerInfo(..), and so I have been searching all week to try and find a solution to getting the CellID and LAC data.I have been tempted to now try the AT command method.Have you had any luck in obtaining this information successfully?
Sebastian Dwornik
no, I still get no answer using above code
michael
+2  A: 

First of all, try L"COM9:" for the first parameter of CreateFile.

Check out this page: Device File Names

atzz
I did that, I successfully opened COM9 I can write to it but never get any response
michael
+1  A: 

Apparently I am not allowed to comment.. so: @Sebastian: I run Ril_GetCellTowerInfo on 2 models of HTC Diamond + an HTC Touch Pro + an ATT Fuze. It works on all 4 phones. I'd be happy to share some working code (in VB.NET) if you need more help.

Boogaloo