using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using System.IO;
using System.IO.Ports;
using System.Threading;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.IO; namespace MFWindowApplication1
{
public class Program : Microsoft.SPOT.Application
{
public static void Main()
{
Program myApplication = new Program(); Window mainWindow = myApplication.CreateWindow(); // Create the object that configures the GPIO pins to buttons.
GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null); #region Test //InterruptPort myBtn = new InterruptPort((Cpu.Pin)(0),
// true,
// Port.ResistorMode.PullDown,
// Port.InterruptMode.InterruptEdgeBoth);
//myBtn.OnInterrupt += (a, b, c) =>
//{
//}; // InputPort[] inputs = new InputPort[5];
//Cpu.Pin[] pins = new Cpu.Pin[]{
//Cpu.Pin.GPIO_Pin0,
//}; #endregion // Start the application
myApplication.Run(mainWindow);
} private Window mainWindow; public Window CreateWindow()
{
// Create a window object and set its size to the
// size of the display.
mainWindow = new Window();
mainWindow.Height = SystemMetrics.ScreenHeight;
mainWindow.Width = SystemMetrics.ScreenWidth; // Create a single text control.
Text text = new Text(); text.Font = Resources.GetFont(Resources.FontResources.small);
text.TextContent = Resources.GetString(Resources.StringResources.String1);
text.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
text.VerticalAlignment = Microsoft.SPOT.Presentation.VerticalAlignment.Center; // Add the text control to the window.
mainWindow.Child = text; // Connect the button handler to all of the buttons.
mainWindow.AddHandler(Buttons.ButtonUpEvent, new RoutedEventHandler(OnButtonUp), false); // Set the window visibility to visible.
mainWindow.Visibility = Visibility.Visible; // Attach the button focus to the window.
Buttons.Focus(mainWindow); SerialPort sp = new SerialPort("COM1", );
sp.Open();
sp.DataReceived += (a, b) =>
{
int nDL = sp.BytesToRead;
int i = ;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
while (i < nDL)
{
byte[] datas = new byte[nDL];
int nLen = sp.Read(datas, , datas.Length);
string s = new string(System.Text.Encoding.UTF8.GetChars(datas, , nLen));//0, nLen
sb.Append(s);
i += nLen;
} text.Dispatcher.Invoke(new TimeSpan(),
new DispatcherOperationCallback((v) =>
{
text.TextContent = v == null ? "#ERROR" : v.ToString();
return true;
}),
sb.ToString());
};
return mainWindow;
} private void OnButtonUp(object sender, RoutedEventArgs evt)
{
ButtonEventArgs e = (ButtonEventArgs)evt; // Print the button code to the Visual Studio output window.
Debug.Print(e.Button.ToString());
}
}
}

MF 模拟器读取PC串口数据的更多相关文章

  1. android模拟器使用PC串口调试

    android模拟器使用PC串口调试1.模拟器可以使用PC的串口  启动模拟器并加载PC串口 命令如下:  运行 emulator @模拟器名称 -qemu -serial COM12.查看串口是否被 ...

  2. python 下串口数据的读取,解析,和保存-

    #!/usr/bin/python # -*-coding: utf-8 -*- import serial import threading import binascii from datetim ...

  3. C#SerialPort如何读取串口数据并显示在TextBox上

    SerialPort中串口数据的读取与写入有较大的不同.由于串口不知道数据何时到达,因此有两种方法可以实现串口数据的读取.一.线程实时读串口:二.事件触发方式实现. 由于线程实时读串口的效率不是十分高 ...

  4. python3 读取串口数据

    python3 读取串口数据 demo import serial import time ser = serial.Serial("COM3",115200,timeout = ...

  5. 基于FPGA的红外遥控解码与PC串口通信

    基于FPGA的红外遥控解码与PC串口通信 zouxy09@qq.com http://blog.csdn.net/zouxy09 这是我的<电子设计EDA>的课程设计作业(呵呵,这个月都拿 ...

  6. Android(Linux)实时监控串口数据

    之前在做WinCE车载方案时,曾做过一个小工具TraceMonitor,用于显示WinCE系统上应用程序的调试信息,特别是在实车调试时,用于监控和显示CAN盒与主机之间的串口数据.因为需要抢占市场先机 ...

  7. C# ---- 串口数据YSI实例

    原文:C# ---- 串口数据YSI实例 C#----串口数据接收发送中,发送接收数据已经可以模拟了. 本次YSI实例过程中 主要是:类型转换问题 .计算校验码 一.不同设备不同的规则,本次实例代码如 ...

  8. STM32—无需中断来实现使用DMA接收串口数据

    本节目标: 通过DMA,无需中断,接收不定时长的串口数据 描述:当在串口多数据传输下,CPU会产生多次中断来接收串口数据,这样会大大地降低CPU效率,同时又需要CPU去做其它更重要的事情,我们应该如何 ...

  9. [转]WEB页获取串口数据

    本文转自:https://www.cnblogs.com/rockyhm/p/3434200.html 最近做一个B/S的项目,需要读取电子秤的值,之前一直没做过,也没有经验,于是在网上找到很多  大 ...

随机推荐

  1. wordpress调用tags作为keywords关键词标签

    有网友问怎么调用wordpress tags作为页面keywords标签?wordpress开发文档有提供了get_tags函数,我们进行改造一下就ok了.下面随ytkah一起来看看如何实现.首先下面 ...

  2. js 类型系统的核心:元类型、原型链与内省机制

    js 类型系统的核心:元类型.原型链与内省机制 二.JS数据类型 下面就来看看JS中的数据类型,在js中定义了如下几种数据类型:大方向上分为 基本数据类型(简单数据类型) 和 引用数据类型(复杂数据类 ...

  3. 编程语言的类型修饰符modifiers

    编程语言修饰符,代表语言要素与常规表达不同的语义: 这些语义的不同需要编译器和运行时作出不同的解释: 作用域.访问: 生命周期: 同步异步: 多态: 纯函数: 注解: 懒加载: 编译器合成:

  4. Boring counting HDU - 3518 (后缀数组)

    Boring counting \[ Time Limit: 1000 ms \quad Memory Limit: 32768 kB \] 题意 给出一个字符串,求出其中出现两次及以上的子串个数,要 ...

  5. MongoDB repairDatabase 释放磁盘空间

    repairDatabase是官方文档中认为唯一可以回收硬盘空间的方法. repairDatabase is the appropriate and the only way to reclaim d ...

  6. Xamarin.Forms之主题

    Xamarin.Forms应用程序可以使用DynamicResource标记扩展在运行时动态响应样式更改. 此标记扩展类似于StaticResource标记扩展,两者都使用字典键从ResourceDi ...

  7. Technocup 2020 Elimination Round 3题解

    传送门 \(A\) 曲明连sb模拟不会做,拖出去埋了算了 //quming #include<bits/stdc++.h> #define R register #define fi fi ...

  8. 文件系统EXT3,EXT4和XFS的区别

    1. EXT3 (1)最多只能支持32TB的文件系统和2TB的文件,实际只能容纳2TB的文件系统和16GB的文件 (2)Ext3目前只支持32000个子目录 (3)Ext3文件系统使用32位空间记录块 ...

  9. [NOIP2013]华容道 题解

    [NOIP2013]华容道 首先是一种比较显然的做法. 整个棋盘,除了起点,终点和空格,其他的方块是等价的. 对于终点,它始终不会变化,如果搜到终点结束搜索即可,所以我们不需要考虑终点. 所以需要考虑 ...

  10. Http协议以及Httpclient

    一.HTTP之请求消息Request 客户端发送一个HTTP请求到服务器的请求消息包括以下格式: 请求行(request line).请求头部(header).空行和请求数据四个部分组成. Http请 ...