为了学习C#,所以,自己动手,开发了一个小小的控制台版本的串口调试助手PjComm,截图如下:
上图中的蓝色背景的字符,为热键。在使用SendData时,若串口没有打开,则自动打开。若已经打开,会暂时关闭串口。
默认的串口设置参数是com1,115200,8,1,none。
整个窗口的第0-18行为串口信息显示行,每当显示完一屏幕之后,会自动将屏幕的内容保存至文件,并清屏继续显示。
下载地址:
【电信、网通】点击下载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 line
private 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;
}