如何在串行端口上发送和接收扩展的ASCII码 [英] how to send and receive extended ascii codes on serial port
本文介绍了如何在串行端口上发送和接收扩展的ASCII码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用vc ++ 6.0 MSCOMM进行串行通信,我必须从串行端口读取字节.
例如:
88 84 10 02(来自端口的4字节数据)
C6 1E 10 02(接收到的数据),但是我必须显示88 84,但是我正在获取C6和1E,因为88 84是我无法读取的扩展ASCII码,请帮助.
我的代码是:
Hi i am using vc++ 6.0 MSCOMM for serial communication i have to read bytes and from serial port.
example :
88 84 10 02 (4 bytes data from port)
C6 1E 10 02 (Received Data) but i have to display 88 84 but i am getting C6 and 1E because 88 84 are the extended ASCII Codes which i am unable to read please help.
my code is:
VARIANT data;
BSTR k;
static char dbuff[4];
int dcount=0;
CString data;
if(m_mscom.GetCommEvent()==2){ // Receiving data from port
data = m_mscom.GetInput();
k = data.bstrVal;
dbuff[dcount] = char (k[0]);
dcount++;
if(dcount == 4){
dcount=0;
data.Format ("%02X%02X%02X%02X",(unsigned char)dbuff[0],(unsigned char)dbuff[1],(unsigned char)dbuff[2],(unsigned char)dbuff[3]);
}
}
推荐答案
几天前,您问了一个类似的问题,并得到了 ^ ]不使用CString和char变量;您尝试过吗?
You asked a similar question a few days ago, and got the suggestion[^] to not use CString and char variables; did you try that?
data.bstrVal返回一个BSTR-16位宽的utf-16
这是什么:dbuff [dcount] = char(k [0]);
我将其读取为:dbuff [0] = char(k [0]);您正在将一个字节大小的char设置为分配给k的BSTR中第一个unicode字符的8个最低有效位.
或缺少很多代码....
更新
TurboPower异步专业 [ ^ ]可以与C ++ Builder一起使用.有很多例子和好的文档.
也可以尝试 C ++ 2nd Edition中的思考 [
data.bstrVal returns a BSTR - 16-bit wide utf-16
What''s this: dbuff[dcount] = char (k[0]);
I read it as: dbuff[0] = char (k[0]); you are setting one byte sized char to the 8 least significant bits of the first unicode character in the BSTR assigned to k.
or there is a lot of code missing ....
Update
TurboPower Async Professional[^] can be used with C++ builder. There are lots of examples and good docs.
Also try Thinking in C++ 2nd Edition[^] by Bruce Eckel, Free Electronic Book
Volume 1 & Volume 2
Regards
Espen Harlinn
这篇关于如何在串行端口上发送和接收扩展的ASCII码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文