C++串口通信 5
if(m_ctrlComm.GetPortOpen())m_ctrlComm.SetPortOpen(FALSE);m_ctrlComm.SetCommPort(3);i...
if(m_ctrlComm.GetPortOpen()) m_ctrlComm.SetPortOpen(FALSE);
m_ctrlComm.SetCommPort(3);
if( !m_ctrlComm.GetPortOpen())
m_ctrlComm.SetPortOpen(TRUE);
else
AfxMessageBox("cannot open serial port");
m_ctrlComm.SetSettings("2400,n,8,1");
m_ctrlComm.SetRThreshold(1);
m_ctrlComm.SetInputLen(0);
m_ctrlComm.GetInput();
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);
UpdateData(TRUE); m_ctrlComm.SetOutput(COleVariant(m_strTXData));//发送数据
这程序中能发送数据不能接收数据 求助 展开
m_ctrlComm.SetCommPort(3);
if( !m_ctrlComm.GetPortOpen())
m_ctrlComm.SetPortOpen(TRUE);
else
AfxMessageBox("cannot open serial port");
m_ctrlComm.SetSettings("2400,n,8,1");
m_ctrlComm.SetRThreshold(1);
m_ctrlComm.SetInputLen(0);
m_ctrlComm.GetInput();
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);
UpdateData(TRUE); m_ctrlComm.SetOutput(COleVariant(m_strTXData));//发送数据
这程序中能发送数据不能接收数据 求助 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询