资源简介
c#串口通讯log存储及实时波形绘制代码,工具比较实用,这里只有源代码,设计窗口的设计还需要大家自行根据我博客中的图片进行修改
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO.Ports;
using System.IO;
using System.Collections;
using System.Windows.Forms.DataVisualization.Charting;
using System.Text.Regularexpressions;
namespace WindowsFormsApp1
{
public partial class IO_Setting_Form : Form
{
private SerialPort ComDevice = new SerialPort();
private Queue dataQueue = new Queue(100);
private Queue stringdataQueue = new Queue(100);
private int num = 5;
public IO_Setting_Form()
{
InitializeComponent();
InitralConfig();
}
private void Form2_Load(object sender EventArgs e)
{
textBoxUpSpec.Text = “10“;
textBoxBottomSpec.Text = “0“;
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
AddParameters();
InitChart();
}
private void InitralConfig()
{
//查询主机上存在的串口
comboBox_Port.Items.AddRange(SerialPort.GetPortNames());
if (comboBox_Port.Items.Count > 0)
{
comboBox_Port.SelectedIndex = 0;
}
else
{
comboBox_Port.Text = “未检测到串口“;
}
comboBox_BaudRate.SelectedIndex = -1;
comboBox_DataBits.SelectedIndex = -1;
comboBox_StopBits.SelectedIndex = -1;
comboBox_CheckBits.SelectedIndex = -1;
//pictureBox_Status.BackgroundImage = Properties.Resources.red;
//this.pictureBox_Status.Image = Image.FromFile(Application.StartupPath “\\red.PNG“);
this.pictureBox_Status.Image = Image.FromFile(“D:/VS_Files/WindowsFormsApplication1/WindowsFormsApplication1/Icon/red.png“);
//向ComDevice.DataReceived(是一个事件)注册一个方法Com_DataReceived,当端口类接收到信息时时会自动调用Com_DataReceived方法
ComDevice.DataReceived += new SerialDataReceivedEventHandler(Com_DataReceived);
}
///
/// 一旦ComDevice.DataReceived事件发生,就将从串口接收到的数据显示到接收端对话框
///
///
///
///
char[] ch1={};
private void Com_DataReceived(object sender SerialDataReceivedEventArgs e)
{
//开辟接收缓冲区
byte[] Buffer = new byte[ComDevice.BytesToRead];
//从串口读取数据
ComDevice.Read(Buffer 0 Buffer.Length);
//实现数据的解码与显示
AddData(Buffer);
/*
string str1 = new ASCIIEncoding().GetString(Buffer);
for (int i = 0; i < str1.Length; i++)
{
if (stringdataQueue.Count > 100)
{
- 上一篇:Halcon生成的计算圆心C#代码
- 下一篇:C#客户管理源代码
相关资源
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
评论
共有 条评论