在 Windows CE 6.0 中使用 opennetcf Ras 创建持久 RAS 连接

发布于 10-15 18:03 字数 3363 浏览 10 评论 0原文

我需要在装有 windows ce 6 的 PDA 中创建 GPRS 连接。现在通常我必须使用制造商的 dll 来创建它,但他们说他们使用 ras 来完成此操作。使用它的唯一问题是我在 .net c# 中编程,并且该库是非托管代码库。

幸运的是,我使用了 opennetcf ras 库,它已经为 Windows ras 库提供了必要的 pInvokes,唯一的问题是文档很差。

然后我创建了一个库,可以在 Windows 上调用并设置必要的 GPRS 连接。我正在使用使用以下定义的葡萄牙电信运营商:

Operator Name: Optimus P
Apn:  umts
Password: *******
User: ******

咨询 gsm 模块定义,我有以下调制解调器设置:

Connection Name: GPRS
Device: Hayes Compatible on COM1:
Baund Rate:115200
Data Bits: 8
Parity:1
Stop Bits: 1
Flow Control: Hardware

当然还有额外的设置(或者我如何将其称为 atCall)

+cgdcont=1, "ip", "umts"

当我使用控制面板时此设置并与该配置文件进行连接,它会连接,并且我能够调用所有网络服务而不会出现错误。它还显示调制解调器的额外配置文件,其中显示设备的设置,包括 IP 地址、子网掩码甚至默认网关。

问题是,当我使用我创建的库以编程方式创建 gprs 连接,然后在某个时候调用 Web 服务时,它会抛出一个 Web 异常:无法解析远程名称。我还检查过,没有出现额外的图标,但如果我看到 GPRS 状态,它就会显示为已连接。

创建、销毁和查询是否存在连接的代码如下:

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using OpenNETCF.Net;
using OpenNETCF.Diagnostics;

namespace gsmAdapterNet
{
/// <summary>
/// GPRS Connection class
/// </summary>
public class GPRS
{
    private static string connectionName = "GPRS";


    /// <summary>
    /// Connects the GPRS.
    /// </summary>
    /// <returns></returns>
    public static bool ConnectGPRS()
    {

            //precisamos de obter as connecoes e ligar

            RasEntryCollection connecoesPossiveis = Ras.Entries;
            RasEntry _currentEntry = connecoesPossiveis[connectionName];
            _currentEntry.RasStatus += new RasNotificationHandler(RasStatusHandler);
            RasError resultado = _currentEntry.Dial(false);
            if (resultado == RasError.Success)
                return true;
            else
                return false;


    }

    static void RasStatusHandler(int hConn, RasConnState State, RasError ErrorCode)
    {
        Logger.WriteLine("");
        Logger.WriteLine("RAS STATUS: " + ErrorCode.ToString() + " , State: " + State.ToString());
    }


    /// <summary>
    /// Disconnects the GPRS.
    /// </summary>
    /// <returns></returns>
    public static void DisconnectGPRS()
    {
        RasEntryCollection entradas = Ras.Entries;
        foreach (RasEntry possivelEntrada in entradas)
        {
            if (possivelEntrada.Name == connectionName)
            {
                possivelEntrada.Hangup();
            }
        }


    }

    /// <summary>
    /// Determines whether this instance is connected.
    /// </summary>
    /// <returns>
    ///     <c>true</c> if this instance is connected; otherwise, <c>false</c>.
    /// </returns>
    public static bool isConnected()
    {

        RasConnection[] conecoes = Ras.ActiveConnections;
        foreach (RasConnection conecao in conecoes)
        {
            if (conecao.Name == connectionName)
                return true;
        }
        return false;

    }

    /// <summary>
    /// Dumps the ras entries.
    /// </summary>
    public static void DumpRasEntries()
    {
        foreach (RasEntry entry in Ras.Entries)
        {
            Logger.DumpRasEntry(entry);
        }
    }

}

}

因此,继续问题是我如何与 opennetcf ras 库创建可行的连接

最好的问候

I'm in need to create an GPRS connection in an PDA that has windows ce 6. Now normally i would had to use the manufacturer's dll to create that, but they said that they use ras to accomplish this. The only problem of using that is that i program in .net c#, and the library is an unmanaged code one.

Fortunately i came by the opennetcf ras library that does already the necessary pInvokes for the windows ras library, the only problem being the poor documentation.

I created then an library that would call and set-up the necessary GPRS connection on windows. I'm using an Portuguese telecom operator that uses the following definitions:

Operator Name: Optimus P
Apn:  umts
Password: *******
User: ******

Consulting the gsm module definition, i had the following modem settings:

Connection Name: GPRS
Device: Hayes Compatible on COM1:
Baund Rate:115200
Data Bits: 8
Parity:1
Stop Bits: 1
Flow Control: Hardware

and of course the extra settings (or how i call it the atCall)

+cgdcont=1, "ip", "umts"

This settings when i use the control panel and do an connect with that profile, it connects and i'm able to call all the webservices without an error. It also shows an extra profile for the modem that shows the settings for the device, incluid the ipaddress, subnet mask and even the default gateway.

The problem is that when i use the library that i created to create an gprs connection programatically, and then call the webservices at some point it throws me an web exception : The remote name could not be resolved. I also checked and the extra icon does not appear, but if i see the GPRS status it appears as it is connected.

The code that create, destroys and query if it exists an connection is as follows:

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using OpenNETCF.Net;
using OpenNETCF.Diagnostics;

namespace gsmAdapterNet
{
/// <summary>
/// GPRS Connection class
/// </summary>
public class GPRS
{
    private static string connectionName = "GPRS";


    /// <summary>
    /// Connects the GPRS.
    /// </summary>
    /// <returns></returns>
    public static bool ConnectGPRS()
    {

            //precisamos de obter as connecoes e ligar

            RasEntryCollection connecoesPossiveis = Ras.Entries;
            RasEntry _currentEntry = connecoesPossiveis[connectionName];
            _currentEntry.RasStatus += new RasNotificationHandler(RasStatusHandler);
            RasError resultado = _currentEntry.Dial(false);
            if (resultado == RasError.Success)
                return true;
            else
                return false;


    }

    static void RasStatusHandler(int hConn, RasConnState State, RasError ErrorCode)
    {
        Logger.WriteLine("");
        Logger.WriteLine("RAS STATUS: " + ErrorCode.ToString() + " , State: " + State.ToString());
    }


    /// <summary>
    /// Disconnects the GPRS.
    /// </summary>
    /// <returns></returns>
    public static void DisconnectGPRS()
    {
        RasEntryCollection entradas = Ras.Entries;
        foreach (RasEntry possivelEntrada in entradas)
        {
            if (possivelEntrada.Name == connectionName)
            {
                possivelEntrada.Hangup();
            }
        }


    }

    /// <summary>
    /// Determines whether this instance is connected.
    /// </summary>
    /// <returns>
    ///     <c>true</c> if this instance is connected; otherwise, <c>false</c>.
    /// </returns>
    public static bool isConnected()
    {

        RasConnection[] conecoes = Ras.ActiveConnections;
        foreach (RasConnection conecao in conecoes)
        {
            if (conecao.Name == connectionName)
                return true;
        }
        return false;

    }

    /// <summary>
    /// Dumps the ras entries.
    /// </summary>
    public static void DumpRasEntries()
    {
        foreach (RasEntry entry in Ras.Entries)
        {
            Logger.DumpRasEntry(entry);
        }
    }

}

}

So resuming the question is how i can create an viable connection with the opennetcf ras library

Best Greetings

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

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

发布评论

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

评论(1

浴红衣2024-10-22 18:03:03

您拨入时获得的 GPRS 连接的网络接口似乎未配置正确的 DNS 服务器。或者,您的服务调用所需的域名可能是错误的。

验证一下:

是否只是某个特定的Web服务的域名无法解析?总是一样吗?其他人工作吗?在建立连接后,您可以通过编程方式简单地进行 HTTP GET 类似 http://stackoverflow.com 的内容吗?

It seems as if the network interface for the GPRS connection that you get when dialing in is not configured with the correct DNS servers. Alternatively, the domain names needed for your service calls may be wrong.

To verify this:

Is it only a specific web service whose domain name cannot be resolved? Is it always the same? Do others work? Can you simply HTTP GET something like http://stackoverflow.com programmatically after the connection has been established?

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