c# serialport读取不限数量的16进制数据
2016-07-04 21:59
393 查看
//private char[] HexChar = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) { char hexH; char hexL; byte receivebyte; string dataToshow = ""; while (serialPort1.BytesToRead > 0) { receivebyte = (byte)serialPort1.ReadByte(); hexH = HexChar[receivebyte / 16]; hexL = HexChar[receivebyte % 16]; dataToshow += hexH.ToString() + hexL.ToString(); } this.tBox.Invoke(new MethodInvoker(delegate { this.tBox.AppendText(dataToshow + "\n"); })); }
相关文章推荐
- [C#6] 3-null 条件运算符
- MD5算法原理简要介绍并采用C#应用在桌面应用系统的用户登录与注册中
- C#中的Sealed和J#中的Final比较(转载)
- C# 对象的使用
- C#实现对远程服务器的内存和CPU监控
- c# 16进制显示转化
- C# Enum,Int,String的互相转换 枚举转换
- c#断点无效:"当前不会命中断点。没有与此行关联的可执行代码。可能的原因包括:条件编译或编译器优化"
- c# listView
- c# datagridview列头添加复选框实现全选
- C# 用interface和delgate实现回调-----配合索引器实现List
- C#中字符 '\0' 是a还是空格?
- [转]DataGridView 的右键菜单(ContextMenuStrip)
- C# 中的#if、#elif、#else、#endif等条件编译符号
- C# 获取一个13位的时间戳
- 【C#编写Windows服务】
- [转]C#多线程学习 之 线程池[ThreadPool]
- 值类型 引用类型 ref out
- C# IEnumerator, IEnumerable, and Yield
- C#==>匿名方法