⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adport.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      Result := TFlowControlState(Pred(CheckException(Self,
        ValidDispatcher.HWFlowState)));                            
      if Result = fcOff then
        Result := TFlowControlState(Pred(CheckException(Self,
          Dispatcher.SWFlowState)));
    end else begin
      Result := fcOff;
    end;
  end;

  procedure TApdCustomComPort.SetSWFlowOptions(const NewOpts : TSWFlowOptions);
  var
    Opts : Word;
  begin
    if (FSWFlowOptions <> NewOpts) or Force then begin
      if NewOpts = swfBoth then
        Opts := sfTransmitFlow + sfReceiveFlow
      else if NewOpts = swfTransmit then
        Opts := sfTransmitFlow
      else if NewOpts = swfReceive then
        Opts := sfReceiveFlow
      else
        Opts := 0;

      {Validate bufferfull and bufferresume if opts not zero}
      if Opts <> 0 then begin
        if (BufferFull = 0) or (BufferFull > InSize) then
          FBufferFull := Trunc(InSize * 0.75);
        if (BufferResume = 0) or (BufferResume > BufferFull) then
          FBufferResume := Trunc(InSize * 0.25);
      end;

      if (PortState = psOpen) then begin
        if Opts <> 0 then
          CheckException(Self,
            Dispatcher.SWFlowEnable(FBufferFull, FBufferResume, Opts))
        else
          CheckException(Self, Dispatcher.SWFlowDisable);
      end;
      FSWFlowOptions := NewOpts;
    end;
  end;

  procedure TApdCustomComPort.SetXonChar(const NewChar : Char);
    {-Set new xon character}
  begin
    if (NewChar <> FXOnChar) or Force then begin
      FXOnChar := NewChar;
      if (PortState = psOpen) then
        CheckException(Self, Dispatcher.SWFlowChars(FXOnChar, FXOffChar));
    end;
  end;

  procedure TApdCustomComPort.SetXoffChar(const NewChar : Char);
    {-Set new xoff character}
  begin
    if (NewChar <> FXOffChar) or Force then begin
      FXOffChar := NewChar;
      if (PortState = psOpen) then
        CheckException(Self, Dispatcher.SWFlowChars(FXOnChar, FXOffChar));
    end;
  end;

  procedure TApdCustomComPort.SetBufferFull(const NewFull : Word);
    {-Set buffer full mark}
  var
    SaveForce : Boolean;
  begin
    if (NewFull <> FBufferFull) or Force then begin
      if NewFull <= InSize then
        FBufferFull := NewFull
      else
        FBufferFull := Trunc(NewFull * 0.9);
      SaveForce := Force;
      Force := True;
      SetHWFlowOptions(HWFlowOptions);
      SetSWFlowOptions(SWFlowOptions);
      Force := SaveForce;
    end;
  end;

  procedure TApdCustomComPort.SetBufferResume(const NewResume : Word);
    {-Set buffer resume mark}
  var
    SaveForce : Boolean;
  begin
    if (NewResume <> FBufferResume) or Force then begin
      if NewResume > FBufferFull then
        FBufferResume := Trunc(FBufferFull * 0.1)
      else
        FBufferResume := NewResume;
      SaveForce := Force;
      Force := True;
      SetHWFlowOptions(HWFlowOptions);
      SetSWFlowOptions(SWFlowOptions);
      Force := SaveForce;
    end;
  end;

  procedure TApdCustomComPort.SetDTR(const NewDTR : Boolean);
    {-Set a new DTR value}
  begin
    if (NewDTR <> FDTR) or Force then begin
      if (PortState = psOpen) then begin
        if CheckException(Self, Dispatcher.SetDTR(NewDTR)) = ecOK then
          FDTR := NewDTR;
      end else begin
        FDTR := NewDTR;
      end;
    end;
  end;

  procedure TApdCustomComPort.SetRTS(const NewRTS : Boolean);
    {-Set new RTS value}
  begin
    if (NewRTS <> FRTS) or Force then begin
      if (PortState = psOpen) then begin
        if CheckException(Self, Dispatcher.SetRTS(NewRTS)) = ecOK then
          FRTS := NewRTS;
      end else begin
        FRTS := NewRTS;
      end;
    end;
  end;

  procedure TApdCustomComPort.SetOnTrigger(const Value : TTriggerEvent);
  begin
    FOnTrigger := Value;
    UpdateHandlerFlag;
  end;

  procedure TApdCustomComPort.SetOnTriggerAvail(const Value : TTriggerAvailEvent);
  begin
    FOnTriggerAvail := Value;
    UpdateHandlerFlag;
  end;

  procedure TApdCustomComPort.SetOnTriggerData(const Value : TTriggerDataEvent);
  begin
    FOnTriggerData := Value;
    UpdateHandlerFlag;
  end;

  procedure TApdCustomComPort.SetOnTriggerStatus(const Value : TTriggerStatusEvent);
  begin
    FOnTriggerStatus := Value;
    UpdateHandlerFlag;
  end;

  procedure TApdCustomComPort.SetOnTriggerTimer(const Value : TTriggerTimerEvent);
  begin
    FOnTriggerTimer := Value;
    UpdateHandlerFlag;
  end;

  procedure TApdCustomComPort.SetOnTriggerLineError(const Value : TTriggerLineErrorEvent);
  begin
    FOnTriggerLineError := Value;
    UpdateHandlerFlag;
  end;

  procedure TApdCustomComPort.SetOnTriggerModemStatus(const Value : TNotifyEvent);
  begin
    FOnTriggerModemStatus := Value;
    UpdateHandlerFlag;
  end;

  procedure TApdCustomComPort.SetOnTriggerOutbuffFree(const Value : TNotifyEvent);
  begin
    FOnTriggerOutbuffFree := Value;
    UpdateHandlerFlag;
  end;

  procedure TApdCustomComPort.SetOnTriggerOutbuffUsed(const Value : TNotifyEvent);
  begin
    FOnTriggerOutbuffUsed := Value;
    UpdateHandlerFlag;
  end;

  procedure TApdCustomComPort.SetOnTriggerOutSent(const Value : TNotifyEvent);
  begin
    FOnTriggerOutSent := Value;
    UpdateHandlerFlag;
  end;

  function TApdCustomComPort.GetDispatcher : TApdBaseDispatcher;
    {-Return the current Dispatcher, opening the port if necessary}
  begin
    if FDispatcher = nil then
      if not (csDesigning in ComponentState) then begin
        if (PortState <> psOpen) and
            (not (csLoading in ComponentState)) and
            AutoOpen then
          Open := True;
      end;
    Result := FDispatcher;
  end;

  function TApdCustomComPort.GetModemStatus : Byte;
    {-Return the current modem status register value}
  begin
    if (PortState = psShuttingDown) then
      Result := 0
    else
      Result := ValidDispatcher.GetModemStatus;
  end;

  function TApdCustomComPort.GetDSR : Boolean;
    {-Return the DSR bit state}
  begin
    if (PortState = psOpen) then
      Result := Dispatcher.CheckDSR
    else
      Result := False;
  end;

  function TApdCustomComPort.GetCTS : Boolean;
    {-Return CTS bit state}
  begin
    if (PortState = psOpen) then
      Result := Dispatcher.CheckCTS
    else
      Result := False;
  end;

  function TApdCustomComPort.GetRI : Boolean;
    {-Return RI bit state}
  begin
    if (PortState = psOpen) then
      Result := Dispatcher.CheckRI
    else
      Result := False;
  end;

  function TApdCustomComPort.GetDCD : Boolean;
    {-Return DCD bit state}
  begin
    if (PortState = psOpen) then
      Result := Dispatcher.CheckDCD
    else
      Result := False;
  end;

  function TApdCustomComPort.GetDeltaDSR : Boolean;
    {-Return delta DSR bit state}
  begin
    if (PortState = psOpen) then
      Result := Dispatcher.CheckDeltaDSR
    else
      Result := False;
  end;

  function TApdCustomComPort.GetDeltaCTS : Boolean;
    {-Return delta CTS bit state}
  begin
    if (PortState = psOpen) then
      Result := Dispatcher.CheckDeltaCTS
    else
      Result := False;
  end;

  function TApdCustomComPort.GetDeltaRI : Boolean;
    {-Return delta RI bit state}
  begin
    if (PortState = psOpen) then
      Result := Dispatcher.CheckDeltaRI
    else
      Result := False;
  end;

  function TApdCustomComPort.GetDeltaDCD : Boolean;
    {-Return delta DCD bit state}
  begin
    if (PortState = psOpen) then
      Result := Dispatcher.CheckDeltaDCD
    else
      Result := False;
  end;

  function TApdCustomComPort.GetLineError : Word;
    {-Return most severe current line error}
  begin
    if (PortState = psOpen) then
      Result := Word(CheckException(Self, Word(Dispatcher.GetLineError)))
    else
      Result := leNoError;
  end;

  function TApdCustomComPort.GetLineBreak : Boolean;
    {-Return True if break received}
  begin
    if (PortState = psOpen) then
      Result := Dispatcher.CheckLineBreak
    else
      Result := False;
  end;

  procedure TApdCustomComPort.SetTriggerLength(const NewLength : Word);
    {-Change the length trigger}
  begin
    if (FTriggerLength <> NewLength) or Force then begin
      FTriggerLength := NewLength;
      if (PortState = psOpen) then                                  
        Dispatcher.ChangeLengthTrigger(NewLength);
    end;
  end;

  function TApdCustomComPort.GetInBuffUsed : Word;
    {-Return the number of used bytes in the input buffer}
  begin
    if (PortState = psOpen) then                                     
      Result := Dispatcher.InBuffUsed
    else
      Result := 0;
  end;

  function TApdCustomComPort.GetInBuffFree : Word;
    {-Return amount of freespace in inbuf}
  begin
    if (PortState = psOpen) then                                     
      Result := Dispatcher.InBuffFree
    else
      Result := DispatchBufferSize;                                  
  end;

  function TApdCustomComPort.GetOutBuffUsed : Word;
    {-Return number of used bytes in output buffer}
  begin
    if (PortState = psOpen) then                                     
      Result := Dispatcher.OutBuffUsed
    else
      Result := 0;
  end;

  function TApdCustomComPort.GetOutBuffFree : Word;
    {-Return amount of free space in outbuff}
  begin
    if (PortState = psOpen) then                                   
      Result := Dispatcher.OutBuffFree
    else
      Result := FOutSize;
  end;

  procedure TApdCustomComPort.SetUseMSRShadow(NewUse : Boolean);
    {-Set the MSR shadow option}
  begin
    { UseMSRShadow is only applicable to 16-bit, ignore it }
  end;

  procedure TApdCustomComPort.SetUseEventWord(NewUse : Boolean);
    {-Set the UseEventWord option}
  begin
    if (FUseEventWord <> NewUse) or Force then begin
      FUseEventWord := NewUse;
      if (PortState = psOpen) then
        if FUseEventWord then
          Dispatcher.OptionsOn(poUseEventWord)
        else
          Dispatcher.OptionsOff(poUseEventWord);
    end;
  end;

  procedure TApdCustomComPort.SetCommNotificationLevel(NewLevel : Word);
    {-Set the comm notification level}
  begin
    { 16-bit }
    if (FCommNotificationLevel <> NewLevel) or Force then begin
      FCommNotificationLevel := NewLevel;
    end;
  end;

  procedure TApdCustomComPort.SetRS485Mode(NewMode : Boolean);
    {-Set the RS485 mode}
  var
    NewFlowOpts : THWFlowOptionSet;
  begin
    if (FRS485Mode <> NewMode) or Force then begin
      FRS485Mode := NewMode;
      if (PortState = psOpen) then
        Dispatcher.SetRS485Mode(NewMode);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -