MSCOMM串口问题,当送一串数据到下位机,等待收到相应的数据,如果超时没有到就提示通信出错,怎么做到?
我没有定时器

解决方案 »

  1.   

    你在串口线的上口机做传输质量控制不可以解决么
    发送完数据后,等待一段时间(可以采用延时),然后在mscomm中侦听数据,受到数据后发消息给主控程序,在规定时间没有受到mscomm消息,则通信失败,采取下一步动作,是重发还是丢包处理
      

  2.   

    不是自己已经很明白了吗?
    发包--延时--读数据--
    IF 没读到 THEN  报超时!
      

  3.   

    大家帮我看看我这个处理过程,是否合理呢?
    procedure TForm1.MSCommComm(Sender: TObject);
    var
     ReciveStr:string;
     vtmp,ovTmp:variant;
     i,iReceived:Integer;
     bTmp:Byte;
     s:String;begin
     case mscomm.CommEvent of
        comEvReceive:
        begin
         mscomm.InputMode:=comInputModeBinary;
         iReceived:=mscomm.InBufferCount;
         ovtmp:=mscomm.Input;
         vtmp:=VarArrayCreate([0,iReceived],varbyte);
         vtmp:=ovtmp   ;
         s:='';
         for i:=0 to iReceived-1 do
         begin
            btmp:=vtmp[i];
            //s:=s+chr(bTmp)                      //字符接收   else
            s:=s+inttohex(ord(chr(bTmp)),2);     //16进制接收
         end;
         //开始判断收到的字符进行下一步的处理
         if (s='06')and(conn=1) then    //握手成功
           begin
            mscomm.Output:=char(pp[0]);
            conn:=2;
           end else     //发送06联机
        if (length(s)=16) and (s[1]+s[2]='50') then        //'5032313037F00000'
         begin
         mscomm.Output:=char(ReceiveData[0]);
         conn:=3;
         end else     //发送收取数据信息
         if(s='06')and(conn=3) then
         begin
         read_writedata;
         inc(Addr_int);
         end else
        // if (length(s)=24)and() then
        end;
     comEventRxParity:
     begin
     end;
     comEvSend:
     begin
     end; comEventBreak: showmessage('comEventBreak');// 1001 接收到中断信号
     comEventCTSTO:showmessage('comEventCTSTO');// 1002 Clear-to-send 超时
     comEventDSRTO:showmessage('comEventDSRTO');// 1003 Data-set ready 超时
     comEventFrame:showmessage('comEventFrame');// 1004 帧错误
     comEventOverrun:showmessage('comEventOverrun');// 1006 端口超速
     comEventCDTO:showmessage('comEventCDTO');// 1007 Carrier detect 超时
     comEventRxOver:showmessage('comEventRxOver');// 1008 接收缓冲区溢出
     comEventRxParity:showmessage('comEventRxParity');// 1009 Parity 错误
     comEventTxFull:showmessage('comEventTxFull');// 1010 传输缓冲区满
     comEventDCB:showmessage('comEventDCB');// 1011 检索端口 设备控制块 (DCB) 时的意外错误end;
    end;
    还有呀,我想在实现以下数据交换过程请大家指教:
       send:02 12 12 12 12 12 08 12
    receive:06
       send:02
    receive:02 33 31 30 37 12 12 12
       send:06
    receive:06
       send:52 00 00 08
    receuve:57 00 00 08 12 45 45 45 ff ff ff ff 
       send:06
    receive:06
    ....
    ....
    //////////////////////////
    但是我现在设计的收发过程是这样子的:
       send:02 12 12 12 12 12 08 12
    receive:06
       send:02
    receive:02 33 31 30 37 12 12 12
       send:06
    receive:06
       send:52 00 00 08
    receive:57 00 00 08 12 45 45 45    //注意这里出问题
    receive:ff ff ff ff                //注意这里出错 
       send:06
    receive:06
    ....
    ....
    我要怎么重新设置参数呢?谢谢
      

  4.   

    newfang(传说中的MIC):
    不是自己已经很明白了吗?
    发包--延时--读数据--
    IF 没读到 THEN  报超时!
    --------------------------------
    老大我想知道的就是你说的:IF 没读到 THEN  报超时!、这句话中的“没读到,”具体怎么表达?
    在线等呀