将数据发送到其他设备时,它会收到第一个字母n第4个字母 [英] When sending data to other device it receive the 1st letter n 4th letter

查看:87
本文介绍了将数据发送到其他设备时,它会收到第一个字母n第4个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发送帮助时,我收到hp但 h 12 12 l 123 p 我收到帮助,这意味着在每封信后必须有2个空格



我尝试过:



public void receiveMsg()

receivedMsgTextbox.AppendText(serialPort1.ReadExisting());

private void sendMsgTextbox_KeyPress(object sender,KeyPressEventArgs e)

byte c =(byte)e.KeyChar;

if(c == 0x0D )

c = 0x0A;

serialPort1.WriteLine(sendMsgTextbox.Text);

receiveMsg();

when sending "help" i receive "hp" but "h12e12l123p"i receive "help" which means after every letter the must be 2 space

What I have tried:

public void receiveMsg()
receivedMsgTextbox.AppendText(serialPort1.ReadExisting());
private void sendMsgTextbox_KeyPress(object sender, KeyPressEventArgs e)
byte c = (byte)e.KeyChar;
if(c == 0x0D)
c = 0x0A;
serialPort1.WriteLine(sendMsgTextbox.Text);
receiveMsg();

推荐答案

检查串口配置:可能需要调整BPC,停止位和/或奇偶校验以匹配目标硬件。



首先使用Hyperterminal这样的东西来确保你的PC和目标之间有良好的可靠通信 - 直到你可以完美地工作,你只需通过编码SerialPort代码来增加复杂性。目前,您不知道问题是否在您的最后,或者远程设备无法像您发送的那样快速处理数据。
Check your serial port configuration: it may be that you need to "tweek" the BPC, stop bits, and / or parity to match the target hardware.

Start by using something like Hyperterminal to make sure you have good solid communications between your PC and the target - until you have that provably working perfectly, you are just adding complications by coding SerialPort code. At present, you don't know if the problem is at your end or the remote device just can't cope with data as "quickly" as you are sending it.


这篇关于将数据发送到其他设备时,它会收到第一个字母n第4个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆