期末测验.docx
《期末测验.docx》由会员分享,可在线阅读,更多相关《期末测验.docx(12页珍藏版)》请在冰豆网上搜索。
期末测验
浙江万里学院实验报告
课程名称:
WinCE和.NetMircoFramework开发技术
实验名称:
期末测验
专业班级:
电子102班姓名:
林庆喜学号:
2010014057
一、实验目的:
(1)检验本学期该课程的的掌握情况
(2)了解.NETMicroFramework的框架,熟练使用VisualStudio2008进行应用程序的编写,并掌握在MF模拟器和Gemini开发板上进行调试的方法。
二、实验内容:
(1)
制作中文字体资源,添加到窗口应用工程当中,使用WPF设计界面,要求如下图所示:
其中,时区和时间要求设置为本地的时区和当前时间,并以1秒钟为单位进行刷新,窗口背景要求有渐变效果,图片下方的矩形尺寸为100*50像素,内部为圆和椭圆,在模拟器中给出设计结果。
(2)
新建控制台应用,要求能够在PC机上通过串口调试助手进行MF开发板5个LED灯的控制,并要求在开发板的屏幕上给出文字提示,如:
“LED1亮”、“LED1灭”,最后下载到开发板上进行调试。
三、实验结果:
1.实验关键代码
(1)界面设计部分
usingSystem;
usingMicrosoft.SPOT;
usingMicrosoft.SPOT.Input;
usingMicrosoft.SPOT.Presentation;
usingMicrosoft.SPOT.Presentation.Controls;
usingMicrosoft.SPOT.Presentation.Media;
usingSystem.Threading;
usingCSIP.SPOT.HardWare.Gemini;
usingMicrosoft.SPOT.Hardware;
usingSystem.IO.Ports;
namespaceqimokaoshi
{
publicclassProgram:
Microsoft.SPOT.Application
{
constbyteHead=0XA5;
constbyteOpen=0XFA;
constbyteClose=0XF5;
staticbyte[]S_Buffer=newbyte[64];
staticbyte[]Rx_Buffer=newbyte[10];
staticSerialPortserialport=newSerialPort(Serial.COM1,(int)BaudRate.Baudrate115200,Parity.None,8,StopBits.One);
DispatcherTimertime;
Texttext;
Bitmapbmp=newBitmap(400,400);
publicstaticvoidMain()
{
ProgrammyApplication=newProgram();
WindowmainWindow=myApplication.CreateWindow();
GPIOButtonInputProviderinputProvider=newGPIOButtonInputProvider(null);
myApplication.Run(mainWindow);
}
privateWindowmainWindow;
publicWindowCreateWindow()
{
mainWindow=newWindow();
mainWindow.Height=SystemMetrics.ScreenHeight;
mainWindow.Width=SystemMetrics.ScreenWidth;
text=newText();
DateTimenewlocaltime=newDateTime(2013,6,8,14,32,43);
Utility.SetLocalTime(newlocaltime);
text.Font=Resources.GetFont(Resources.FontResources.songti);
text.TextContent=Resources.GetString(Resources.StringResources.String1);
text.HorizontalAlignment=Microsoft.SPOT.Presentation.HorizontalAlignment.Right;
text.VerticalAlignment=Microsoft.SPOT.Presentation.VerticalAlignment.Bottom;
ImageBrushib=newImageBrush(Resources.GetBitmap(Resources.BitmapResources._123));
ib.Stretch=Stretch.None;
bmp.DrawRectangle(Colors.Red,1,0,0,320,240,0,0,Colors.Blue,0,0,Colors.White,100,100,Bitmap.OpacityOpaque);
bmp.DrawRectangle(Color.Black,1,110,161,100,50,0,0,Color.White,0,0,Color.White,0,0,Bitmap.OpacityOpaque);
bmp.DrawEllipse(Colors.Black,160,186,25,25);//中点为150,120,半径为100的圆
bmp.DrawEllipse(Colors.Black,160,186,50,25);
Fontb=Resources.GetFont(Resources.FontResources.songti);
bmp.DrawText("林庆喜",b,Colors.Black,50,10);
bmp.DrawText("2010014057",b,Colors.Black,140,10);
bmp.DrawText("电子102",b,Colors.Black,240,10);
bmp.DrawText("MF期末考核",b,Colors.Black,120,20);
bmp.DrawText("界面设计部分",b,Colors.Black,120,30);
bmp.StretchImage(80,40,Resources.GetBitmap(Resources.BitmapResources._123),160,120,Bitmap.OpacityOpaque);
bmp.Flush();
ib=newImageBrush(bmp);
ib.Stretch=Stretch.None;
mainWindow.Background=ib;
mainWindow.Child=text;
time=newDispatcherTimer();
time.Interval=newTimeSpan(0,0,1);
time.Tick+=newEventHandler(time_tick);
time.Start();
mainWindow.AddHandler(Buttons.ButtonUpEvent,newButtonEventHandler(OnButtonUp),false);
mainWindow.Visibility=Visibility.Visible;
Buttons.Focus(mainWindow);
returnmainWindow;
}
privatevoidOnButtonUp(objectsender,ButtonEventArgse)
{
Debug.Print(e.Button.ToString());
}
voidtime_tick(objectsender,EventArgse)
{
text.TextContent="当前系统时间:
"+DateTime.Now.ToString();
}
}
}
(2)LED控制
2.usingSystem;
3.usingCSIP;
4.usingMicrosoft.SPOT;
5.usingMicrosoft.SPOT.Input;
6.usingMicrosoft.SPOT.Presentation;
7.usingMicrosoft.SPOT.Presentation.Controls;
8.usingCSIP.SPOT.HardWare.Gemini;
9.usingMicrosoft.SPOT.Hardware;
10.usingSystem.IO;
11.usingSystem.IO.Ports;
12.namespaceMFConsoleApplication2
13.
14.{
15.publicclassProgram
16.{
17.//intflag;
18.//DispatcherTimertimer=newDispatcherTimer();
19.////staticSerialPortserialport=newSerialPort(serialport,115200,System.IO.Ports.SerialPort.Equals,8,0);
20.//staticSerialPortserialport=newSerialPort(Serial.COM1,(int)BaudRate.Baudrate115200,Parity.None,8,StopBits.One);
21.//staticbyte[]S_Buffer=newbyte[10];
22.//staticintcount;
23.constbyteHead=0XA5;
24.constbyteOpen=0XFA;
25.constbyteClose=0XF5;
26.staticintcount;
27.//Texttext1=newText("LED1亮");
28.
29.//Gemini_II.Led
30.
31.
32.DispatcherTimertimer;
33.staticbyte[]S_Buffer=newbyte[64];
34.staticbyte[]Rx_Buffer=newbyte[10];
35.staticstringPrintInfo="";
36.staticstringErrorInfo="ContentError";
37.staticSerialPortserialport=newSerialPort(Serial.COM1,(int)BaudRate.Baudrate115200,Parity.None,8,StopBits.One);
38.publicstaticvoidMain()
39.{
40.serialport.Open();
41.//serialport.ToString(HELLOWORD);
42.while(true)
43.{
44.count=serialport.Read(Rx_Buffer,0,serialport.BytesToRead);
45.if(count>0)
46.{
47.serialport.Write(Rx_Buffer,0,count);
48.serialport.Flush();
49.if(Rx_Buffer[3]==((Rx_Buffer[0]+Rx_Buffer[1]+Rx_Buffer[2])&0xff));
50.if(Rx_Buffer[0]==Head)
51.if(Rx_Buffer[1]==Open)
52.{
53.Gemini_II.Led.LED_Open(true);
54.switch(Rx_Buffer[2])
55.{
56.case0x01:
57.Gemini_II.Led.ShowInfo("LED0亮");
58.Gemini_II.Led.LED_Out(0,true);
59.break;
60.case0x02:
61.Gemini_II.Led.ShowInfo("LED1亮");
62.Gemini_II.Led.LED_Out(1,true);
63.break;
64.case0x03:
65.Gemini_II.Led.ShowInfo("LED2亮");
66.Gemini_II.Led.LED_Out(2,true);
67.
68.break;
69.case0x04:
70.Gemini_II.Led.ShowInfo("LED3亮");
71.Gemini_II.Led.LED_Out(3,true);
72.break;
73.case0x05:
74.Gemini_II.Led.ShowInfo("LED4亮");
75.Gemini_II.Led.LED_Out(4,true);
76.break;
77.default:
78.Gemini_II.Led.ShowInfo(ErrorInfo);
79.break;
80.}
81.}
82.}
83.elseif(Rx_Buffer[1]==Close)
84.{
85.switch(Rx_Buffer[2])
86.{
87.case0x01:
88.Gemini_II.Led.ShowInfo("LED0灭");
89.Gemini_II.Led.LED_Out(0,false);
90.break;
91.case0x02:
92.Gemini_II.Led.ShowInfo("LED1灭");
93.Gemini_II.Led.LED_Out(1,false);
94.break;
95.case0x03:
96.Gemini_II.Led.ShowInfo("LED2灭");
97.Gemini_II.Led.LED_Out(2,false);
98.break;
99.case0x04:
100.Gemini_II.Led.ShowInfo("LED3灭");
101.Gemini_II.Led.LED_Out(3,false);
102.break;
103.case0x05:
104.Gemini_II.Led.ShowInfo("LED4灭");
105.Gemini_II.Led.LED_Out(4,false);
106.break;
107.default:
108.Gemini_II.Led.ShowInfo(ErrorInfo);
109.break;
110.}
111.}
112.}
113.}
114.}
115.}
116.程序调试运行情况说明
(1)界面设计部分成果
(2)LED控制成果
四、实验总结:
这次期末的测试中通过自己的思考和对以前知识的总结,相对来说整体测试不算太难,也许结果和平时的学习程度成正比。
在碰到问题时候应该先找出可能出现的原因,而不能盲目的去寻找解决办法。
对于学到的东西要会应用,不能光敲代码,为了完成任务而完成任务,对自己所学的知识一无所知。