如何将LF和Cr添加到char数组中

如何将LF和Cr添加到char数组中

本文介绍了如何将LF和Cr添加到char数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从串口(sp)收到三个字符,它们是''abc'',我通过使用下面的代码收到它们,其中sp是串口。

I recieve three character from serial port (sp) they are ''abc'', and I received them by using the code below, where sp is the serialport.

MySrting = sp.ReadExisting();
textBox1.AppendText(MySrting);



该字符不可读,它们看起来像是方角。发送三个字符的设备没有添加换行和CR,我的意思是LF和CR



我想问题是丢失了LF和CR,我不知道知道如何将LF和Cr添加到字符串MyString



编辑:

确定我收到来自Pic微控制器的字符串我想收到abc到我的c#程序然后将该字符串存储到textbox1。但字符串变得越来越长我要清除 sp(serialport)所以我再次获得新字符串这是序列端口事件


the character are not readable, and they looks like the corner of square. The device which sent the three character did not add line feed and CR, i mean LF and CR

I guess the problem is loss of LF and CR,i do not know how to add LF and Cr to the string MyString


ok i receive the string from Pic microcontroller i want to recevied abc to my c# program then store that string to textbox1. but the string becomes longer and longer i wich to clear the sp(serialport) so i get new string again this is the serialport event

void serialPort_DataReceived(object s, SerialDataReceivedEventArgs e)
{
// str is defined somewhere else 
byte[] data = new byte[sp.BytesToRead];
sp.Read(data, 0, data.Length);
// sp.Read(data, 0, 8); 
//MessageBox.Show(data.ToString()); 
str=ByteArrayToString2(data);
MessageBox.Show(str);
}

推荐答案



这篇关于如何将LF和Cr添加到char数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:33