stm32cubemx 串口3 需要多次复位是什么原因
答案:2 悬赏:60
解决时间 2021-02-28 04:07
- 提问者网友:冷场帝
- 2021-02-27 10:58
stm32cubemx 串口3 需要多次复位是什么原因
最佳答案
- 二级知识专家网友:苦柚恕我颓废
- 2021-02-27 11:03
//创建一个串口通讯
SerialPort CurrentPort = null;
CurrentPort = new SerialPort();
CurrentPort.ReadBufferSize = 128;
CurrentPort.PortName = comName; //端口号
CurrentPort.BaudRate = bandRate; //比特率
CurrentPort.Parity =parity;//奇偶校验
CurrentPort.StopBits = stop;//停止位
CurrentPort.DataBits = databit;//数据位
CurrentPort.ReadTimeout = 1000; //读超时,即在1000内未读到数据就引起超时异常
//绑定数据接收事件,因为发送是被动的,所以你无法主动去获取别人发送的代码,只能通过这个事件来处理
CurrentPort.DataReceived += Sp_DataReceived;
CurrentPort.Open();
定义一个变量 byte[] receiveStr;
//绑定的事件处理函数
private static void Sp_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
SerialPort sp = sender as SerialPort;
if (sp == null)
return;
byte[] readBuffer = new byte[sp.ReadBufferSize];
sp.Read(readBuffer, 0, readBuffer.Length);
//赋值
receiveStr=readBuffer;//当然你可以通过转换将byte[]转换为字符串。
}
//你要求的按钮事件可以这么写
private void button1_Click(object sender, EventArgs e)
{
if(receiveStr!=null)
{
变量 xxx=receiveStr;
}
}
SerialPort CurrentPort = null;
CurrentPort = new SerialPort();
CurrentPort.ReadBufferSize = 128;
CurrentPort.PortName = comName; //端口号
CurrentPort.BaudRate = bandRate; //比特率
CurrentPort.Parity =parity;//奇偶校验
CurrentPort.StopBits = stop;//停止位
CurrentPort.DataBits = databit;//数据位
CurrentPort.ReadTimeout = 1000; //读超时,即在1000内未读到数据就引起超时异常
//绑定数据接收事件,因为发送是被动的,所以你无法主动去获取别人发送的代码,只能通过这个事件来处理
CurrentPort.DataReceived += Sp_DataReceived;
CurrentPort.Open();
定义一个变量 byte[] receiveStr;
//绑定的事件处理函数
private static void Sp_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
SerialPort sp = sender as SerialPort;
if (sp == null)
return;
byte[] readBuffer = new byte[sp.ReadBufferSize];
sp.Read(readBuffer, 0, readBuffer.Length);
//赋值
receiveStr=readBuffer;//当然你可以通过转换将byte[]转换为字符串。
}
//你要求的按钮事件可以这么写
private void button1_Click(object sender, EventArgs e)
{
if(receiveStr!=null)
{
变量 xxx=receiveStr;
}
}
全部回答
- 1楼网友:情战凌云蔡小葵
- 2021-02-27 12:27
不是中文路径,stm32cubemx路径是d:\program files\stmicroelectronics\stm32cube\stm32cubemx,mdk路径是d:\keil\uv4,我在d:\program files\stmicroelectronics\stm32cube\stm32cubemx\db\plugins\projectmanager文件夹下stm32tck.cfg文件中找到有像是ide路径的设置,将原来的“mdk-arm 1.0 c:\keil uv4\uv4.exe”改为“mdk-arm 1.0 d:\keil\uv4\uv4.exe”还是一样。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |