Windows Mobile 6 AT 命令

发布于 2024-07-08 21:00:45 字数 1773 浏览 4 评论 0原文

我试图使用 AT 命令获取 CellID,但我没有从调制解调器得到任何响应,我的代码如下所示,我发送 AT+CCED 命令,但从未得到任何响应。

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;


}

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;


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

九厘米的零° 2024-07-15 21:00:45

首先,尝试使用 L"COM9:" 作为 CreateFile 的第一个参数。

查看此页面:设备文件名

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

Check out this page: Device File Names

帝王念 2024-07-15 21:00:45

我不知道如何使用 AT 命令获取小区 ID,但您可以使用 RIL 接口获取小区 ID。 它可能比使用 AT 命令更简单(除非您尝试远程获取它?)

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

您可以使用 RIL_GetCellTowerInfo 函数获取当前的基站 ID。

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.

木槿暧夏七纪年 2024-07-15 21:00:45

我的问题是,在某些设备上,RIL iterface 方法返回 E_NOTIMPL 并且没有任何效果,所以我认为我可以直接使用 AT 命令与移动调制解调器通信。

有没有人能解决这个问题,我已经和它斗争了一个多星期了。

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.

叫嚣ゝ 2024-07-15 21:00:45

显然我不被允许发表评论..所以:
@Sebastian:我在 2 个型号的 HTC Diamond + HTC Touch Pro + ATT Fuze 上运行 Ril_GetCellTowerInfo。 它适用于所有 4 部手机。 如果您需要更多帮助,我很乐意分享一些工作代码(在 VB.NET 中)。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文