C# 如何断开 cdma 1x 的数据连接?

changlin365 2008-12-24 01:35:11
程序访问webservice时mobile6 自动创建了cdma1x 连接。 因为 cdma 1X 无线连接后 电话和短信 无法接入了。所以要用C#代码,断开cdma 1X 已经找到这个断开 gprs 的代码。如下,不知道程序如何调用一下,请高手给出调用代码C#,谢谢高分相送。

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Threading;

namespace CoolMeeting2
{
class GPRSConnection
{
const int S_OK = 0;
const uint CONNMGR_PARAM_GUIDDESTNET = 0x1;
const uint CONNMGR_FLAG_PROXY_HTTP = 0x1;
const uint CONNMGR_PRIORITY_USERINTERACTIVE = 0x08000;
const uint INFINITE = 0xffffffff;
const uint CONNMGR_STATUS_CONNECTED = 0x10;
static Hashtable ht = new Hashtable();

static GPRSConnection()
{
ManualResetEvent mre = new ManualResetEvent(false);
mre.Handle = ConnMgrApiReadyEvent();
mre.WaitOne();
CloseHandle(mre.Handle);
}

~GPRSConnection()
{
ReleaseAll();
}

public static bool Setup(Uri url)
{
return Setup(url.ToString());
}

public static bool Setup(string urlStr)
{
ConnectionInfo ci = new ConnectionInfo();
IntPtr phConnection = IntPtr.Zero;
uint status = 0;

if (ht[urlStr] != null)
return true;

if (ConnMgrMapURL(urlStr, ref ci.guidDestNet, IntPtr.Zero) != S_OK)
return false;

ci.cbSize = (uint)Marshal.SizeOf(ci);
ci.dwParams = CONNMGR_PARAM_GUIDDESTNET;
ci.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
ci.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
ci.bExclusive = 0;
ci.bDisabled = 0;
ci.hWnd = IntPtr.Zero;
ci.uMsg = 0;
ci.lParam = 0;

if (ConnMgrEstablishConnectionSync(ref ci, ref phConnection, INFINITE, ref status) != S_OK &&
status != CONNMGR_STATUS_CONNECTED)
return false;

ht[urlStr] = phConnection;
return true;
}

public static bool Release(Uri url)
{
return Release(url.ToString());
}

public static bool Release(string urlStr)
{
return Release(urlStr, true);
}

private static bool Release(string urlStr, bool removeNode)
{
bool res = true;
IntPtr ph = IntPtr.Zero;
if (ht[urlStr] == null)
return true;
ph = (IntPtr)ht[urlStr];
if (ConnMgrReleaseConnection(ph, 1) != S_OK)
res = false;
CloseHandle(ph);
if (removeNode)
ht.Remove(urlStr);
return res;
}

public static void ReleaseAll()
{
foreach (DictionaryEntry de in ht)
{
Release((string)de.Key, false);
}
ht.Clear();
}

[StructLayout(LayoutKind.Sequential)]
public struct ConnectionInfo
{
public uint cbSize;
public uint dwParams;
public uint dwFlags;
public uint dwPriority;
public int bExclusive;
public int bDisabled;
public Guid guidDestNet;
public IntPtr hWnd;
public uint uMsg;
public uint lParam;
public uint ulMaxCost;
public uint ulMinRcvBw;
public uint ulMaxConnLatency;
}

[System.Runtime.InteropServices.DllImport("cellcore.dll")]
private static extern int ConnMgrMapURL(string pwszURL, ref Guid pguid, IntPtr pdwIndex);

[DllImport("cellcore.dll")]
private static extern int ConnMgrEstablishConnectionSync(ref ConnectionInfo ci, ref IntPtr phConnection, uint dwTimeout, ref uint pdwStatus);

[DllImport("cellcore.dll")]
private static extern IntPtr ConnMgrApiReadyEvent();

[DllImport("cellcore.dll")]
private static extern int ConnMgrReleaseConnection(IntPtr hConnection, int bCache);

[DllImport("coredll.dll")]
private static extern int CloseHandle(IntPtr hObject);

[DllImport("cellcore.dll")]
private static extern int ConnMgrConnectionStatus(IntPtr phConnection, ref uint pdwStatus);


}
}
...全文
293 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lh154691780 2008-12-31
  • 打赏
  • 举报
回复
bool bIsConn = GPRSConnection.Setup("http://XXXXXXX");
if (bIsConn)
{
//已连接
}
else
{
//未连接
}
儿大不由爷 2008-12-27
  • 打赏
  • 举报
回复
bExclusive = TRUE;
建立连接的句柄要保存;
用ConnMgrReleaseConnection断开连接
changlin365 2008-12-26
  • 打赏
  • 举报
回复
不知道大家如何断开 gprs 的?
overbill 2008-12-26
  • 打赏
  • 举报
回复
不懂,帮顶
changlin365 2008-12-26
  • 打赏
  • 举报
回复
pcmouse 谢谢 是啊 gprs是可以的 一边传输, 一边还能接收短信,接打电话 可是我是中国电信 的cdma 1X 就不行了 现在找了个小程序 一运行就挂断 gprs 或 cdma 1X 在程序里调用一下 以后 cdma 2000上了就不怕了 呵呵
pcmouse 2008-12-26
  • 打赏
  • 举报
回复
我用C++的写过, 不过没有你说的那样啊, GPRS可以一边传输, 一边还能接收短信,接打电话啊
内容概要:本文针对风电功率随机波动对电网频率稳定性的不利影响,提出一种基于灰狼优化算法(GWO)与改进的自适应噪声完备集合经验模态分解(ICEEMDAN)相结合的混合储能功率平抑策略。通过GWO优化ICEEMDAN的关键参数(如噪声幅值、分解层数),以样本熵为适应度函数提升风电功率信号分解精度,有效抑制模态混叠问题;进而构建四阶段协同调控框架:参数优化—自适应分解—互信息熵初级功率分层—模糊控制动态修正中频功率分配,实现低频、中频、高频波动功率的合理分配。该策略结合储能系统中蓄电池与超级电容的特性,利用模糊控制器根据两者实时荷电状态(SOC)动态调整中频功率分配比例,避免过充过放,延长设备寿命。基于实测风电数据的仿真结果表明,该方法显著降低了并网功率波动率,提升了储能运行安全性与系统整体平抑效果。; 适合人群:具备一定电力系统、新能源并网、储能控制背景,熟悉Matlab/Simulink仿真工具,从事相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①解决风电功率波动导致的电网频率不稳定问题;②优化混合储能系统(蓄电池+超级电容)的功率分配策略;③提升风电并网电能质量与储能系统运行寿命;④为基于智能算法的新能源功率平滑控制提供可复现的技术方案。; 阅读建议:建议结合Matlab代码与Simulink仿真模型进行实践,重点关注GWO参数寻优流程、ICEEMDAN分解效果对比、互信息熵判据应用及模糊规则设计等核心模块,深入理解信号分解与储能状态协同控制的闭环机制。

7,655

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧