Pregunta

Edit: Splitting is working now and I am Converting hex in C# and not in arduino (But if anyone know conversion on arduino side I want to know the solution to convert hex to string on arduino)

I am getting data in Hex on arduino serial monitor,now I want to convert it back to String(how to do this?) and I wrote a a code for Serial Client in C# where I am receiving the data sent on COM Port & i just want the string from the data I am sending from phone but unable to Separate from that Firmware Version, Found Something! Texts (because they are also coming on COM Port), I want to display Everything in RichTextBox(that is working) but how to just the string we got for other purpose? Data coming on Serial Client is Found chip PN532 Firmware ver. 1.6 Waiting for Tap! Found Phone! 68656c6c2079656168

now I just want to use this hex no for the process ahead in serial client, So how to separate it in C#?

¿Fue útil?

Solución

To split the data and get the last line, you can simply split it at line delimiters and use Linq to get the last line;

var hex = 
  data.Split(new[] {'\n','\r'}, StringSplitOptions.RemoveEmptyEntries).Last();

Otros consejos

if your string is seperated by NewLine character you can split your String using Environment.NewLine delimeter.

Try This:

var words = str.Split(Environment.NewLine);
var hexNum = words[words.Length-1];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top