VC ++窗体中的System :: IO :: Ports [英] System::IO::Ports in VC++ windows forms

查看:96
本文介绍了VC ++窗体中的System :: IO :: Ports的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我遇到从串口发送/接收数据的问题。



我有一个字符串Hello World。



我使用



Hi all

I face a problem to sending/receiving data from serial port.

I have a string "Hello World".

I use

//at sending part
array<byte>^ sbyte = Encoding::ASCII -> GetBytes("€‚ƒ‰Š");
this -> serialPort1 -> Write(sbyte, 0, sbyte -> Length);

//receiving part
String^ cipher = this -> serialPort1 -> ReadLine;
array<byte>^ rbyte = this -> serialPort1 -> Read(cipher, 0, cipher -> Length);





从上面的代码,我不能收到任何字节。



我想做的主要事情是

1)从字符串中获取字节其中包含扩展的ASCII。

2)以字节形式发送

3)以字节形式接收



我发现如果我直接发送字符串形式的扩展ASCII,接收器无法确定它并出来?????。

有任何其他方法可以确保扩展的ASCII可以发送并正确收到?



提前谢谢谁可以帮助我...



From above code, i cant receive any byte.

the main thing i would like to do is
1) Get Byte from a String which contain extended ASCII.
2) send in byte form
3) receive in byte form

I discovered if i straight send extended ASCII in string form, the receiver can''t determine it and come out "?????".
Got any other way to make sure the extended ASCII can send and receive properly?

Thanks in advance who can help me...

推荐答案

你正在使用编码:: ASCII [ ^ ]。这将用问号字符替换所有非ASCII字符(最高位集)。



您可以按原样发送字符而不进行任何转换。如果您的数据使用某种文本编码,则发送方和接收方必须使用相同的编码。或者,在发送之前将文本转换为您定义的编码或单独提供编码,以便接收方可以在必要时进行转换。



术语扩展ASCII '确实具有误导性,应该避免(另见维基百科 [ ^ ])。
You are using Encoding::ASCII[^]. This will replace all non ASCII characters (highest bit set) by a question mark character.

You may send the characters as they are without performing any conversion. If your data use some kind of text encoding, sender and receiver must use the same encoding. Alternatively convert the text before sending to an encoding defined by you or provide the encoding separately so that the receiver can convert it if necessary.

The term ''Extended ASCII'' is really misleading and should be avoided (see also in the Wikipedia[^]).


这篇关于VC ++窗体中的System :: IO :: Ports的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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