发表于:2005-06-02 15:31:00
2楼
另外,这个也不是线长短的问题,我换了不同长度的线,结果还是一样。
初始化的时候的代码:
m_comm.SetCOmmPort(1);
m_comm.SetInBufferSize(1024);
m_comm.SetOutBuferSize(512);
m_comm.SetInputMode(1);
m_comm.SetSettings(_T("9600,N,8,1"));
m_comm.SetHandshaking(1);
m_comm.SetRthreshold(1);
m_comm.SetSThreshold(1);
m_comm.SetRTSEnable(TRUE);
m_comm.SetDTREnable(TRUE);
m_comm.SetPortOpen(TRUE);
接收:
short event = m_comm.GetCommEvent();
switch(event)
{
case 2:
{
BYTE rxd;
m_strReceive.Empty();
COleariant vrd;
COldSafeArray array;
vrd.Atach(m_comm.GetInput());
array = vrd;
long len = array.GetOneDimSize();
for (long i=0; i < len && i < 1024; i++)
{
array.GetElement(&i, &rxd);
m_strReceive +=CString(rxd);
}
m_listboxReceive.InsertString(0, m_srReceive);
m_listboxReceive.SetSel(0, FALSE);
}
break;
}
}
发送:
COleVariant varOutput;
CByteArray OutBuf;
for (int i =0; i < m_strSend.GetLength(); i++)
{
OutBuf.Add(m_strSend[i]);
}
varOutput = OutBuf;
while (0 == m_comm.GetPortOpen())
{
m_comm.SetPortOpen(TRUE);
}
m_comm.SetOutput(varOutput);