你可以使用MsComm控件,是由微软提供的activex控件。可以在ActiveX的控件选项中添加。

解决方案 »

  1.   

    我的朋友在c++builder中使用过一个串口读写控件,我想肯定有的。
    下面是一段读写的代码:主程序中收发数据
    void __fastcall TMainForm::fashu()
    {
        //TODO: Add your source code here
            int i;
            Comm1->Write(fahuan,m_nCount);
            while(1){
                    i=Comm1->OutQueCount();
                    if(i==0)
                            break;
            }
    }
    void __fastcall TMainForm::jieshu()
    {
        //TODO: Add your source code here
        //TODO: Add your source code here
            int nLen,k,i,nTimeOver,nCountTemp,nRetry=0;
            bool bTm,bOver,bGroupOver=false;
            unsigned char buf[1024];
            nCountTemp=m_nCount;
            while(!bOver){
                    bTm=false;
                    bOver=false;
                    m_nCount=0;
                    nTimeOver=0;
                    bGroupOver=false;
                    while(!bGroupOver){
                            nLen=Comm1->InQueCount();
                            if(nLen>0){
                                    nTimeOver=0;
                                    k=Comm1->Read(buf,512);
                                    for(i=0;i<k;i++){
                                            jiehuan[m_nCount]=buf[i];
                                            =f((jiehuan[m_nCount]==0xff)&&(bTm==false)){
                                                    bOver=true;
                                                    return;
                                            }
                                            =f((bTm==false)&&(jiehuan[m_nCount]==touming)){
                                                    bTm=true;
                                                    continue;
                                            }
                                            m_nCount++;
                                            bTm=false;
                                    }
                            }
                            else{
                                    Sleep(1000);
                                    nTimeOver++;
                                    if(nTimeOver>5){
                                            bGroupOver=true;
                                    }
                            }
                    }
                    nRetry++;
                    if(nRetry>=3){
                            bOver=true;
                    }
                    else{
                            m_nCount=nCountTemp;
                            fashu();
                    }
            }
    }