mscomm 怎么收不到数据 (急,在线等)
发送代码
if (Form1->MSComm->PortOpen ==false)
{
Form1->MSComm->PortOpen =true;
}
int send[12]={0xcc,0x1,2,3,4,5,6,7,8,9,10,11};
OleVariant VarBuff;
int n=12;
VarBuff=VarArrayCreate(OPENARRAY(int,(0,n)),varByte); //注意 int,(0,n-1)) 不应为 int,(0,n))
for (int i=0;i<n;i++)
{
VarBuff.PutElement(send[i],i);
}
Form1->MSComm->Output =VarBuff;
接收代码
if (MSComm->CommEvent==comEvReceive) //接收缓冲区中收到Rthreshold(可设置的属性值)个字符
{
OleVariant RxBuff;
try
{
RxBuff=Form1->MSComm->Input;
if (Form1->MSComm->InBufferCount==12) // 收到 InBufferCount为0????
{
for (int i=0;i<Form1->MSComm->InBufferCount;i++)
{
buff[i]=RxBuff.GetElement(i);
}
Disp();
}
}
catch(Exception &exception)
{
ShowMessage("对不起,数据传输过程中出现错误!");
}
}