VS2013下串口数据char型转COleVariant问题

来源:互联网 发布:斐波那契数列c语言for 编辑:程序博客网 时间:2024/06/16 09:46

在串口需要发送一串字符数组buf[]时,COleVariant(buf)强制转换失效(在vc6.0环境中是允许的)。在VS2013环境下需要借助CByteArray类型进行中间的装换,实现代码如下:

首先定义:CByteArray m_array ;

将char型数组中的数值赋值到 m_array

  for (int i = 0; i < 26; i++)
m_array[i] = sbuf[i]; 

m_ctrlComm.put_Output(COleVariant(m_array));

最后使用串口输出函数将需发送的数据发送出去。


原创粉丝点击