- 浏览: 276157 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
weituotian:
这篇文章真的很好阿
C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值 -
clshuai:
博主,你好,看了你的这篇文章,让我很敬佩。可谓内容之全,涵盖范 ...
C#操作Excel -
devilhand:
DataGridView刷新数据的问题 -
devilhand:
DataGridView刷新数据的问题 -
devilhand:
DataGridView刷新数据的问题
发送串口数据: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO.Ports; namespace SendData { class Program { static void Main(string[] args) { SerialPort port = new SerialPort(); Console.WriteLine("串口(如COM1):"); port.PortName = Console.ReadLine(); Console.WriteLine("波特率:"); port.BaudRate = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("数据位:"); port.DataBits = Convert.ToInt32(Console.ReadLine()); int stopBits = 0; Console.WriteLine("停止位:"); stopBits = Convert.ToInt32(Console.ReadLine()); switch (stopBits) { case 0: port.StopBits = StopBits.None; break; case 1: port.StopBits = StopBits.One; break; case 2: port.StopBits = StopBits.Two; break; default: port.StopBits = StopBits.None; break; } try { port.Open(); string sendData=""; bool exitFlag=false; while (exitFlag == false) { Console.WriteLine("要发送的数据:"); sendData = Console.ReadLine(); if (sendData.CompareTo("exit") == 0) break; else port.WriteLine(sendData); } port.Close(); } catch(Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); } } } } 接受串口数据: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO.Ports; namespace RecvData { class Program { static void Main(string[] args) { SerialPort port = new SerialPort(); Console.WriteLine("串口(如COM1):"); port.PortName = Console.ReadLine(); Console.WriteLine("波特率:"); port.BaudRate = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("数据位:"); port.DataBits = Convert.ToInt32(Console.ReadLine()); int stopBits = 0; Console.WriteLine("停止位:"); stopBits = Convert.ToInt32(Console.ReadLine()); switch (stopBits) { case 0: port.StopBits = StopBits.None; break; case 1: port.StopBits = StopBits.One; break; case 2: port.StopBits = StopBits.Two; break; default: port.StopBits = StopBits.None; break; } try { port.Open(); bool exitFlag = false; int n = 0; while (exitFlag == false) { Console.WriteLine(port.ReadLine()); n++; if (n == 999999) { Console.WriteLine("是否继续?(y/s)"); string ans = Console.ReadLine(); if (ans.CompareTo("y") == 0) exitFlag = true; else n = 0; } } port.Close(); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); } } } }
发表评论
-
C#获取本地IP
2012-06-06 14:39 888/// <summary> ... -
只能启动单个程序
2012-05-04 12:51 783bool ret; System. ... -
.Net控件命名规范
2012-04-25 14:45 772<!--------------A----------- ... -
DataGridView绑定数据时,时间格式显示不全的问题
2012-04-25 13:54 991DataGridView绑定数据时,时间格式显示问题 今天做 ... -
把Dgv的颜色改回默认颜色
2012-04-25 13:35 924dgv.Rows[i].DefaultCellStyle.Ba ... -
Winform 去掉 最大化 最小化 关闭按钮 保留左侧图片
2012-04-23 17:02 1144using System; using System.Col ... -
禁用窗体的关闭按钮
2012-04-23 16:58 838[DllImport("USER32 ... -
c#中用声音提示报警
2012-03-14 09:51 1699using System; using System.Ru ... -
WinForm 查看控制台输出
2012-02-15 10:39 1271/// <summary> ... -
C# 启动外部程序的几种方法
2011-10-17 19:15 7211. 启动外部程序,不等待其退出。2. 启动外部程序,等待其退 ... -
解决VS2005不能调试线程问题
2011-08-12 12:33 2370昨天突然VS2005不能调试线程,网上找了很多方法都不行,后来 ... -
通过域名获取IP的两种方法
2011-07-16 15:09 1814//每次都去Dns服务器上 ... -
执行命名行命令
2011-07-16 14:41 681/// <summary> / ... -
获取指定目录下所有文件
2011-07-01 20:48 1454命名空间 using System.Collections; ... -
C#控制Excel的打印格式
2011-06-22 20:54 3696Excel.Application appExcel=n ... -
C#操作Excel
2011-06-22 14:28 1583using System; using System. ... -
C# 操作Excel的类
2011-06-22 14:20 1332using System; using Micro ... -
DataGridView刷新数据的问题
2011-06-21 11:39 41961、操作:UI线程修改数据后重新绑定dgv,一个后台线程定时刷 ... -
VS2005水晶报表注册码
2011-06-18 13:40 7036707437608 -
按Enter键时,焦点移到下一个控件
2011-06-18 10:06 1209#region 按Enter键时,焦点移 ...
相关推荐
c# 串口发送数据c# 串口发送数据c# 串口发送数据c# 串口发送数据
C#实现串口发送接收数据,有简单的版本和基于协议的两种版本,完整项目文件和详细注释
C# 串口数据接收与发送 示例源码
基于C#的rs232发送和接收数据 基于C#的串口发送和接收数据
c#中串口接收数据并且生成EXCEL
unity3D串口通信程序,可以实现发送接收。脚本语言是C#编写。基本满足通信要求。
1.解决了接收数据不完整、不连续、丢数据等问题。 2.基本达到了超级终端的接收效果。 3.委托+线程+终止符,三项组合才能完美解决上述问题。 4.注意波特率设置应根据发送方效率而选择。 5.完整代码、非常简洁,拿来...
以网上某位大虾的源码为版本,沿用了其可用的代码部分。对其余欠妥部分进行了改造。不要资源分,是大家不用为积分而烦恼。出来混都不容易,希望大家相互照应!
采用C#开发,将下位机发送的数据显示并绘制曲线,配套FPGA频率计下位机
在做项目时,发现C#串口经常会发生丢帧的情况,在发送/接收大量数据时,这种状况尤为明显。因此,在对比了各种缓存处理办法的基础上,做了这个小程序。经过实测,完全可以应对48byte/5ms的数据量。这个小程序只做了...
C#串口通讯时,已经实现正确发送数据包,正确得到回复;如何实现若发送失败最多发送5次,并且发送多个数据包时,发送数据和回复数据在界面的显示不串行;我尝试做过,会出现数据串行,或者一帧数据已成功发送、回复...
使用VS2008编写的C#串口程序,成功发送接收ASCC数据,没有做发送接收二进制的
按照伍兄的博文抄下来的。 博文地址:http://www.cnblogs.com/wuhuacong/archive/2011/07/19/2111055.html#commentform 为了赚点下载分。谢谢!
用C#.NET实现的最简单的串口发送和接收程序,有函数说明。
对C#的serialport类功能进行了总结,给出了发送,接收数据的完整操作类代码,可直接运用该类进行c#的串口数据操作
程序要求:与两个串口进行通讯,定时发出数据,对返回的数据进行处理(帧头帧尾识别),经过算法,得到一组数据,并将其输出到chart图表上(折线图),最后保存图表。
C#操作串口,发送数据,接收数据.Demo中代码已经调试通过
C# 串口 接收和发送数据,用串口助手可以实现数据的接收和发送。
通过串口发送接收数据
c# 打开本机串口接收发送 程序 以及MODBUS 数据CRC校验适用于初级通讯,如有其它需要可以联系我