佚名通过本文主要向大家介绍了wince串口调试助手,串口调试助手,串口调试助手下载,串口调试助手使用教程,蓝牙串口调试助手等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: 用串口调试助手往wince平板上发送数字,结果自动换行是怎么回事?
描述:
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using Microsoft.VisualBasic;
using System.IO;
using System.IO.Ports;
using System.Threading;
namespace SerialPort0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void myDelegate();//这是一个委托,在串口接收事件里用到
public string i;
public int j = 1;
public int n = 0;
public int b = 0;
private void serialPort1_DataReceived_1(object sender, SerialDataReceivedEventArgs e)
//串口接收事件。默认当缓冲区有1个数据时触发此事件,可以修改COM3控件的ReceivedBytesThreshold属性修改
{
Invoke(new myDelegate(updateTextbox), new object[] { });//调用updateTextbox方法
}
public void updateTextbox()
//更新“历史数据”和“当前数据”两个Textbox的文本
{
string i = COM3.ReadExisting();//读取串口3的数据
/*textBox2.Text = i;//当前数据
textBox1.Text += i;//历史数据*/
if (n == 1)//开始写入文件
{
textBox2.Text = i;//当前数据
textBox1.Text += i;//历史数据
FileStream fs = new FileStream("\\NandFlash\\Documents and Settings\\CreateTXT\\" + this.textBox4.Text + ".txt", FileMode.Append);//建立对应的txt,如果是重复的,在原来的基础上往后写
StreamWriter sr = new StreamWriter(fs);
i = COM3.ReadExisting();//读取串口3的数据
sr.WriteLine(textBox2.Text);//写入txt
sr.Close();
fs.Close();
}
}
private void button1_Click(object sender, EventArgs e)//打开串口的按钮,对串口属性进行初始化以及打开串口
{
COM3.BaudRate = Convert.ToInt32(BaudRatebox.Text);//通过一个ComboBox控件设置波特率
COM3.Parity = Parity.None;
COM3.DataBits = 8;//数据有几位
COM3.StopBits = StopBits.One;
COM3.DiscardNull = true;//默认的
COM3.DtrEnable = false;//默认的
COM3.Encoding = Encoding.ASCII;
COM3.RtsEnable = false;//不知道 默认的
//以上是对串口属性初始化
COM3.Open();//打开串口
btnOpenSP.Enabled = false;//打开串口按钮变灰
BaudRatebox.Enabled = false;//波特率选择变灰
label1.Text = "串口已打开!";
}
private void button2_Click(object sender, EventArgs e)//关闭串口的按钮
{
COM3.Close();
timer1.Enabled = false;
timer2.Enabled = false;
btnOpenSP.Enabled = true;
label1.Text = "串口已关闭!";
// label8.Text = "保存结束!";
BaudRatebox.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
if (!COM3.IsOpen)//这个if没有意义不用写
{
&n
描述:
C#wince开发板串口调试助手
代码如下:using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using Microsoft.VisualBasic;
using System.IO;
using System.IO.Ports;
using System.Threading;
namespace SerialPort0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void myDelegate();//这是一个委托,在串口接收事件里用到
public string i;
public int j = 1;
public int n = 0;
public int b = 0;
private void serialPort1_DataReceived_1(object sender, SerialDataReceivedEventArgs e)
//串口接收事件。默认当缓冲区有1个数据时触发此事件,可以修改COM3控件的ReceivedBytesThreshold属性修改
{
Invoke(new myDelegate(updateTextbox), new object[] { });//调用updateTextbox方法
}
public void updateTextbox()
//更新“历史数据”和“当前数据”两个Textbox的文本
{
string i = COM3.ReadExisting();//读取串口3的数据
/*textBox2.Text = i;//当前数据
textBox1.Text += i;//历史数据*/
if (n == 1)//开始写入文件
{
textBox2.Text = i;//当前数据
textBox1.Text += i;//历史数据
FileStream fs = new FileStream("\\NandFlash\\Documents and Settings\\CreateTXT\\" + this.textBox4.Text + ".txt", FileMode.Append);//建立对应的txt,如果是重复的,在原来的基础上往后写
StreamWriter sr = new StreamWriter(fs);
i = COM3.ReadExisting();//读取串口3的数据
sr.WriteLine(textBox2.Text);//写入txt
sr.Close();
fs.Close();
}
}
private void button1_Click(object sender, EventArgs e)//打开串口的按钮,对串口属性进行初始化以及打开串口
{
COM3.BaudRate = Convert.ToInt32(BaudRatebox.Text);//通过一个ComboBox控件设置波特率
COM3.Parity = Parity.None;
COM3.DataBits = 8;//数据有几位
COM3.StopBits = StopBits.One;
COM3.DiscardNull = true;//默认的
COM3.DtrEnable = false;//默认的
COM3.Encoding = Encoding.ASCII;
COM3.RtsEnable = false;//不知道 默认的
//以上是对串口属性初始化
COM3.Open();//打开串口
btnOpenSP.Enabled = false;//打开串口按钮变灰
BaudRatebox.Enabled = false;//波特率选择变灰
label1.Text = "串口已打开!";
}
private void button2_Click(object sender, EventArgs e)//关闭串口的按钮
{
COM3.Close();
timer1.Enabled = false;
timer2.Enabled = false;
btnOpenSP.Enabled = true;
label1.Text = "串口已关闭!";
// label8.Text = "保存结束!";
BaudRatebox.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
if (!COM3.IsOpen)//这个if没有意义不用写
{
&n