串口问题

lianzy 2006-10-31 12:47:10
1) 数据通信波特率4800
2) 电脑通信方式为异步通信
3) 数据格式:
1. 一位为启动位
2. 八位为数据位
3. 若干位为停止位(至少一位)
4) 若电脑PC机接到数据C(43H),PC机必须回送六位密码的单片机


第四点是什么意思呢,看不懂,程序该怎么写
...全文
134 3 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
兔子-顾问 2006-10-31
  • 打赏
  • 举报
回复
InitComPort里,加上这一行
com.RTSEnable = true;
删掉上面的没用的函数:
private void com_OnComm(object sender, EventArgs e)
{
//if (com.InBufferCount > 0) ProcessComData((string)com.Input);
//string indata = (string)com.Input;
//rtfTerminal.AppendText(indata + "\n");
}
lianzy 2006-10-31
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace YD_AD_Client
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
InitComPort();
//com.Output = "Serial Terminal Initialized";
}

private void Form4_Load(object sender, EventArgs e)
{
}

private void com_OnComm(object sender, EventArgs e)
{
//if (com.InBufferCount > 0) ProcessComData((string)com.Input);
//string indata = (string)com.Input;
//rtfTerminal.AppendText(indata + "\n");
}

private void InitComPort()
{
// Set the com port to be 1
com.CommPort = 1;

// This port is already open, close it to reset it.
if (com.PortOpen) com.PortOpen = false;

// Trigger the OnComm event whenever data is received
com.RThreshold = 1;

// Set the port to 9600 baud, no parity bit, 8 data bits, 1 stop bit (all standard)
com.Settings = "4800,n,8,1";

// Force the DTR line high, used sometimes to hang up modems
com.DTREnable = true;

// No handshaking is used
com.Handshaking = MSCommLib.HandshakeConstants.comNone;

// Don't mess with byte arrays, only works with simple data (characters A-Z and numbers)
com.InputMode = MSCommLib.InputModeConstants.comInputModeText;

// Use this line instead for byte array input, best for most communications
//com.InputMode = MSCommLib.InputModeConstants.comInputModeText;

// Read the entire waiting data when com.Input is used
com.InputLen = 0;

// Don't discard nulls, 0x00 is a useful byte
com.NullDiscard = false;

// Attach the event handler
com.OnComm += new System.EventHandler(this.OnComm);

// Open the com port
com.PortOpen = true;
}
private void OnComm(object sender, EventArgs e) // MSCommLib OnComm Event Handler
{
// If data is waiting in the buffer, process it.
// Note: This is using the string method for simple data, be sure
// to use byte arrays (described below) for more generic data.
if (com.InBufferCount > 0) ProcessComData((string)com.Input);
}

private void ProcessComData(string input)
{
// Send incoming data to a Rich Text Box
rtfTerminal.AppendText(input + "\n");
}

}
}

不知道是什么原因,上面的代码没有接收到什么信号。
色郎中 2006-10-31
  • 打赏
  • 举报
回复
PC 端 接受数据啊
如果 是C 那就回6个字节的 密码数据给MCU 就ok了啊

相关推荐
发帖
C#

10.8w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
帖子事件
创建了帖子
2006-10-31 12:47
社区公告

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