请大侠帮我看看这段串口发送数据的程序
我现在用串口控件来做,具体发送程序如下,请大侠看看有没有问题啊,多谢了!
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;
}