请大侠帮我看看这段串口发送数据的程序

angusr 2003-08-22 04:29:23
我现在用串口控件来做,具体发送程序如下,请大侠看看有没有问题啊,多谢了!


void CSTransDlg::OnTransmit()
{
// TODO: Add your control notification handler code here
CFile Trafile;
long nLength;
VARIANT varBLOB;
BYTE* pbuf;

if(0 == Trafile.Open(m_TraPath,CFile::modeRead))
return;
TRACE("trace 打开发送文件%s",m_TraPath);

nLength = Trafile.GetLength();
TRACE("trace 发送文件%s的大小为%d",m_TraPath,nLength);

pbuf = new BYTE[nLength+2];

if(pbuf==NULL)
return; // Memory allocate error
Trafile.Seek( 0, CFile::begin );
UINT nBytesRead=Trafile.Read(pbuf,nLength); //read the file into memory

//Build a SAFEARRAY;
SAFEARRAY* psa;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = nLength;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);

for (long i = 0; i < nLength; i++)
SafeArrayPutElement(psa, &i, pbuf++); //read the file into memory

TRACE("trace 输出字符总长度=%d",nLength);
varBLOB.vt = VT_ARRAY | VT_UI1;

varBLOB.parray = psa;
m_ComPort.SetOutput(varBLOB); //send out the data
delete pbuf;

}
...全文
58 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
AthlonxpX86 2003-08-22
  • 打赏
  • 举报
回复
真懒,自己试试不就知道了,自己写的东西自己还最清楚?

2,640

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧