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. js沉思录一:js的核心概念

    js的核心概念: 原型.对象(Object).函数(Function); 原型:路由路径上非叶子结点的对象: 对象:无序属性(包括函数)的集合: 函数:函数上下文的集合: 原型: 原型的创建.指定.修 ...

  2. luogu P1550 [USACO08OCT]打井Watering Hole

    题目背景 John的农场缺水了!!! 题目描述 Farmer John has decided to bring water to his N (1 <= N <= 300) pastur ...

  3. mybatis 根据多个id查询数据 foreach标签

    //根据设备多个id获取设备信息 public List<Devices> getDevicesAll(@Param("devicesIds") String[] de ...

  4. quick: setup_mac.sh分析

    //quick: setup_mac.sh分析 //quick: setup_mac.sh分析#!/bin/bash //获取并打印根目录QUICK_V3_ROOTDIR="$( cd &q ...

  5. hosts 屏蔽广告 定位

    hosts 屏蔽广告 定位 JS Miner 挖矿 百度全家桶的全天候定位记录 各类统计服务(仅屏蔽 JS.不屏蔽控制台) 常见下载劫持 360 和百度的部分软件下载 CNNIC 根证书劫持 http ...

  6. 【转】守护进程二三事与Supervisor

    扩展阅读:理解Docker容器的进程管理 最顶层的是系统初始化时创建的root namespace(根名空间),再创建的新PID namespace就称之为child namespace(子名空间), ...

  7. Jdk8 DNS解析

    注:JDK7和JDK8关于DNS解析的实现有差异,该问题在JDK7下可能不存在: Java中的DNS解析一般是通过调用下面的方法: public static InetAddress getByNam ...

  8. .Net Core3 新特性整理

    .net core 3实现了.net 标准2.1. 1.生成可执行文件 以前版本需要dotnet run运行项目,.net core 3支持直接生成目标平台的可执行文件.比如windows就是exe了 ...

  9. In Vitro model验证 | Harnessing single-cell genomics to improve the physiological fidelity of organoid-derived cell types

    Transcriptional benchmarking of in vitro cells to in vivo with single-cell rna-seq - 简介 Harnessing s ...

  10. Android相关视频

    Android架构师 层次分析 –从顶层到底层 洞察其原理https://www.bilibili.com/video/av59066641?t=132安卓/Android 逆向破解系统班 第2期 全 ...