将波斯字符串写到C#中的串行端口? [英] write persian string to serial port in c#?

查看:65
本文介绍了将波斯字符串写到C#中的串行端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我将波斯字符写到串行端口,但是在DataRecieved中,我得到了其他字符,例如?等.
如何将波斯语字符串写到串行端口并以波斯语形式接收.

hello.
I write Persian characters to serial port but in DataRecieved I get other characters like ?, etc.
How can I write Persian string to serial port and receive it as Persian.

推荐答案

^ ]方法是有关该函数使用的编码的说明.
In the documentation of the Write[^] method is a remark about the encoding used by the function.
默认情况下,SerialPort使用ASCIIEncoding对字符进行编码. ASCIIEncoding将大于127的所有字符编码为(char)63或?".要支持该范围内的其他字符,请将Encoding设置为UTF8Encoding,UTF32Encoding或UnicodeEncoding.
By default, SerialPort uses ASCIIEncoding to encode the characters. ASCIIEncoding encodes all characters greater then 127 as (char)63 or ''?''. To support additional characters in that range, set Encoding to UTF8Encoding, UTF32Encoding, or UnicodeEncoding.


因此,编码使您的字节变得混乱,如前所述,大于127的任何字节都将被char(63)''?''替换.

尝试使用其他编码.


So the encoding is messing up your bytes, as stated any byte larger than 127 is replaced by char(63) ''?''.

Try using a different encoding.


这篇关于将波斯字符串写到C#中的串行端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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