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的项目,需要读取电子秤的值,之前一直没做过,也没有经验,于是在网上找到很多 大 ...
随机推荐
- wordpress角色权限汇总
我们在用wordpress开发的时候有时候需要设置不同的用户组及权限,具体有哪些角色权限呢?随ytkah一起来看看吧.WordPress使用了角色的概念,旨在让站点所有者能够控制用户在站点中可以做什么 ...
- query_posts函数使用方法小结|wordpress技巧
query_posts是wordpress非常好用的调用文章函数,可以调用某个分类.标签.日期及作者等不同范围的文章列表.下面随ytkah一起来看看query_posts函数使用方法小结 首先是que ...
- signed Unsigned Compare
// signUnsignCompare.cpp : Defines the entry point for the console application. // #include "st ...
- vue element-ui 饿了么布局,gutter间距碰上bordr 会失效
//如下情况,gutter间距会失效 <el-row :gutter="20"> <el-col :span="12" style=" ...
- keil中error: #70: incomplete type is not allowed—解决方法
今天在写程序的时候,想使用sizeof求数组的大小,数组中其他c文件定义,在头文件使用extern uint8_t buff_value[]; 声明 但是keil编译报错,网上查了,发现,需要写成ex ...
- 【每天学一点linux】后台进程不打印日志
command > out.file 2>&1 & 将文件输出到指定的文件中
- [Algorithm] 206. Reverse Linked List
Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4-> ...
- GitHub上如何创建文件夹
看了网上很多关于如何在git上创建空文件夹的文章后,发现大家写的都是用指令在本地创建一个空文件夹后再上传指令和步骤都太繁琐且复杂了,对于用git不是很熟练得到人来说太麻烦了,而且在本地于github上 ...
- k8s实现灰度发布
灰度发布在实际生产部署中是经常被使用的方式,常规的方法是手动从前端LB(负载均衡)上将后端服务器摘掉,然后,停服务,最后上传代码,完成软连接更新.在使用CI/CD工具时,这个过程变得自动化了,我们只需 ...
- Xilinx ISE中Synplicity.ucf无法加上去的问题
在Xilinx ISE中使用Synplify pro进行综合时,有时出现无法将synplicity.ucf添加进工程的问题.这时可以在其它目录下备份synplicity.ucf, 然后使用clean ...