1) 数据通信波特率4800
2) 电脑通信方式为异步通信
3) 数据格式:
1. 一位为启动位
2. 八位为数据位
3. 若干位为停止位(至少一位)
4) 若电脑PC机接到数据C(43H),PC机必须回送六位密码的单片机
第四点是什么意思呢,看不懂,程序该怎么写
2) 电脑通信方式为异步通信
3) 数据格式:
1. 一位为启动位
2. 八位为数据位
3. 若干位为停止位(至少一位)
4) 若电脑PC机接到数据C(43H),PC机必须回送六位密码的单片机
第四点是什么意思呢,看不懂,程序该怎么写
如果 是C 那就回6个字节的 密码数据给MCU 就ok了啊
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");
} }
}不知道是什么原因,上面的代码没有接收到什么信号。
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");
}