为了学习C#,所以,自己动手,开发了一个小小的控制台版本的串口调试助手PjComm,截图如下:

上图中的蓝色背景的字符,为热键。在使用SendData时,若串口没有打开,则自动打开。若已经打开,会暂时关闭串口。

默认的串口设置参数是com1,115200,8,1,none。

整个窗口的第0-18行为串口信息显示行,每当显示完一屏幕之后,会自动将屏幕的内容保存至文件,并清屏继续显示。

下载地址:

【网通】点击下载PjComm,控制台版本的串口调试助手

【电信、网通】点击下载PjComm,控制台版本的串口调试助手

【下载说明】
1、单击上面这个地址,打开下载页面。
2、点普通下载--等待30秒--点“下载”按钮--保存

以上下载的为SharpDevelop 2.2的工程文件,若没有安装SHarpDevelop,请到这里下载。若没有安装.net framework 2.0,请到这里下载。

全部源程序如下:

/** Created by SharpDevelop.* User: PJ* Date: 2012-9-23* Time: 6:47* * To change this template use Tools | Options | Coding | Edit Standard Headers.*/
using System;using System.IO;
using System.Threading;
using System.IO.Ports;namespace PjComm
{class Program{private static int consoleHeight = 25;private static int consoleWidth = 80;// recv string(line0-line18),line19 is a split lineprivate static string[] recvBuffer = new string[19];// prompt(line 20),input(line 21),exception(line 22)private static string[] inputBuffer = new string[3];// menu(line23,line24)private static string menuString = string.Empty;private static SerialPort comm = new SerialPort();private static Thread inputThread = null;private static Thread recvThread = null;private static bool isExit = false;private static StreamWriter sw = null;static void HighlightChar(string str,char ch,int num){int n = 0;for(int i=0;i<str.Length;i++){if(str[i] == ch)n++;if(str[i] == ch && num == n){Console.BackgroundColor = ConsoleColor.Blue;}else{Console.BackgroundColor = ConsoleColor.Black;}Console.Write(str[i]);}}static void PrintMenuString(){Console.SetCursorPosition(0,23);HighlightChar("[PortName]",'P',1);HighlightChar("[BaudRate]",'B',1);HighlightChar("[DataBits]",'D',1);HighlightChar("[StopBits]",'S',1);HighlightChar("[Parity  ]",'a',1);HighlightChar("[OpenPort]",'O',1);HighlightChar("[ShutPort]",'h',1);HighlightChar("[SendData]",'n',1);HighlightChar("[ListPort]",'L',1);HighlightChar("[ExitProg]",'E',1);HighlightChar("[AboutMe ]",'u',1);}static void CleanLine(int left,int top){Console.SetCursorPosition(left,top);for(int i=0;i<consoleWidth;i++){Console.Write(" ");}Console.SetCursorPosition(left,top);}static void PromptString(string str){CleanLine(0,20);Console.Write(str);}static void InputResponse(string str){CleanLine(0,21);Console.Write(str);}static void ExceptionString(string str){CleanLine(0,20);Console.Write(str);}static void RecvThread(){int currentPrintLine = -1;while(!isExit){if(comm.IsOpen){try{string line = comm.ReadLine();currentPrintLine++;if(currentPrintLine < 19){Console.SetCursorPosition(0,currentPrintLine);Console.Write(line);recvBuffer[currentPrintLine] = line;}else{//save the buffer to filefor(int i=0;i<19;i++){sw.WriteLine(recvBuffer[i]);recvBuffer[i] = string.Empty;sw.Flush();}currentPrintLine = 0;for(int i=0;i<19;i++){CleanLine(0,i);}Console.SetCursorPosition(0,currentPrintLine);Console.Write(line);recvBuffer[currentPrintLine] = line;}}catch(Exception){}finally{}}}}static void InputThread(){while(!isExit){ConsoleKeyInfo pressKey = Console.ReadKey(true);switch(pressKey.KeyChar){case 'u':case 'U':PromptString("Application Information: ");InputResponse("Author: PJ  Email: joyee.peng@gmail.com  Blog: http://blog.csdn.net/pengqianhe");break;case 'p':case 'P':PromptString("Port Name(eg. com1): ");comm.PortName = Console.ReadLine();InputResponse("[OK]set the COM port to " + comm.PortName);break;case 'b':case 'B':PromptString("Baud Rate(eg. 115200): ");comm.BaudRate = int.Parse(Console.ReadLine());InputResponse("[OK]set baud rate to " + comm.BaudRate.ToString());break;case 'd':case 'D':PromptString("Data Bits(5~8): ");int n = int.Parse(Console.ReadLine());if( n >= 5 && n <= 8 ){InputResponse("[OK]set data bits to " + n.ToString());comm.DataBits = n;}else{InputResponse("[NG]must be 5 ~ 8.");}break;case 's':case 'S':PromptString("Stop Bits(1/2): ");int sb = int.Parse(Console.ReadLine());if(sb == 1 || sb == 2){InputResponse("[OK]send the stop bits to " + sb.ToString());comm.StopBits = (sb == 1) ? StopBits.One : StopBits.Two;}else{InputResponse("[NG]must be 1 or 2.");}break;case 'a':case 'A':PromptString("Parity(eg. None/Even/Odd/Mark/Space): ");switch(Console.ReadLine().ToLower()){default:case "none":comm.Parity = Parity.None;break;case "even":comm.Parity = Parity.Even;break;case "odd":comm.Parity = Parity.Odd;break;case "mark":comm.Parity = Parity.Mark;break;case "space":comm.Parity = Parity.Space;break;}InputResponse("[OK]set parity to " + comm.Parity.ToString());break;case 'o':case 'O':try{comm.Open();if(comm.IsOpen){ExceptionString("Open " + comm.PortName + " passed.");InputResponse("[OK]Open " + comm.PortName + " passed.");}}catch(Exception e){ExceptionString(e.Message);InputResponse("[NG]"+e.Message);}break;case 'h':case 'H':try{if(comm.IsOpen){comm.Close();ExceptionString("Close " + comm.PortName + " passed.");InputResponse("[OK]" + "Close " + comm.PortName + " passed.");}else{ExceptionString(comm.PortName + " is not opened.");}}catch(Exception e){ExceptionString(e.Message);InputResponse("[NG]"+e.Message);}break;case 'l':case 'L':SerialPort temp = new SerialPort();string ports = string.Empty;for(int i=1;i<256;i++){try{temp.PortName = "com" + i.ToString();temp.BaudRate = 115200;temp.StopBits = StopBits.One;temp.DataBits = 8;temp.Parity = Parity.None;temp.Open();if(temp.IsOpen){ports += temp.PortName + " ";ExceptionString("Open " + temp.PortName + "passed.");temp.Close();}}catch(Exception e){ExceptionString(e.Message);}}if(temp.IsOpen) temp.Close();ExceptionString("Valid Ports: " + ports);break;case 'e':case 'E':try{if(comm.IsOpen){comm.Close();ExceptionString("Close " + comm.PortName + " passed.");}else{ExceptionString(comm.PortName + " is not opened.");}}catch(Exception e){ExceptionString(e.Message);}isExit = true;break;case 'n':case 'N':if(comm.IsOpen) comm.Close();PromptString("Input your send string: ");string sendString = string.Empty;sendString = Console.ReadLine();if(sendString.Length > 0){InputResponse("[OK]set send string to \"" + sendString + "\".");PromptString("Add new line to the end(y/n)? ");string ans = Console.ReadLine();if(ans.Contains("y")){sendString += Environment.NewLine;}comm.Open();comm.Write(sendString);InputResponse("[OK]send data successfully.");}else{InputResponse("[NG]input string lenth is empty.");}break;}}}public static void Main(string[] args){Console.WindowHeight = consoleHeight;Console.WindowWidth = consoleWidth;string fileName = Environment.CurrentDirectory + "\\" + DateTime.Now.ToShortDateString() + ".log";sw = new StreamWriter(fileName,true);PrintMenuString();Console.SetCursorPosition(0,19);for(int i=0;i<consoleWidth;i++) Console.Write("*");Console.SetCursorPosition(0,22);for(int i=0;i<consoleWidth;i++) Console.Write("*");PromptString("Please set your port settings at first.");// load the default settingscomm.PortName = "com1";comm.BaudRate = 115200;comm.DataBits = 8;comm.StopBits = StopBits.One;comm.Parity = Parity.None;InputResponse("Default Setting: com1,115200,8,1,0");inputThread =  new Thread(new ThreadStart(InputThread));inputThread.Start();recvThread = new Thread(new ThreadStart(RecvThread));recvThread.Start();}}
}

【更多文章】

  1. [原]WMICodeCreator:C#产生WMI代码的工具
  2. [原]Hotkey.cs:为应用程序添加热键
  3. [原]ManageApps:C#读取Windows系统中的已经安装的程序并卸载软件
  4. [原]Hotkey.cs:为应用程序添加热键
  5. [原]SeeFiles:C#查看和修改文件或目录所有属性的工具
  6. [原]Baidu:C#利用百度来搜索网页、图片、视频等等
  7. [原]PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序
  8. [原]ManageApps:C#读取Windows系统中的已经安装的程序并卸载软件
  9. [原]PjCleanSystemTrash:C#清除系统盘垃圾
  10. [原]QQHelper:QQ大家来找茬 辅助工具 外挂

PjComm:控制台版本的串口调试助手相关推荐

  1. C#之windows桌面软件第三课:完整的串口调试助手

    接上一节,这节来编写一个完整的串口调试助手! using System; using System.Collections.Generic; using System.ComponentModel; ...

  2. uart口图片_uart 加强了的串口调试助手,可以自动记录传输数据,并且显示图片,示波器等功能 Com Port 编程 267万源代码下载- www.pudn.com...

    文件名称: uart下载  收藏√  [ 5  4  3  2  1 ] 开发工具: C# 文件大小: 10479 KB 上传时间: 2014-06-06 下载次数: 62 提 供 者: 林元峰 详细 ...

  3. Qt实践录:串口调试助手

    由于项目需要使用到串口调试及测试,为了练手,使用 Qt 编写一个串口调试助手.本文按开发的过程进行简单介绍,同时也涉及部分用到的模块代码.详细代码参考源码仓库. 工具特性 具体功能 具备串口收发功能. ...

  4. 【博客8】缤果PyQt5串口调试助手V1.1(初级篇)

    超级好用的Python QT GUI串口调试助手 目录 前言 一.软件概要: 二.软件界面: 1.App动态演示 2.其他扩展展示 三.main.py源码: 1.PyQt5_Serial_Debug_ ...

  5. 基于QT的串口调试助手

    大家好,我是KookNut39,在CSDN写文,分享一些自己认为在学习过程中比较重要的东西,致力于帮助初学者入门,希望可以帮助你进步.最近在更新C/C++方面的知识,感兴趣的欢迎关注博主,可以去专栏查 ...

  6. 使用Qt打造属于自己的串口调试助手

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家. 点击跳转到教程,人工智能编程入门博客 一个专注于嵌入式知识分享,学习路上不迷路的公众号,欢迎关注. 想加技术交流群的 ...

  7. 【博客4】缤果LabView串口调试助手V1.0 (初级篇)

    目录 超级好用的LabView串口调试助手! 目录 一.软件概要: 二.软件界面: 三.串口功能实现: 3.1 串口初始化 3.2 串口事件处理 3.2.1 打开串口 3.2.2 关闭串口 3.2.3 ...

  8. 自己写了一个串口调试助手

    五叶草串口调试助手(持续更新-) 最新版本v1.1.0.0 介绍 作为一个嵌入式开发者, 经常用到串口, 也经常因为串口调试助手而烦恼. 于是决定自己做一款串口调试助手. 修改日志 v1.1.0.0 ...

  9. java串口调试助手_基于 QML的 串口调试助手

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/weixin_38416696/arti ...

最新文章

  1. 百度 71 个炸天的开源项目!你知道几个?
  2. mysql-5.5.59安装_MySQL-5.5 安装
  3. transfer function
  4. 《UNIX环境高级编程》--符号链接
  5. 关于addr=u32(r.recvuntil(‘\xf7‘)[-4:])的解释
  6. 使用Kubernetes容器服务在云上搭建AI推理环境
  7. 京东与中国石化全面深化战略合作 涉及能源供应服务等
  8. 最简单的基于FFmpeg的移动端例子附件:SDL Android HelloWorld
  9. [QT][待解决问题]对话框ui载入卡顿问题
  10. 腾达U12无线网卡驱动安装教程
  11. win7计算机系统还原,如何使用Win7系统自带还原修复电脑
  12. ID卡介绍和工作原理
  13. oracle 查询表最大值,ORA-1653报错 调整oracle数据表的最大值
  14. cad批量选择相同块_在CAD中如何快速选择相同或类似的图形、图块
  15. CXF框架发布WebService服务的例子
  16. F功能键必须按Fn才管用,如何设置不按Fn就直接使用F键功能
  17. redis下载安装基本使用
  18. 有1克、2克、3克、4克的砝码各一枚,能称出哪几种重量?
  19. 二代征信已经来了,这些常识你还不懂么
  20. 豆瓣影片TOP250排名分析报告-PPT呈现

热门文章

  1. AcWing 713. 区间 2
  2. #10172. 「一本通 5.4 练习 1」涂抹果酱 【 三进制状态压缩 】【 方案数 】
  3. C语言使用文件系统简单模拟数据库
  4. MySQL主从复制中的“show slave status”详细含义
  5. 上栗县委副书记李志猛一行调研红谷滩区·高通中国·影创联合创新中心
  6. 打印和预览功能兼容IE、谷歌、火狐,解决IE打印只显示第一页
  7. Python | 获取本机IP地址的几种方式
  8. “香港科大-汇川技术” 2018百万奖金国际创业大赛(BJ)——国际智能机器人【创业营+创业比赛】...
  9. 华硕台式机 安装 centos7 遇到的各种问题
  10. Vulnhub靶机-JIS-CTF-VulnUpload-CTF01学习