遇到串口问题了,希望高手给看看
建立了一个对话框,在OnInitDialog中添加了if(m_ctrlComm.GetPortOpen())
m_ctrlComm.SetPortOpen(FALSE);
m_ctrlComm.SetCommPort(1);
if(!m_ctrlComm.GetPortOpen())
m_ctrlComm.SetPortOpen(TRUE);
else
AfxMessageBox("cannot open serial port");
m_ctrlComm.SetSettings("9600,n,8,1");
m_ctrlComm.SetInputMode(1);
m_ctrlComm.SetRThreshold(1);
m_ctrlComm.SetInputLen(0);
m_ctrlComm.GetInput();
在OnOnCommMscomm中添加了
m_strRXData=" ";
VARIANT variant_inp;
COleSafeArray safearray_inp;
LONG len,k;
BYTE rxdata[2048];
CString strtemp;
if(m_ctrlComm.GetCommEvent()==2)
{
variant_inp=m_ctrlComm.GetInput();
safearray_inp=variant_inp;
len=safearray_inp.GetOneDimSize();
for(k=0;k<len;k++)
safearray_inp.GetElement(&k,rxdata+k);
for(k=0;k<len;k++)
{
BYTE bt=*(char*)(rxdata+k);
strtemp.Format("%c",bt);
m_strRXData+=strtemp;
}
}
UpdateData(FALSE);
可是为什么对话框中的编辑框内没有数据显示呢?