C#编写串口助手,实现串口的收发,实现十六进制的收发。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 896 2017-10-23 12:11 CHCH.sln
文件 43008 2017-10-28 15:38 CHCH.v11.suo
目录 0 2017-10-25 21:10 CHCH
文件 766 2017-10-25 21:10 CHCH2.ico
文件 766 2017-10-25 21:04 CHCH3.ico
文件 187 2017-10-23 12:11 CHCHApp.config
目录 0 2017-10-24 21:44 CHCHin
目录 0 2017-10-25 21:10 CHCHinDebug
文件 11776 2017-10-25 21:10 CHCHinDebugAxInterop.MSCommLib.dll
文件 53760 2017-10-25 21:10 CHCHinDebugAxInterop.WMPLib.dll
文件 141312 2017-10-27 14:28 CHCHinDebugCH.exe
文件 187 2017-10-23 12:11 CHCHinDebugCH.exe.config
文件 36352 2017-10-27 14:28 CHCHinDebugCH.pdb
文件 22984 2017-10-28 14:07 CHCHinDebugCH.vshost.exe
文件 187 2017-10-23 12:11 CHCHinDebugCH.vshost.exe.config
文件 490 2016-03-09 13:48 CHCHinDebugCH.vshost.exe.manifest
文件 18432 2017-10-25 21:10 CHCHinDebugInterop.MSCommLib.dll
文件 331264 2017-10-25 21:10 CHCHinDebugInterop.WMPLib.dll
目录 0 2017-10-25 21:10 CHCHinDebugsq-AL
文件 4608 2017-10-27 14:28 CHCHinDebugsq-ALCH.resources.dll
目录 0 2017-10-24 21:44 CHCHinRelease
文件 11776 2017-10-24 21:44 CHCHinReleaseAxInterop.MSCommLib.dll
文件 53760 2017-10-24 21:44 CHCHinReleaseAxInterop.WMPLib.dll
文件 140800 2017-10-25 20:17 CHCHinReleaseCH.exe
文件 187 2017-10-23 12:11 CHCHinReleaseCH.exe.config
文件 34304 2017-10-25 20:17 CHCHinReleaseCH.pdb
文件 22984 2017-10-25 20:20 CHCHinReleaseCH.vshost.exe
文件 187 2017-10-23 12:11 CHCHinReleaseCH.vshost.exe.config
文件 490 2016-03-09 13:48 CHCHinReleaseCH.vshost.exe.manifest
文件 18432 2017-10-24 21:44 CHCHinReleaseInterop.MSCommLib.dll
文件 331264 2017-10-24 21:44 CHCHinReleaseInterop.WMPLib.dll
............此处省略66个文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace CH
{
public partial class COMForm : Form
{
int a = 0;
int b = 0;//计算发送数据位数
string data;//
string checkBox2_data;//
public COMForm()
{
InitializeComponent();
}
private void axMSComm1_OnComm(object sender EventArgs e)
{
}
private void label1_Click(object sender EventArgs e)
{
}
private void timer1_Tick(object sender EventArgs e)
{
}
private void TextReceive_TextChanged(object sender EventArgs e)
{
}
private void TextSend_TextChanged(object sender EventArgs e)
{
}
//获取串口列表初始化
private void COMForm_Load(object sender EventArgs e)
{
//查询到串口号然后显示到列表里
string[] array = System.IO.Ports.SerialPort.GetPortNames();
for (int i = 0; i < array.Length; ++i)
{
string name = array[i];
comboBox1.Items.Add(name);
}
//在下拉控件上面显示
comboBox1.Text = comboBox1.Items[0].ToString();
comboBox2.Text = comboBox2.Items[2].ToString();
comboBox3.Text = comboBox3.Items[0].ToString();
comboBox4.Text = comboBox4.Items[0].ToString();
checkBox1.Checked =false;
checkBox(TextReceive.Text);
}
//退出按钮
private void CmdClosed_Click(object sender EventArgs e)
{
serialPort1.Close();
Close();
}
//发送数据按钮
private void CmdSend_Click(object sender EventArgs e)
{
string outdata = TextSend.Text;
byte[] byteArray =new byte[outdata.Length] ;
int i = outdata.Length;
if (button1.Text == “打开串口“)
{
MessageBox.Show(“请打开串口“);
}
else if (outdata == ““)
{
MessageBox.Show(“发送数据不能为空“);
}
else
{
if (checkBox2.Checked == true)
{
//协议:长度加数据
//int s = outdata.Length/2;
//if (s.ToString().Length%2==1)
// outdata = s.ToString().PadLeft(s.ToString().Length+1‘0‘) + outdata;
//else
// outdata = s.ToString().PadLeft(s.ToString().Length ‘0‘) + outdata;
byteArray = strToToHexByte(outdata.Replace(“ “ ““));
serialPort1.Write(byteArray 0 (outdata.Length) / 2);
a = a + o
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 896 2017-10-23 12:11 CHCH.sln
文件 43008 2017-10-28 15:38 CHCH.v11.suo
目录 0 2017-10-25 21:10 CHCH
文件 766 2017-10-25 21:10 CHCH2.ico
文件 766 2017-10-25 21:04 CHCH3.ico
文件 187 2017-10-23 12:11 CHCHApp.config
目录 0 2017-10-24 21:44 CHCHin
目录 0 2017-10-25 21:10 CHCHinDebug
文件 11776 2017-10-25 21:10 CHCHinDebugAxInterop.MSCommLib.dll
文件 53760 2017-10-25 21:10 CHCHinDebugAxInterop.WMPLib.dll
文件 141312 2017-10-27 14:28 CHCHinDebugCH.exe
文件 187 2017-10-23 12:11 CHCHinDebugCH.exe.config
文件 36352 2017-10-27 14:28 CHCHinDebugCH.pdb
文件 22984 2017-10-28 14:07 CHCHinDebugCH.vshost.exe
文件 187 2017-10-23 12:11 CHCHinDebugCH.vshost.exe.config
文件 490 2016-03-09 13:48 CHCHinDebugCH.vshost.exe.manifest
文件 18432 2017-10-25 21:10 CHCHinDebugInterop.MSCommLib.dll
文件 331264 2017-10-25 21:10 CHCHinDebugInterop.WMPLib.dll
目录 0 2017-10-25 21:10 CHCHinDebugsq-AL
文件 4608 2017-10-27 14:28 CHCHinDebugsq-ALCH.resources.dll
目录 0 2017-10-24 21:44 CHCHinRelease
文件 11776 2017-10-24 21:44 CHCHinReleaseAxInterop.MSCommLib.dll
文件 53760 2017-10-24 21:44 CHCHinReleaseAxInterop.WMPLib.dll
文件 140800 2017-10-25 20:17 CHCHinReleaseCH.exe
文件 187 2017-10-23 12:11 CHCHinReleaseCH.exe.config
文件 34304 2017-10-25 20:17 CHCHinReleaseCH.pdb
文件 22984 2017-10-25 20:20 CHCHinReleaseCH.vshost.exe
文件 187 2017-10-23 12:11 CHCHinReleaseCH.vshost.exe.config
文件 490 2016-03-09 13:48 CHCHinReleaseCH.vshost.exe.manifest
文件 18432 2017-10-24 21:44 CHCHinReleaseInterop.MSCommLib.dll
文件 331264 2017-10-24 21:44 CHCHinReleaseInterop.WMPLib.dll
............此处省略66个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)