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的项目,需要读取电子秤的值,之前一直没做过,也没有经验,于是在网上找到很多 大 ...
随机推荐
- 第一个python&selenium自动化测试实战项目
说明:本项目采用流程控制思想,未引用unittest&pytest等单元测试框架 一.项目介绍 目的 测试某官方网站登录功能模块可以正常使用 用例 1.输入格式正确的用户名和正确的密码,验证是 ...
- Pros and Cons of Game Based Learning
https://www.gamedesigning.org/learn/game-based-learning/ I remember days gone by at elementary schoo ...
- Windows Automation API 3.0 Overview
https://www.codemag.com/article/0810042 While general accessibility requirements (such as font color ...
- LwIP应用开发笔记之八:LwIP无操作系统HTTP客户端
前面我们实现了TCP服务器和客户端的简单应用,接下来我们实现一个基于TCP协议的应用协议,那就是HTTP超文本传输协议 1.HTTP协议简介 超文本传输协议(Hyper Text Transfer P ...
- Numpy | 01 简介
NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库. NumPy 是一个运行速度非常快的数学库 ...
- 59: loj #10215
$des$ https://loj.ac/problem/10215 $sol$ exgcd检查 $code$ #include <iostream> #include <cstdl ...
- 洛谷p2330繁忙的都市题解
题面 根据题意来分析, 要求出你选了几条路, 最小生成树是能解的, 那么就直接输出n - 1条路即可, 至于最大值则走一遍最小生成树求出即可 这里提供最小生成树的两种方法 1. 克鲁斯卡尔 克鲁斯卡尔 ...
- cogs 920. [東方S1] 琪露诺
二次联通门 : cogs 920. [東方S1] 琪露诺 /* cogs 920. [東方S1] 琪露诺 dp 方程为dp[i] = max (dp[i - L], dp[i - L + 1] ... ...
- MySQL中自增ID起始值修改方法
在实际测试工作过程中,有时因为生产环境已有历史数据原因,需要测试环境数据id从某个值开始递增,此时,我们需要修改数据库中自增ID起始值,下面以MySQL为例: 表名:users; 建表时添加: ); ...
- Django 的 slug url 正则匹配
如果按照 .* 去匹配,最后会把 /edit/ 和 /delete/ 也匹配进去. urlpatterns = [ #... url(r'^(?P<slug>.*)/$', post_de ...