button1, button2, richtexbox1, serialport1,

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;

namespace serialCom
{
public partial class Form1 : Form
{
 
string datain;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM5"; //通信端口
serialPort1.BaudRate = 4800; //设置波特率
serialPort1.Open();//打开串口
}

private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
datain = serialPort1.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}

//定义返回数据函数
private void DisplayText(object sender, EventArgs e)
{
richTextBox1.Text = datain;

}

private void button2_Click(object sender, EventArgs e)
{
serialPort1.Close();
Close();
}

}
}

*************************************************************************

2.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.IO;

namespace sw
{
public partial class Form1 : Form
{
Queue<string> dataQueue = new Queue<string>(100);
int num =10;
string datain;

Boolean flag = true;

public Form1()
{
InitializeComponent();
serialInt();
InitChart();
}
private void button1_Click(object sender, EventArgs e)
{
serialSetInt();

this.timer1.Start();

}

private void button2_Click(object sender, EventArgs e)
{

if (flag == true)
{
this.timer1.Stop();
serialPort1.Close();
flag = false;
button2.Text = "继续测量";
}
else
{
this.timer1.Start();
serialPort1.Open();
flag = true;
button2.Text = "暂停测量";
}

}
private void button4_Click(object sender, EventArgs e)
{
this.timer1.Stop();
Close();
}

private void timer1_Tick(object sender, EventArgs e)
{

this.chart1.Series[0].Points.Clear();

updateQueue();
for (int i = 0; i < dataQueue.Count; i++)
{

this.chart1.Series[0].Points.AddXY(i, dataQueue.ElementAt(i));

}
}

private void updateQueue()
{

if (dataQueue.Count > 90)
{
//先出列
for (int i = 0; i < num; i++)
{
dataQueue.Dequeue();
}
}
for (int i = 0; i < num; i++)
{

dataQueue.Enqueue(datain);

}
this.chart1.ChartAreas[0].AxisY.Maximum = Convert.ToDouble(dataQueue.Max()) + 5;
//this.chart1.ChartAreas[0].AxisY.Minimum = Convert.ToDouble(dataQueue.Min()) +5;

}

private void serialSetInt()
{
serialPort1.PortName = comboBox1.Text;
serialPort1.Open();
serialPort1.BaudRate = int.Parse(comboBox2.Text);

}
private void serialInt()
{
string[] portList = System.IO.Ports.SerialPort.GetPortNames();
for (int i = 0; i < portList.Length; ++i)
{
string name = portList[i];
comboBox1.Items.Add(name);
}

string[] BaudRateList = { "1200","2400", "4800", "9600","19200","38400","57600","115200" };
for (int i = 0; i < BaudRateList.Length; i++)
{
comboBox2.Items.Add(BaudRateList[i]);
}

}

private void InitChart()
{
//定义图表区域
this.chart1.ChartAreas.Clear();
ChartArea chartArea1 = new ChartArea( );
this.chart1.ChartAreas.Add(chartArea1);
//定义存储和显示点的容器
this.chart1.Series.Clear();
Series series1 = new Series( );
this.chart1.Series.Add(series1);
//设置图表显示样式
this.chart1.ChartAreas[0].AxisY.Minimum = 260;
this.chart1.ChartAreas[0].AxisY.Maximum =360;
this.chart1.ChartAreas[0].AxisX.Interval = 5;
this.chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart1.Series[0].Color = Color.Red;
this.chart1.Series[0].ChartType = SeriesChartType.Line;

}

private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
datain= serialPort1.ReadExisting();
}

}
}

***********************************************************************

3.

read temperature的更多相关文章

  1. [LeetCode] Rising Temperature 上升温度

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  2. BZOJ2276: [Poi2011]Temperature

    2276: [Poi2011]Temperature Time Limit: 20 Sec  Memory Limit: 32 MBSubmit: 293  Solved: 117[Submit][S ...

  3. leetcode-Rising Temperature

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  4. Application to find the maximum temperature in the weather dataset

    import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop. ...

  5. Leetcode 197. Rising Temperature

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  6. Temperature hdu 3477

    Temperature Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  7. [SQL]LeetCode197. 上升的温度 | Rising Temperature

    SQL架构 Create table If Not Exists Weather (Id int, RecordDate date, Temperature int) Truncate table W ...

  8. Raspberry pi connect temperature and humidity to onenet (移动云平台)

    工具 树莓派3 modelB 一个 dht11温湿度传感器一个  onenet平台 安装好requests库的python(一定要安装好不然代码不能正确运行,可以参考我的另一篇博文点击打开链接) 树莓 ...

  9. STM32 F4 ADC DMA Temperature Sensor

    STM32 F4 ADC DMA Temperature Sensor Goal: detecting temperature variations using a temperature senso ...

  10. [SQL]197. Rising Temperature

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

随机推荐

  1. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  2. yum update 自动忽略内核更新

    系统每天凌晨 3 点自动执行 yum update 任务 但升级内核后,会出现下面情况 一些编译软件需要内核模块才能够被调用, 而内核模块需要与当前版本内核编译后才能够使用, 假设内核升级后,之前软件 ...

  3. MS17-010漏洞检测

    1.扫描脚本的下载和加载 由于Metasploit还没有更新MS17-010检测的模块,所以要去exploit-db下载,并在MSF中加载. cd /usr/share/metasploit-fram ...

  4. 我的一次rsync+inotify本地数据同步示例

    环境: web工作目录:/var/www/mydafuhao git仓库目录: /var/www/mydafuhao.git/mydafuhao 需求:inotify监控git仓库目录,发现有版本更新 ...

  5. python 文件操作: 文件操作的函数, 模式及常用操作.

    1.文件操作的函数: open("文件名(路径)", mode = '模式', encoding = "字符集") 2.模式: r , w , a , r+ , ...

  6. Jmeter(三十九)获取响应结果中参数出现的次数(转载)

    转载自 http://www.cnblogs.com/yangxia-test 在测试中,有时候会遇到要统计响应结果中某个参数出现了多少次,如果量级很大,一个一个数不太现实,下面讲一下实现自动打印出该 ...

  7. weechat 常用指令

    添加服务器: /server add freenode irc.freenode.org 设置nick: /set irc.server.freenode.nicks "mynick,myn ...

  8. 在window下搭建Vue.Js开发环境(转)

    nodejs官网http://nodejs.cn/下载安装包,无特殊要求可本地傻瓜式安装,这里选择2017-5-2发布的 v6.10.3 cmd命令行: node -v //显示node版本 v6.1 ...

  9. python网络爬虫《http和https协议》

    一.HTTP协议 1.官方概念: HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文 ...

  10. HDFS之深入简出(一)

    分布式文件系统HDFS 一:概述 1.HDFS设计目标 2.HDFS核心组件 3.HDFS副本机制 4.HDFS环境搭建 5.HDFS shell命令  java api 6.HDFS读写流程 7.H ...