串口调试助手源代码
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
using System.Thread in g.Tasks; using System.Wi ndows.Forms;
using Syste m.IO;
using Syste m.IO .Ports;
using System.Thread ing;
using DevExpress.XtraEditors;
串口调试助手预源代码
using System;
using System.Collect ion s.Ge neric; using System.Comp onen tModel;
using System.Data;
using System.Draw ing;
using System.Linq;
using System.Text;
成毫秒单位
tmSe nd.Start();//开启定时器
}
else
{
sp1.Write(StrSe nd);//写入数据
}
public Form1()
{
In itializeComp onen t();
sp1.DataReceived += sp1_DataReceived; }
private void Form1_Load(object sen der, Even tArgs e) {-
this.MaximizeBox = false;
{
case "
sp1.Parity =
break;
case "
sp1.Parity = break;
case "
参数不正确!
//
无":
波特率
数据位
停止位
", "Error");
校验位
//private void CloseSerial_Click(object sen der, Even tArgs e)
//设置各参数
stri ng strBaudRate = cbBaudRate.Text; string strDateBits = cbDataBits.Text;
string strStopBits = cbStop.Text;
sp1.BaudRate=Con vert.ToI nt32(strBaudRate);〃sp1.DataBits = Con vert.ToI nt32(strDateBi ts);〃switch (cbStop.Text)//
int StateCha nged = 0;
int StateCha nged_Ascii = 1; int StateCha nged_16 = 0;
string Temp = null;
stri ng Temp memoSe nd = n ull;
private void memoSe nd_EditValueCha nged(object sen der, Even tArgs e) {-
{
sp1.Close();
//SerialPort sp1 = new SerialPort();
if (!sp1.lsOpe n)〃串口是关闭的,设置参数,打开串口
{
try
{
//获取串口号
string serialName=cbSerial.SelectedItem.ToString();
sp1.PortName = serialName;
〃{
// if (sp1.lsOpe n)
// {
//sp1.Close();
//labSerial.Text ="串口号:” +sp1.PortName;
//labState.Text ="状 态:关闭";
//}
〃}
private void Sen d_Click(object sen der, Even tArgs e) {
SerialDataReceivedEve ntHa ndler(sp1 DataReceived); //
private void comboBoxEdit1 Selectedl ndexCha nged(objectБайду номын сангаасsen der, Even tArgs e)
private void Open Serial_Click(object sen der. Even tArgs e)
cbSerial.Properties .I tems.Add(port);
}
//串口设置默认选择项
cbSerial.Selectedl ndex = 0;
Con trol.CheckForlllegalCrossThreadCalls = false;
spl.DataReceived += new
stri ng StrSe nd = memoSe nd.Text;
if (!sp1.lsOpe n)
{
if (ckTimeSe nd.Checked
&& !(stri ng.lsNullOrEmpty(textTime.Text)))//
{
string Time = textTime.Text;
tmSe nd.l nterval = int.P arse(Time) * 1000;//时间单位是秒,化
using System.Text.RegularExpressi ons;
amespace Win dowsFormsApplicati on3
public partial class Form1:XtraForm {
SerialPort sp1 = new SerialPort(); int Flag = 0;
//检查是否有串口
stri ng[] str = SerialPort.GetPortNames();
if (str == n ull)
{
MessageBox.Show(”本机没有串口!", "error");
return;
}
//添加串口项目
foreach (stri ng port in Syste m.IO.P orts.SerialPort.GetPortNames()) {
{
case "1":
sp1.StopBits =
break;
case "1.5":
sp1.StopBits =
break;
case "2":
sp1.StopBits =
break;
default:
MessageBox.Show("Error:
break;
}
switch (cbParity.Text)
using Syste m.IO;
using Syste m.IO .Ports;
using System.Thread ing;
using DevExpress.XtraEditors;
串口调试助手预源代码
using System;
using System.Collect ion s.Ge neric; using System.Comp onen tModel;
using System.Data;
using System.Draw ing;
using System.Linq;
using System.Text;
成毫秒单位
tmSe nd.Start();//开启定时器
}
else
{
sp1.Write(StrSe nd);//写入数据
}
public Form1()
{
In itializeComp onen t();
sp1.DataReceived += sp1_DataReceived; }
private void Form1_Load(object sen der, Even tArgs e) {-
this.MaximizeBox = false;
{
case "
sp1.Parity =
break;
case "
sp1.Parity = break;
case "
参数不正确!
//
无":
波特率
数据位
停止位
", "Error");
校验位
//private void CloseSerial_Click(object sen der, Even tArgs e)
//设置各参数
stri ng strBaudRate = cbBaudRate.Text; string strDateBits = cbDataBits.Text;
string strStopBits = cbStop.Text;
sp1.BaudRate=Con vert.ToI nt32(strBaudRate);〃sp1.DataBits = Con vert.ToI nt32(strDateBi ts);〃switch (cbStop.Text)//
int StateCha nged = 0;
int StateCha nged_Ascii = 1; int StateCha nged_16 = 0;
string Temp = null;
stri ng Temp memoSe nd = n ull;
private void memoSe nd_EditValueCha nged(object sen der, Even tArgs e) {-
{
sp1.Close();
//SerialPort sp1 = new SerialPort();
if (!sp1.lsOpe n)〃串口是关闭的,设置参数,打开串口
{
try
{
//获取串口号
string serialName=cbSerial.SelectedItem.ToString();
sp1.PortName = serialName;
〃{
// if (sp1.lsOpe n)
// {
//sp1.Close();
//labSerial.Text ="串口号:” +sp1.PortName;
//labState.Text ="状 态:关闭";
//}
〃}
private void Sen d_Click(object sen der, Even tArgs e) {
SerialDataReceivedEve ntHa ndler(sp1 DataReceived); //
private void comboBoxEdit1 Selectedl ndexCha nged(objectБайду номын сангаасsen der, Even tArgs e)
private void Open Serial_Click(object sen der. Even tArgs e)
cbSerial.Properties .I tems.Add(port);
}
//串口设置默认选择项
cbSerial.Selectedl ndex = 0;
Con trol.CheckForlllegalCrossThreadCalls = false;
spl.DataReceived += new
stri ng StrSe nd = memoSe nd.Text;
if (!sp1.lsOpe n)
{
if (ckTimeSe nd.Checked
&& !(stri ng.lsNullOrEmpty(textTime.Text)))//
{
string Time = textTime.Text;
tmSe nd.l nterval = int.P arse(Time) * 1000;//时间单位是秒,化
using System.Text.RegularExpressi ons;
amespace Win dowsFormsApplicati on3
public partial class Form1:XtraForm {
SerialPort sp1 = new SerialPort(); int Flag = 0;
//检查是否有串口
stri ng[] str = SerialPort.GetPortNames();
if (str == n ull)
{
MessageBox.Show(”本机没有串口!", "error");
return;
}
//添加串口项目
foreach (stri ng port in Syste m.IO.P orts.SerialPort.GetPortNames()) {
{
case "1":
sp1.StopBits =
break;
case "1.5":
sp1.StopBits =
break;
case "2":
sp1.StopBits =
break;
default:
MessageBox.Show("Error:
break;
}
switch (cbParity.Text)