Micro Framework 3.0模擬器改造

Micro Framework 3.0SDK去年十月份就已經發布了,本打算在該SDK發佈之後就把我以前開發的,可支持GPIOI2CSPI測試的模擬器同步升級爲3.0版,以便早點支持VS2008Micro Framework v2.x僅支持VS2005Micro Framework v3.0僅支持VS2008)。不過前段時間太忙了,現在趁着年假,花了一兩天的工夫,終於達成了心願。

新的模擬器相對於以前的模擬器有了兩部分改變,下面詳細說一下:

一、由於Micro Framework v3.0 SDK已經含有觸摸屏組件,所以新模擬器中去掉了以前的SPI通道的鼠標模塊,添加了最新的觸摸屏支持。

this.lcdDisplay.TouchPort = (TouchGpioPort)_emulator.GpioPorts[TouchGpioPort.DefaultTouchPin];

protected override void OnMouseDown(MouseEventArgs e)

{

base.OnMouseDown(e);

flags = TouchSampleValidFlag | TouchSampleDownFlag;

_touchPort.WriteTouchData(flags, e.X, e.Y);

}

protected override void OnMouseUp(MouseEventArgs e)

{

base.OnMouseUp(e);

flags = TouchSampleValidFlag | TouchSamplePreviousDownFlag;

_touchPort.WriteTouchData(flags, e.X, e.Y);

}

protected override void OnMouseMove(MouseEventArgs e)

{

base.OnMouseMove(e);

if ((flags & (TouchSampleValidFlag | TouchSampleDownFlag)) == (TouchSampleValidFlag | TouchSampleDownFlag))

{

flags = TouchSampleValidFlag | TouchSamplePreviousDownFlag | TouchSampleDownFlag;

if ((e.X >= 0) && (e.Y >= 0))

{

_touchPort.WriteTouchData(flags, e.X, e.Y);

}

}

}

二、3.0 SDK已經支持文件系統,所以新模擬器添加了這部分功能支持,不過新功能有些討巧,不像虛擬機能支持真正的磁盤鏡像文件,而是引用了windows自身文件操作API,把windows的文件操作封裝到模擬器中。

List<EmulatorRemovableBlockStorageDevice> bsdList = new List<EmulatorRemovableBlockStorageDevice>();

removableBSDs = new Dictionary<string, EmulatorRemovableBlockStorageDevice>();

foreach (BlockStorageDevice bsd in _emulator.BlockStorageDevices)

{

if (bsd is EmulatorRemovableBlockStorageDevice)

{

bsdList.Add((EmulatorRemovableBlockStorageDevice)bsd);

}

}

if (bsdList.Count > 0)

{

insertEjectMenuItem.Visible = true;

foreach (EmulatorRemovableBlockStorageDevice removableBSD in bsdList)

{

ToolStripItem item = new ToolStripMenuItem(GetItemText(removableBSD), null, InsertEjectOnClick);

item.Name = removableBSD.Namespace;

insertEjectMenuItem.DropDownItems.Add(item);

removableBSDs.Add(removableBSD.Namespace, removableBSD);

}

}

mf3.0

模擬器V3.0

mffile

新模擬器改進了***制,下載後解壓到任一目錄,直接運行YFMFEmulator.exe文件即可完成註冊。

至於模擬器如何使用,請參見我以前寫的文章:

1[MSDN Webcast]Windows Embedded從入門到精通系列課程(18):用模擬器零成本體驗MF開發

2.Net Micro Framework研究—模擬器改造

3用模擬器零成本體驗MF開發

關於Micro Framework 3.0 SDK的幾點問題

1、下載鏈接:http://www.microsoft.com/downloads/details.aspx?FamilyId=9356ED6F-F1F0-43EF-B21A-4644DD089B4A&displaylang=en

2、幾個bug

其實這幾個bug在安裝SDK3.0後的Micro Framework SDK Release Notes.txt中已經有了說明。

主要有如下兩個問題:

(1) 非英文版VS2008安裝SDK3.0後,在新建項目中無micro Framework選項

解決辦法:

If you are running a non-English version of Visual Studio, you will need to

move the Micro Framework project and item template files to a new location.

Assuming the default installation directory, you would need to copy all files

from

\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\

CSharp\Micro Framework\1033 to

\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\

CSharp\Micro Framework

and all MicroFramework* files from

\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\

1033 to

\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\

注意:進行以上操作以後,一定要運行如下指令:X:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe /setup

(2) V2.x的應用程序升級爲V3.0時失敗

解決辦法:

If you have existing projects written for previous versions of the Micro

Framework, follow these steps to update them to version 3.

1) Open the .csproj file for each of your projects and update the value of the

TargetFrameworkVersion from

<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> to

<TargetFrameworkVersion>v3.0</TargetFrameworkVersion>

2) Open the project (or solution) in Visual Studio 2008 and complete the

Conversion Wizard.

3) Review the "New behavior" section below and update code as needed.