MF 模拟器读取PC串口数据


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串口数据的更多相关文章
- android模拟器使用PC串口调试
android模拟器使用PC串口调试1.模拟器可以使用PC的串口 启动模拟器并加载PC串口 命令如下: 运行 emulator @模拟器名称 -qemu -serial COM12.查看串口是否被 ...
- python 下串口数据的读取,解析,和保存-
#!/usr/bin/python # -*-coding: utf-8 -*- import serial import threading import binascii from datetim ...
- C#SerialPort如何读取串口数据并显示在TextBox上
SerialPort中串口数据的读取与写入有较大的不同.由于串口不知道数据何时到达,因此有两种方法可以实现串口数据的读取.一.线程实时读串口:二.事件触发方式实现. 由于线程实时读串口的效率不是十分高 ...
- python3 读取串口数据
python3 读取串口数据 demo import serial import time ser = serial.Serial("COM3",115200,timeout = ...
- 基于FPGA的红外遥控解码与PC串口通信
基于FPGA的红外遥控解码与PC串口通信 zouxy09@qq.com http://blog.csdn.net/zouxy09 这是我的<电子设计EDA>的课程设计作业(呵呵,这个月都拿 ...
- Android(Linux)实时监控串口数据
之前在做WinCE车载方案时,曾做过一个小工具TraceMonitor,用于显示WinCE系统上应用程序的调试信息,特别是在实车调试时,用于监控和显示CAN盒与主机之间的串口数据.因为需要抢占市场先机 ...
- C# ---- 串口数据YSI实例
原文:C# ---- 串口数据YSI实例 C#----串口数据接收发送中,发送接收数据已经可以模拟了. 本次YSI实例过程中 主要是:类型转换问题 .计算校验码 一.不同设备不同的规则,本次实例代码如 ...
- STM32—无需中断来实现使用DMA接收串口数据
本节目标: 通过DMA,无需中断,接收不定时长的串口数据 描述:当在串口多数据传输下,CPU会产生多次中断来接收串口数据,这样会大大地降低CPU效率,同时又需要CPU去做其它更重要的事情,我们应该如何 ...
- [转]WEB页获取串口数据
本文转自:https://www.cnblogs.com/rockyhm/p/3434200.html 最近做一个B/S的项目,需要读取电子秤的值,之前一直没做过,也没有经验,于是在网上找到很多 大 ...
随机推荐
- oracle中删除表:drop、delete、truncate
相同点,使用drop delete truncate 都会删除表中的内容 drop table 表名 delete from 表名(后面不跟where语句,则删除表中所有的数据) truncate t ...
- The difference between Virtual DOM and DOM
dom是结构化的文本信息的抽象,是结构化的文本信息在内存中的表示 是操作结构化文本信息的api. Follow: Follow React attacks us with the virtual DO ...
- python--递归函数讲解
递归算法是一种直接或间接调用自身算法的过程. 递归算法解决问题的特点: (1)递归就是在过程或函数里调用自身 (2)在使用递归策略时,必须有一个明确的递归结束条件,称为递归出口. (3)递归算法解题通 ...
- [Cqoi2016]K远点对 K-Dtree
4520: [Cqoi2016]K远点对 链接 bzoj 思路 用K-Dtree求点的最远距离. 求的时候顺便维护一个大小为2k的小根堆. 不知道为啥一定会对. 代码 #include <bit ...
- luogu P2353 背单词
二次联通门 : luogu P2353 背单词 一眼看过去, 卧槽,AC自动机板子题 写完后T成SB 卧槽10^6 做个篮子啊 重构思路... 恩..Hash + 莫队... 恶心啊.. 找xxy d ...
- python 整数转16进制数
def toHex(num): """ :type num: int :rtype: str """ chaDic = {: : : : : ...
- 【POJ1426】Find The Multiple
本题传送门 本题知识点:深度优先搜索 | 宽度优先搜索 题意很简单,让我们找一个只有1和0组成的十位数是n的倍数的数. 这题一开始吓到我了--因为Output里说输出的长度最长不超过100位???那是 ...
- Python 元编程
1.为函数添加包装器 总是存在这样的场景,在一个函数执行前后需要做一些操作处理,常见于日志创建.权限认证或者性能分析等.但有一个问题存在,那就是被装饰的函数,其元信息会丢失,函数引用会指向装饰器的返回 ...
- C复习---动态内存分配
原型extern void *malloc(unsigned int num_bytes);头文件#include <stdlib.h>#include <malloc.h>函 ...
- [Web] mobx 异步操作
转载自:https://www.jianshu.com/p/66dd328726d7 异步action action只能影响正在运行的函数,而无法影响当前函数调用的异步操作 .action 包装/装饰 ...