资源简介

C#开发的串口调试助手,和网上的窗口调试助手功能类似,附源码,可供参考,再vs2005下可以把源码拷贝过去,稍加修改即可

资源截图

代码片段和文件信息

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.IO.Ports;
using Microsoft.Win32;
using System.Threading;

namespace SerialPort_Assistant
{
    public partial class Form1 : SerialPort_Form.SerialPort_Form
    {
        SerialPort serialPort;
        System.Timers.Timer timerSendAuto;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            cbComList.DataSource = GetComList();
            cbBaudRateList.DataSource = GetRautBitsList();
            cbParityList.DataSource = GetParityList();
            cbDataBitsList.DataSource = GetDataBitsList();
            cbStopBitsList.DataSource = GetStopBitsList();
        }
        private void Form1_FormClosing(object sender FormClosingEventArgs e)
        {
            if (serialPort != null)
                if (serialPort.IsOpen)//处于打开状态
                {
                    serialPort.Close();
                    serialPort = null;
                }
            if (timerSendAuto != null)
            {
                timerSendAuto.Close();
                timerSendAuto.Dispose();
            }
        }
        //信号灯
        private void picComState_Paint(object sender PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Brush brush;
            if (serialPort == null)
                brush = Brushes.Red;
            else if (serialPort.IsOpen)
                brush = Brushes.Green;
            else
                brush = Brushes.Red;
            g.FillEllipse(brush e.ClipRectangle);
        }
        //打开、关闭串口
        private void btnComOpen_Click(object sender EventArgs e)
        {
            if (serialPort == null)
            {
                serialPort = new SerialPort();
                serialPort.RtsEnable = true;
                serialPort.ReceivedBytesThreshold = 1;
                serialPort.ErrorReceived+=new SerialErrorReceivedEventHandler(serialPort_ErrorReceived);
                serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);
            }
            if (serialPort.IsOpen)//处于打开状态
            {
                serialPort.Close();
                if (timerSendAuto != null)
                    timerSendAuto.Stop();
            }
            else
            {
                try
                {
                    serialPort.PortName = cbComList.Text.Trim();
                    serialPort.BaudRate = int.Parse(cbBaudRateList.Text);
                    serialPort.Parity = (Parity)Enum.Parse(typeof(Parity) cbParityList.Text);
                    serialPort.DataBits = int.Parse(cbDataBitsList.Text);
                    serialPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits) cbStopBitsLi

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        144  2011-01-21 21:34  SerialPort_Assistant\app.config

     文件      10284  2011-03-11 10:27  SerialPort_Assistant\Form1.cs

     文件      19068  2011-01-28 16:43  SerialPort_Assistant\Form1.Designer.cs

     文件       5817  2011-01-28 16:43  SerialPort_Assistant\Form1.resx

     文件      18753  2011-01-28 16:43  SerialPort_Assistant\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6326  2011-03-11 10:27  SerialPort_Assistant\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        408  2011-01-28 16:44  SerialPort_Assistant\obj\x86\Debug\GenerateResource.read.1.tlog

     文件        966  2011-01-28 16:44  SerialPort_Assistant\obj\x86\Debug\GenerateResource.write.1.tlog

     文件      10114  2011-03-10 22:07  SerialPort_Assistant\obj\x86\Debug\ResolveAssemblyReference.cache

     文件       1963  2011-03-11 10:29  SerialPort_Assistant\obj\x86\Debug\SerialPort_Assistant.csproj.FileListAbsolute.txt

     文件      20992  2011-03-11 10:27  SerialPort_Assistant\obj\x86\Debug\SerialPort_Assistant.exe

     文件        180  2011-01-28 16:44  SerialPort_Assistant\obj\x86\Debug\SerialPort_Assistant.Form1.resources

     文件      40448  2011-03-11 10:27  SerialPort_Assistant\obj\x86\Debug\SerialPort_Assistant.pdb

     文件        180  2011-01-28 16:44  SerialPort_Assistant\obj\x86\Debug\SerialPort_Assistant.Properties.Resources.resources

     文件       4608  2011-01-21 21:38  SerialPort_Assistant\obj\x86\Debug\TempPE\Properties.Resources.Designer.cs.dll

     目录          0  2011-04-10 16:13  SerialPort_Assistant\obj\x86\Debug\TempPE

     目录          0  2011-04-10 16:13  SerialPort_Assistant\obj\x86\Debug

     目录          0  2011-04-10 16:13  SerialPort_Assistant\obj\x86

     目录          0  2011-04-10 16:13  SerialPort_Assistant\obj

     文件        501  2011-01-21 21:14  SerialPort_Assistant\Program.cs

     文件       1390  2011-01-21 21:14  SerialPort_Assistant\Properties\AssemblyInfo.cs

     文件       2876  2011-01-21 21:34  SerialPort_Assistant\Properties\Resources.Designer.cs

     文件       5612  2011-01-21 21:14  SerialPort_Assistant\Properties\Resources.resx

     文件       1116  2011-01-21 21:34  SerialPort_Assistant\Properties\Settings.Designer.cs

     文件        249  2011-01-21 21:14  SerialPort_Assistant\Properties\Settings.settings

     目录          0  2011-04-10 16:13  SerialPort_Assistant\Properties

     文件       4012  2011-01-21 21:51  SerialPort_Assistant\SerialPort_Assistant.csproj

     目录          0  2011-04-10 16:13  SerialPort_Assistant

----------- ---------  ---------- -----  ----

               156007                    28

............此处省略1个文件信息

评论

共有 条评论