通过串口延长器延长串口通讯,使用串口助手可以接收到数据,而我自己写的程序却不可以

清风树下 2010-10-28 09:45:19
通过串口延长器延长串口通讯,使用串口助手可以接收到数据,而我自己写的程序却不可以,接收到的数据是不完整的,,,,谁能帮帮我!!!谢谢大家了

我的接收数据和发送数据部份代码。

定义:
public SerialPort SeriaP;//串口连接
SeriaP = new SerialPort(PostName, baudRate, parity, DataBits, stopBits);
public System.Timers.Timer CTimer = new System.Timers.Timer();//实时监控连接的状态
this.SeriaP.ReadBufferSize = 2048;
this.CTimer.Interval = 1000;
this.CTimer.AutoReset = true;
this.CTimer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);


发送数据部份:
/// <summary>
/// 发送字符串数据
/// </summary>
/// <param name="StrTxt">发送数据</param>
public void Send(string StrTxt)
{
try
{
if (this.IsConn)
{
//this.SeriaP.WriteLine(StrTxt);
this.SeriaP.Write(StrTxt);
}
else
{
throw (new Exception("发送信息时连接异常断开"));
}
}
catch (Exception Ex)
{
//出错处理
}
}

接收数据:
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
if (this.IsConn) //串口是否打开 true为打开
{
int Int = 0;
Int = this.SeriaP.BytesToRead;
if (Int > 0)
{
this.ClientDTConnect = DateTime.Now;
byte[] Byte = new byte[Int];
this.SeriaP.Read(Byte, 0, Int);
this.DataVoid(Byte);//数据处理
}
}
}
catch ()
{}
}




...全文
243 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
清风树下 2011-03-03
  • 打赏
  • 举报
回复
问题解决,,谢谢各位
兔子-顾问 2010-10-28
  • 打赏
  • 举报
回复
你试试我博客中第一篇或第二篇中的工具是否可以收到?如果可以,你直接看文章和源码了解一下?
http://blog.csdn.net/wuyazhe/category/695097.aspx

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧