如何在COM设备(串口)中使用unicode [英] How to using unicode in COM Device( Serial Port )

查看:149
本文介绍了如何在COM设备(串口)中使用unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
如何在终端屏幕上编写unicode?你能帮我吗?非常感谢.........
我正在使用串行端口类,并且我有serialPort.Write(ê").但这会在最终屏幕上显示一个字符Ω:D

Hi every body,
How to write unicode on teminal screen? Can you help me, please? tks all so much.........
I''m using Serial Port class and i have serialPort.Write("ê"). But it show to teminal screen a charater Ω :D

推荐答案

这不是我们可以简单回答的问题:甚至不可能.

如果您的意思是说您有一个终端,例如通过串行端口(RS232或类似端口)连接到您的PC的VDT(诸如VT220之类的哑终端设备),那么它将完全取决于终端本身可以显示,以及您如何告诉它执行此操作.我不知道没有使用Unicode的终端机(哎呀,我不知道他们还是在制作VDT!)-我那天他们都使用ASCII,这可能会为您的问题提供解决方案.
而不是将数据作为字符串发送到终端,而是将其作为字节数组发送,并使用ASCII编码而不是Unicode:
This isn''t a question we can answer simply: it may not even be possible.

If you mean that you have a terminal as in a VDT (a dumb terminal device such as a VT220, or similar) connected to your PC via a serial port (RS232 or similar) then it is going to depend on exactly what the terminal itself can display, and exactly how you tell it to do that. I know of no terminal that uses Unicode (heck, I didn''t know they still made VDTs!) - they all used ASCII in my day, which may present a solution to your problem.
Instead of sending your data to the terminal as a string, send it as a byte array instead, and use ASCII encoding instead of Unicode:
string s = "Hello!\r\n'être et avoir' is a French documentary, made in 2002";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(s);
mySerialPort.Write(bytes, 0, bytes.Length);

我不保证它将对您需要的所有字符都有效,但是它代表了更好的机会!

I don''t guarantee it will work for all characters you need, but it stands a better chance!


这篇关于如何在COM设备(串口)中使用unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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