在Windows CE 6.0中使用opennetcf Ras创建持久RAS连接
我需要在具有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"
这个设置当我使用控制面板并与该配置文件连接时,它连接并且我能够在没有错误的情况下调用所有Web服务。它还显示调制解调器的额外配置文件,显示设备的设置,包括ipaddress,子网掩码甚至默认网关。
问题是,当我使用我创建的库以编程方式创建gprs连接,然后在某个时刻调用webservices时,它会抛出一个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库建立可行的连接
最好的问候
没有找到相关结果
已邀请:
1 个回复
完趣镐