我的代码无法识别我从微控制器发送的一些字符 [英] My code can not recognize some characters that I sent from microcontroller

查看:56
本文介绍了我的代码无法识别我从微控制器发送的一些字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我的名字是Josev,我是这里的新手。



我正在努力用visual studio(C#)构建接收程序来接收我的微控制器的数据。我的PC通过USB连接到XBee并通过COM端口读取数据。来自微控制器的字符串数据已使用aes128加密。但是我的电脑无法识别某些字符,从而导致解密过程失败。这里有一些我的数据示例:



实际数据:@ A1 @ 3.2 @ 4.5 @(字符串)

从我的micro发送的数据: »Ë?IUU ?? ?? 3AR A * \?

我的电脑收到的数据:??????? 3ar ?? * \?



有些字符无法识别并成为?

我使用ReadLine()读取COM端口并将其捕获到字符串中像这样的变量。

Hi all, my name is Josev and I'm a newbie here.

I'm working to build receiver program with visual studio (C#) to receive data from my microcontroller. My PC connected to XBee via USB and read the data through COM port. The string data from microcontroller has been encrypted using aes128. But some characters can't be recognized by my PC, resulting in decrypting process failure. Here some example of my data :

real data : @A1@3.2@4.5@ (string)
data sent from my micro : »ËÌùû˜3ar€å*\
data received by my pc : ??????3ar??*\

Some characters can't be recognized and become "?"
I use ReadLine() to read COM port and catch it in string variable like this.

String data = ComPort.ReadLine();



但是当我通过在我的复选框上打印它来检查它时,一些字符变成?。我在这个链接中截取了一个屏幕截图。



请真的需要帮助。


But when I check it by print it on my checkbox, some characters become "?". I took a screenshot in this link.

Please, really need help.

推荐答案

停止尝试将其作为字符串接收,并且将其作为字节数据取而代之:可能是来自微控制器的数据不是Unocode,ReadLine方法会认为它是。



因此将其读作字节,看看你得到了什么值 - 并看看uController应该发送什么 - 很可能它不是直接人类可读的...

https://msdn.microsoft.com/en-us/library/ms143549(v=vs .110).aspx [ ^ ]可能会有所帮助。
Stop trying to receive it as a string, and fetch it as byte data instead: the chances are that the data from the microcontroller isn't Unocode, which the ReadLine method will assume it is.

So read it as bytes, and look at what values you are getting - and look at what the uController is supposed to be sending - chances are it isn't meant to be directly human readable...
https://msdn.microsoft.com/en-us/library/ms143549(v=vs.110).aspx[^] may help.


这篇关于我的代码无法识别我从微控制器发送的一些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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