2009年3月31日 星期二
Timeout偵錯
HttpWebRequest.Timeout 屬性
Session Timeout 設定及讀取
WebService calling from Pocket PC
12月04日「 微軟線上專家對談」主題:ASP通往ASP .NET的升級之路
c# 关于HttpWebResponse蹦出的异常的一个问题
C# 呼叫 WebService
http://sls.weco.net/calendar-orig/2009/01/4
2009年3月14日 星期六
開啟關閉 windows mobile WIFI
[DllImport("coredll.dll")]
public static extern int DevicePowerNotify(string device, CEDEVICE_POWER_STATE state, int flags);
[DllImport("coredll.dll")]
public static extern int SetDevicePower(string pvDevice, int df, CEDEVICE_POWER_STATE ds);
没有专门针对WIFI设备的API, 但是可以通过上面两个方法,控制WIFI状态
2. ref: http://topic.csdn.net/u/20080728/20/a5efe62a-629c-4811-add5-bc6c53fcdd5b.html
用无线管理器ChangeRadioState函数可以指定打开或关闭某一设备,包括WIFI
首先使用函数HRESULT GetWirelessDevices()获得一个设备链表,在设备链表中根据设备类型,找到wifi设备,然后调用ChangeRadioState()打开或者关闭指定的设备。
有关上述函数的详细使用,可以查windows mobile 6 documentation
GetWirelessDevices(),ChangeRadioState()都是MS公布给OEM的标准接口,WM6都是支持的。
openNETCF有,且有例子,你找找去。
看看人家做的
http://www.cnblogs.com/MS-Frank/archive/2008/11/14/1333664.html
軟體 wifiswitch
http://www.winbile.net/bbs/forums/threads/1014040.aspx
http://www.pudn.com/downloads90/sourcecode/windows/comm/detail342414.html
Native Wifi api
该api的可以实现windows的无线客户端的网络参数配置(WlanSetProfile),连接指定的ap,断开连接和获得其他关于无线网络的信息(ssid,rssi等)。
並且有一個斷開WIFI的範例。
另一個繼續深入的搜尋資源
http://search.pudn.com/search.asp?keyword=%20wifi
coredll 全部的函式名稱
http://topic.csdn.net/t/20050826/13/4233161.html
2009年3月10日 星期二
webservice 傳送問題
用戶端找到的回應內容型別為'text/html; charset=iso-8859-1',但需要的是'text/xml'。
解:
如果您檢視錯誤訊息的內容,會發覺這個 HTML 網頁是您瀏覽 .ASMX 檔案時所見到的。這時會產生一個疑問:當我將 XML (SOAP Envelope 的格式) 公佈到 Web 服務時,為什麼會傳回 HTML?結果就是您沒有使用 SOAP Envelope 傳送 HTTP POST 要求,卻只是傳送沒有本文的 HTTP GET 要求,而 Web 服務會適當地假設您是瀏覽器,並傳回它一般的 HTML 回應。
refer
http://www.microsoft.com/taiwan/msdn/library/2002/Sep-2002/service08062002.htm
2009年3月8日 星期日
開啟/關閉 WIFI 裝置
http://topic.csdn.net/u/20080728/20/a5efe62a-629c-4811-add5-bc6c53fcdd5b.html
解法
Windows Mobile 中开关 WIFI 的“通用”代码
SystemState.WiFiStatePowerOn Property 讀取WIFI狀態的屬性,但無法設置開關
英文的 ><
Deactivate /Activate all Services like (Internet,WIFI,Bluetooth,WLAN..)
Enabling Radio in the Windows Mobile 5.0
WiFi Power On Event
開啟D0 關閉D4
We can implement this functionality with ease. Hope this can give your some idea.
See the code below:
// D0 indicates open; D4 indicates close;
CEDEVICE_POWER_STATE state = D0;
HRESULT hr = SetDevicePower(TEXT(""),POWER_NAME,state);
Note: We use SetDevicePower function here. It sets the device power state for a device.
- 1st parameter: specify the device.
- 2nd parameter: we use POWER_NAME here to indicate that the first parameter is just a device name.
- 3rd parameter: sets the power state.
In order to get information in details, you can find it in MSDN. Thanks!
Regards,
Zero Dai - MSFT
之後
Battery Status
GPS Application
Mobile GPS
2009年3月5日 星期四
在不同執行緒下存取UI控制項(textbox combobox)
解法:
1.Form.CheckForIllegalCrossThreadCalls = False
2.建立委派
3.使用BackgroundWorker
首先在windows.form 的 onload事件建置一條執行緒
compareandprintout = new Thread(new ThreadStart(MRTcompareThread));
compareandprintout.Start();
這條thread 會執行compare()方法,存取UI控制項的程式就寫在裡面(存取textbox,combobox)
public void MRTcompareThread()
{
compare(); //裡面有無限迴圈
}
委派的建立!!
1.建立方法
publik int XXmethod(int a, int b);
2.宣告委派;委派參數,需要與被呼叫的方法一樣,包含回傳型別 (相同 signature)
private delegate void XXDelegate();
private delegate int XXDelegate(int a, int b);
3.引用委派(實體化),後指定方法
XXDelegate d = new XXDelegate(XXMethod); //參考的方法只要名稱就可以了
invoke();
真的開始囉~~
於class form1裡宣告委派
delegate void SetTextCallback(Control ctl,String str); 設置textbox.text
delegate string GetTextCallback(Control ctl); 讀取textbox.text
delegate string GetCBTextCallback(ComboBox ctl, int i); 讀取ComboBox
delegate string GetCBTextCallback(Listcontrol ctl, int i); 讀取ComboBox
另外要寫委派方法
public string gettext(Control ctl)
{
if (this.InvokeRequired) //InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true.
{
GetTextCallback d = new GetTextCallback(gettext);
// this.Invoke(d);
string x;
x =(string) this.Invoke(d, new Object[] { ctl });
return x;
}
else
{
return ctl.Text;
}
}
public void settext(Control ctl,String str)
{
if (this.InvokeRequired)
{
SetTextCallback s = new SetTextCallback(settext);
this.Invoke(s, ctl, str );
}
else
{
ctl.Text = str;
}
}
public string getCBtext(ComboBox ctl, int i)
{
if (this.InvokeRequired)
{
string try1 = ctl.GetItemText(i); //i = 1 2 3 4 遞增,奇怪~難道我誤會MSDN? 給出來的是combobox的item索引
string try2 = (string)ctl.Items[i];//
GetCBTextCallback Gcb = new GetCBTextCallback(getCBtext); //建立
string x;
x = (string)this.Invoke(Gcb, ctl, i);
return x;
}
else
{
return (string) ctl.Items[i];
// return ctl.GetItemText(i);
}
}
在非產生UI控制項的副執行緒主程式 compare裡面有
while(true)
{
for (i = 1; i < style="color: rgb(51, 204, 255);"> getCBtext(comboBox1,i) && startstation == true)
//if (nowBox.Text == comboBox1.Items[i].ToString() )
{
//onBox.Text = comboBox1.Items[i].ToString(); //debug會出錯(不同控制項執行緒叫用 ... 我忘了)
string y = getCBtext(comboBox1,i) ;
settext(onBox, y); //叫用方法,自動判斷叫用invoke
}
}
for (i = 1; i < style="color: rgb(255, 0, 0);">// if (onBox.Text == comboBox1.Items[i].ToString())
{
if (goal > getonposition)
{
//nexterrorstop = comboBox1.Items[i - 1].ToString();
nexterrorstop = getCBtext(comboBox1,i-1);
}
else
{
nexterrorstop = "error";
}
}
}
}
VB版
一樣 ,先建立一個拿來更新 UI 的方法( UpdateUI),再建立一個有相同 signature 的委派( UpdateUICallBack)
Private Delegate Sub UpdateUICallBack(ByVal newText As String, ByVal c As Control)
Private Sub UpdateUI(ByVal newText As String, ByVal c As Control)
If Me.InvokeRequired() Then
Dim cb As New UpdateUICallBack(AddressOf UpdateUI)
Me.Invoke(cb, newText, c)
Else
c.Text = newText
End If
End Sub
ref:
舊文重發:Windows 表單與多執行緒
HOW TO:進行對 Windows Form 控制項的安全執行緒呼叫
VB/ VBA/ C#/ Java/ C++ 語言學習筆記
2009年3月4日 星期三
2009年2月23日 星期一
Device Emulator 透過 ActiveSync方式上網
工具->裝置模擬 器管理員
選擇 windows mobile5.0示範
STEP1. 選擇 windows mobile5.0 Pocket PC Emulator右鑑->connect
出現綠色開始鍵,並且跳出模擬器畫面
STEP2. 開啟 Microsoft ActiveSync->檔案->連線設定
允許連線到下列其中一個裝置->選擇DMA(direct memory access)
STEP3. 回到裝置模擬器管理器
右鍵->連結底座(Cradle)
End!!!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我..真的是太淺了..現在才知道
MSDN原來還有影片教學~~好物啊~
MSDN教學影片
webservice使用
逐步解說:使用 Visual Basic 或 Visual C# 存取 XML Web Service
並且新增一行程式碼
ws.Url = "http://XXX.XXX.XXX.XXX/webservice所處位置/方法代理名稱";
如何開啟模擬器PDA 網路連線呢??
2009年2月18日 星期三
scoket傳送封包流過長
發現搭車到到一半時就發生過長時間才收到server的回應
最後一筆有效紀錄(經web server過濾後所顯示)的地圖標點
都來沒走一半呢...回到研究室看看debug訊息~
怪哉~ 再看console
不知道什麼原因造成多筆記錄在同一筆傳送socket封包支援到1024byte,一旦超過,傳送的data stream 就會被截斷在下一個封包繼續傳送
如果網路狀況不擁擠(小於1024byte),那麼頂多只會loss掉幾筆資料..
但如果遇到split(,),剛好data資料開頭剛好是"," 程式裡頭判斷所欲存之值為空..就會發生錯誤(格式不對)看看資料庫就知道...多糟了><

看樣子,要避開這種情況目前想到只有
- 修改每次傳送封包格式的大小,能整除1024(目前一筆資料大小為76byte以下),這樣就能確保所存資料格式正確
但server程式部分要限制每個欄位的資料大小,之後如果PDA要新增傳送資料,要再修改 重算能整除值...而對定位而言,更會遺失至多12筆資料(1024/76=13.47) - server程式先行判斷所收到資料筆數(依封包大小),再複雜變數儲存判斷,但好像遇到封包過大,還是有stream被截的問題...
- 搜尋stream buffer相關.. 迫使程式接收一定是一筆一筆進來分析.
2009年2月2日 星期一
PDA底層連線
http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/f524cc42-a132-4c1b-8fcb-6c63d977aab2/
Connection Manager API Functions
http://msdn.microsoft.com/en-us/aa458120.aspx
幾個使用情境說明
http://msdn.microsoft.com/en-us/aa459117.aspx
這裡有步驟~
http://msdn.microsoft.com/en-us/aa459118.aspx
2009年1月22日 星期四
2008年10月30日 星期四
SystemState.OwnerPhoneNumber 取得手機電話號碼
SystemState.OwnerPhoneNumber 來得到~
但 為什麼我們抓不到呢~?
因為 這裡抓到的電話號碼是 事先已被設定在手機裡頭的 (非sim卡)
你可以看看 (開始->設定->個人資訊)
那如何實做抓取SIM卡的電話號碼呢?
在路徑
C:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Pocket PC SDK\Samples\CPP\Win32\GetPhoneNumber\
有sample可以學習~
但要注意不是所有GSM的sim卡都支援號碼內建
2008年9月29日 星期一
於vs2005開啟一PDA專案檔
點擊.sln檔案時,跳出一個錯誤視窗
從使用者資料存放區擷取資訊時發生錯誤。找不到平台。
確定後又跳一個 : 無法開啟專案,因為它參考了您的資料存放區中沒有的裝置平台。
這個原因是因為開發這個PDA程式時是在某個平台上的SDK開發的
要怎麼看呢~ 用筆記本開啟.csproj檔, 找到下面幾行敘述
PocketPC 5.01 是 WIndows Mobile 5.0的平台,要安裝相關的SDK,可以到下載中心下載.
http://www.microsoft.com/downloads/details.aspx?FamilyID=83a52af2-f524-4ec5-9155-717cbe5d25ed&DisplayLang=en





