最近打算用c#做点实事,原来一直都在用串口调试,打算开发一种结合securt的串口保存机制及传统调试助手的便携串口配置模式的软件。今天发出第一个版本,这段时间慢慢积累打算把这个软件网上起来。
今天解决了串口关闭问题,及串口接收16进制显示的问题。
由于这里不能放置源代码压缩包。
源代码我放在百度云盘及115网盘了,大家可以下载试用,并提报告意见:
http://pan.baidu.com/share/link?shareid=3114178268&uk=588847378
源代码见如下链接
http://115.com/lb/5lbdpjgwemqt
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.Collections;
using System.IO.Ports;
using System.Threading;
namespace ComAssistant1
{
public partial class Form1 : Form
{
public enum LogMsgType { Incoming, Outgoing, Normal, Warning, Error };
public enum DataMode { Text, Hex }
private Color[] LogMsgTypeColor = { Color.Orange, Color.Green, Color.Black, Color.Blue, Color.Red };
/// 准备关闭串口=true
/// </summary>
private bool m_IsTryToClosePort = false;
/// <summary>
/// true表示正在接收数据
/// </summary>
private bool m_IsReceiving = false;
public Form1()
{
InitializeComponent();
}
Mutex m_Mutex = null;//锁
bool flag;
private void Form1_Load(object sender, EventArgs e)
{
//判断串口打开或关闭
if (serialPort1.IsOpen)
{
serialPort1.Close();
pictureBox1.Image = Image.FromFile("E:\\C#\\图标\\PNG\\20091007130906335.png");
}
else
{
pictureBox1.Image = Image.FromFile("E:\\C#\\图标\\PNG\\20091007130902885.png");
}
RefrespictureBox1();
int ii = 0;
foreach (string s in SerialPort.GetPortNames())
{
if (ii >= 1)
{
comboBox1.Items.Add(s);
}
ii++;
}
if (SerialPort.GetPortNames().Length != 0)
{
comboBox1.Text = (string)comboBox1.Items[0];
}
string[] ss = new string[] { "9600", "19200", "57600", "115200" };
comboBox2.DataSource = ss;
comboBox3.DataSource = Enum.GetNames(typeof(Parity));
ss = new string[] { "5", "6", "7", "8" };
comboBox4.DataSource = ss;
comboBox4.Text = "8";
comboBox5.DataSource = Enum.GetNames(typeof(StopBits));
comboBox5.Text = Enum.Format(typeof(StopBits), StopBits.One, "G");