mscomm在delphi怎样发送和接受大于128的数据呢?
我要接受/发送下位机的字节类型数据,但是大于128,
怎样接受发送?

解决方案 »

  1.   

    我也是想問:是数据长度还是 值啊?
    數據長度是沒有問題的!至于值, Byte本來就是0..255,有啊, 用十六進制發送方式就可發送
      

  2.   

    procedure TFormMain.ReadCommByte();
    //Description : read a byte of data from comm when every call.
    //  this function used by callthread.
    //Date : 2002.07.09
    var
      vTmp:variant;
      CodeSize:Integer;
      Code:Byte;
    begin
      StatusBar1.Panels[1].Text:='';
      CodeSize:=MsCommCall.InBufferCount;
      if CodeSize>0 then begin
        vTmp:=VarArrayCreate([0,CodeSize-1],varByte);
        vTmp:=MsCommCall.Input;
        Code:=vTmp[CodeSize-1];
      end
      else begin
        Code:=C_None;
      end;
      AThreadCall.SetBackCode(Code);
      case Code of
      C_Idle:StatusBar1.Panels[0].Text:=Translate('C_Idle','Idle');
      C_Succ:StatusBar1.Panels[0].Text:=Translate('C_Succ','Succ');
      C_Err:StatusBar1.Panels[0].Text:=Translate('C_Err','Err');
      C_None:StatusBar1.Panels[0].Text:=Translate('C_None','None');
      else StatusBar1.Panels[0].Text:=Translate('C_Unk','UnkCode %xH',[Code]);
      end;
    end;procedure TFormMain.SendIdleCode();
    //Description : send the idle code to the comm,
    //  this function used by callthread
    //Date : 2002.02.24
    var
      vTmp:variant;
    begin
      if not MsCommCall.PortOpen then begin
        AddLog(Translate('IdleError','Comm closed when send idle code!'),false);
        exit;
      end;
      vTmp:=VarArrayCreate([0,0],varByte);
      vTmp[0]:=Byte(0);//the code is 0x00h
      MsCommCall.Output:=vTmp;
      StatusBar1.Panels[1].Text:=Translate('Idle','Idle');
    end;