Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13

    Problem using Asyncpro AdxPort.pas form


    I am having a small problem using the standard from provided with AsyncPro for setting the port options. Although I can get the window to open none of the current settings are shown and none of the available ports are shown. If I set up a tapi device and use the show config dialog, it does not show any of the direct comports. Can you Async pro guys point me in the right direction. please find following.

    Main Form
    Code:
    unit datacollex;
    
    interface
    
    uses
      ShareMem, Memcheck, Windows, Messages, SysUtils, Variants, Classes, Graphics, 
    Controls, ............., OoMisc, AdPort, AdStMach, AdTapi, AdPacket;
    
    type
      TMainForm = class(TForm)
        MainMenu1: TMainMenu;
        SerialPortSettings1: TMenuItem;
        ...................................
        ApdTapiDevice1: TApdTapiDevice;
        ApdComPort1: TApdComPort;
        ApdDataPacket1: TApdDataPacket;
    
    implementation
       uses 
       AdxPort;
    
    procedure TMainForm.SerialPortSettings1Click(Sender: TObject);
    begin
    ApdTapiDevice1.ShowConfigDialog;
    end;
    and AdxPort form sorry about how long it is.

    Code:
    unit AdXPort;
    
    interface
    
    uses
      WinTypes,
      WinProcs,
      ....................
      StdCtrls,
      datacollex,
      AdPort,
      AdTapi,
      AdTSel;
    
    type
      TComPortOptions = class(TForm)
        FlowControlBox: TGroupBox;
        Label1: TLabel;
        Label2: TLabel;
        DTRRTS: TCheckBox;
        RTSCTS: TCheckBox;
        SoftwareXmit: TCheckBox;
        SoftwareRcv: TCheckBox;
        Edit1: TEdit;
        Edit2: TEdit;
        Bauds: TRadioGroup;
        Paritys: TRadioGroup;
        Databits: TRadioGroup;
        Stopbits: TRadioGroup;
        Comports: TGroupBox;
        OK: TButton;
        Cancel: TButton;
        PortComboBox: TComboBox;
        procedure OKClick(Sender: TObject);
        procedure CancelClick(Sender: TObject);
        procedure PortComboBoxChange(Sender: TObject);
        procedure FormShow(Sender: TObject);
    
      private
        FShowTapiDevices : Boolean;
        FShowPorts       : Boolean;
        ApdComPort1   : TApdComPort;
        FTapiDevice: string;
        Executed   : Boolean;
    
      protected
        function GetComPort : TApdComPort;
        procedure SetComPort(NewPort : TApdComPort);
    
      public
        //constructor Create(AOwner: TComponent); override;
        //destructor Destroy; override;
        function Execute: Boolean;
    
        property ComPort : TApdComPort
          read GetComPort write SetComPort;
        property TapiDevice : string
          read FTapiDevice write FTapiDevice;
        property ShowTapiDevices : Boolean
          read FShowTapiDevices write FShowTapiDevices;
        property ShowPorts : Boolean
          read FShowPorts write FShowPorts;
      end;
    
    var
      ComPortOptions: TComPortOptions;
    
    implementation
    
    {$R *.DFM}
    
    const
      BaudValues : array[0..9] of Word =
        (30, 60, 120, 240, 480, 960, 1920, 3840, 5760, 11520);
    
    
    
    function TComPortOptions.Execute: Boolean;
    var
      I : Word;
      CheckBaud : Word;
      E : TDeviceSelectionForm;
    begin
      {Update dialog controls}
      Bauds.ItemIndex := 6;
      CheckBaud := ApdComPort1.Baud div 10;
      for I := 0 to 9 do
        if CheckBaud = BaudValues[I] then begin
          Bauds.ItemIndex := I;
          break;
        end;
      Paritys.ItemIndex := Ord(ApdComPort1.Parity);
      Databits.ItemIndex := 8-ApdComPort1.Databits;
      Stopbits.ItemIndex := Pred(ApdComPort1.StopBits);
    
      {Hardware flow}
      DTRRTS.Checked := hwfUseDTR in ApdComPort1.HWFlowOptions;
      RTSCTS.Checked := hwfUseRTS in ApdComPort1.HWFlowOptions;
    
      {Software flow}
      SoftwareXmit.Checked := (ApdComPort1.SWFlowOptions = swfBoth) or
                              (ApdComPort1.SWFlowOptions = swfTransmit);
      SoftwareRcv.Checked := (ApdComPort1.SWFlowOptions = swfBoth) or
                             (ApdComPort1.SWFlowOptions  = swfReceive);
      Edit1.Text := IntToStr(Ord(ApdComPort1.XOnChar));
      Edit2.Text := IntToStr(Ord(ApdComPort1.XOffChar));
    
      {Gather all tapi devices and ports}
      E := TDeviceSelectionForm.Create(Self);
      try
              E.ShowTapiDevices := ShowTapiDevices;
        E.ShowPorts       := ShowPorts;
        E.EnumAllPorts;
        PortComboBox.Items := E.PortItemList;
      finally;
        E.Free;
      end;
    
      ShowModal;
      Result := ModalResult = mrOK;
      Executed := Result;
    end;
    
    function TComPortOptions.GetComPort : TApdComPort;
    var
      HWOpts : THWFlowOptionSet;
      SWOpts : TSWFlowOptions;
      Temp   : Integer;
      Code   : Integer;
    begin
      if Executed then begin
        {Update ComPort from dialog controls}
        ApdComPort1.Baud := LongInt(BaudValues[Bauds.ItemIndex]) * 10;
        ApdComPort1.Parity := TParity(Paritys.ItemIndex);
        ApdComPort1.Databits := 8-Databits.ItemIndex;
        ApdComPort1.Stopbits := Succ(Stopbits.ItemIndex);
    
        {Update HW flow}
        HWOpts := [];
        if DTRRTS.Checked then
          HWOpts := [hwfUseDTR, hwfRequireDSR];
        if RTSCTS.Checked then begin
          Include(HWOpts, hwfUseRTS);
          Include(HWOpts, hwfRequireCTS);
        end;
        ApdComPort1.HWFlowOptions := HWOpts;
    
        {Update SW flow}
        if SoftwareXmit.Checked then
          if SoftwareRcv.Checked then
            SWOpts := swfBoth
          else
            SWOpts := swfTransmit
        else if SoftwareRcv.Checked then
          SWOpts := swfReceive
        else
          SWOpts := swfNone;
        ApdComPort1.SWFlowOptions := SWOpts;
    
        Val(Edit1.Text, Temp, Code);
        if Code = 0 then
          ApdComPort1.XOnChar := Char(Temp);
        Val(Edit2.Text, Temp, Code);
        if Code = 0 then
          ApdComPort1.XOffChar := Char(Temp);
      end;
      Result := ApdComPort1;
    end;
    
    procedure TComPortOptions.SetComPort(NewPort : TApdComPort);
    begin
      if (NewPort <> ApdComPort1) then
        ApdComPort1.Assign(NewPort);
    end;
    
    procedure TComPortOptions.OKClick(Sender: TObject);
    begin
      ModalResult := mrOK;
    end;
    
    procedure TComPortOptions.CancelClick(Sender: TObject);
    begin
      ModalResult := mrCancel;
    end;
    
    procedure TComPortOptions.PortComboBoxChange(Sender: TObject);
    var
      DeviceName : string;
    begin
      DeviceName := PortComboBox.Items[PortComboBox.ItemIndex];
      if Pos(DirectTo, DeviceName) > 0 then begin
        ComPort.TapiMode := tmOff;
        ComPort.ComNumber := StrToInt(Copy(DeviceName, Length(DirectTo)+1, Length(DeviceName)));
      end else begin
        ComPort.TapiMode := tmAuto;
        ComPort.ComNumber := 0;
        TapiDevice := DeviceName;
      end;
    end;
    
    procedure TComPortOptions.FormShow(Sender: TObject);
    begin
     { Highlite the active device in the list }
      with PortComboBox do
        if Assigned(ApdComPort1) and (ComPort.TapiMode = tmOff) then begin
          ItemIndex := Items.IndexOf(DirectTo+IntToStr(ComPort.ComNumber));
        end else begin
          ItemIndex := Items.IndexOf(TapiDevice);
        end;
    end;
    
    end.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    I can now select a port using ApdTapiDevice1.SelectDevice; but how do I go about configuring the selected port? There seems to be no form for this. if so what is the best way to share the settings for the component between two forms.
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    I think it would be simplier if I could get to the component properties on the main page. I believe the settings in the windows generated dialog do not work except for baud rate.

    If I could do something like the following in the dialog from
    Edit1.text := IntToStr(ApdcomPort1.baud);


    Where ApdComPort1 is the asyncpro component on the main form, that would be great. I dont know if this is some type of inheritance thing, but a pointer in the right direction would help.
  8. #5
  9. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    Ah, that's easy enough then.

    Let's say you have form1 and form2, where form2 has the dialog box. Let's say there's a button on form1 that says "config...". First, I would remove Form2 from the list of autocreated forms on startup (Project --> Options --> Forms tab). Here's how I'd do the code:
    Code:
    --- On unit1
    implementation
    
    uses unit2;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
    	form2 : TForm2;
    begin
    	form2 := TForm2.Create(self);
    	form2.Parent := self;
    	form2.PrepareDisplay;
    	form2.ShowModal;
    	form2.free;
    end;
    
    
    ---- Then on unit2:
    type
    	TForm2 = class(TForm)
    		Label1: TLabel;
    
    	private
    		{ Private declarations }
    	public
    		{ Public declarations }
    		procedure PrepareDisplay;
    	end;
    
    var
    	Form2: TForm2;
    
    implementation
    
    uses Unit1;
    
    {$R *.dfm}
    
    procedure TForm2.PrepareDisplay;
    var
    	parentform : TForm1;
    begin
    	parentform := self.parent as TForm1;
    	label1.Caption := IntToStr(parentform.ApdComPort1.baud);
    end;
    Hope this helps
    Last edited by Scorpions4ever; January 26th, 2004 at 09:58 PM.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    Scorpions,
    Thanks, it seem to work without to much problem. I had to comment out one line as it was causing problems and so ended up with the following.

    Code:
    procedure TMainForm.Portsettings1Click(Sender: TObject);
    Var
      PortSetupMain: TPortSetupMain;
    begin
         PortSetupMain := TPortSetupMain.Create(self);
         try
    	//PortSetupMain.Parent := self;
    	PortSetupMain.PrepareDisplay;
    	PortSetupMain.ShowModal;
            finally
    	PortSetupMain.free;
         end
    end;
    What will be the implication if I do not use that line?
  12. #7
  13. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    What error are you getting when you try to set the value of PortSetupMain.Parent? I explicitly set it so that PrepareDisplay could access the parent form (i.e. MainForm) by using the Parent property.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    The error I get is 'Cannot focus a disabled or invisiblw window' when I click on the button to open the dialog window.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    Now the trick is getting the changes back into the component? I unashamedly nick most of the component names fron the async pro dialog and usefd the following to populate the dialog form. I now need to translate all of these back to the component.

    Code:
    procedure TPortSetupMain.PrepareDisplay;
    var
              I : Word;
              CheckBaud : Word;
         parentform : TMainForm;
    begin
         parentform := self.parent as TMainForm;
    
              Bauds.ItemIndex := 6;
      CheckBaud := MainForm.ApdComPort1.Baud div 10;
      for I := 0 to 9 do
        if CheckBaud = BaudValues[I] then begin
          Bauds.ItemIndex := I;
          break;
        end;
    
        {Hardware flow}
      DTRRTS.Checked := hwfUseDTR in MainForm.ApdComPort1.HWFlowOptions;
      RTSCTS.Checked := hwfUseRTS in MainForm.ApdComPort1.HWFlowOptions;
    
        {Software flow}
      SoftwareXmit.Checked := (MainForm.ApdComPort1.SWFlowOptions = swfBoth) or
                              (MainForm.ApdComPort1.SWFlowOptions = swfTransmit);
      SoftwareRcv.Checked := (MainForm.ApdComPort1.SWFlowOptions = swfBoth) or
                             (MainForm.ApdComPort1.SWFlowOptions  = swfReceive);
      Edit1.Text := IntToStr(Ord(MainForm.ApdComPort1.XOnChar));
      Edit2.Text := IntToStr(Ord(MainForm.ApdComPort1.XOffChar));
    
      Paritys.ItemIndex := Ord(MainForm.ApdComPort1.Parity);
      Databits.ItemIndex := 8-MainForm.ApdComPort1.Databits;
      Stopbits.ItemIndex := Pred(MainForm.ApdComPort1.Stopbits);
    
          label3.Caption := IntToStr(MainForm.ApdComPort1.DataBits);
    
    end;
  18. #10
  19. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    That's easy to do too. All you have to do is reverse the logic of PrepareDisplay. Assuming you have an Ok button in TPortSetupMain, something like this ought to do the trick:
    Code:
    procedure TPortSetupMain.OkButtonClick(Sender : TObject);
    begin
        ProcessSettings;
        Close;
    end;
    
    procedure TPortSetupMain.ProcessSettings;
    var
         parentform : TMainForm;
    begin
         parentform := self.parent as TMainForm;
         parentform.ApdComPort1.XOnCharend := Edit1.Text;
         ...
    end;
    BTW I noticed in PrepareDisplay, you're referring to the mainform components as Mainform.ApdComPort1.xxx instead of parentform.ApdComPort1.xxx, even though you went to the trouble of assiging parentform and typecasting it correctly. Is there a good reason for this?
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    That was a mistake and did throw up an hint in delphi so I deleted it. Should I leave it in? The form is actually called mainform.
  22. #12
  23. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    >> That was a mistake and did throw up an hint in delphi so I deleted it. Should I leave it in?
    Only if you're using parentform to refer to the components on the main form. i.e. instead of doing this:
    Code:
              Bauds.ItemIndex := 6;
      CheckBaud := MainForm.ApdComPort1.Baud div 10;
    I would do this:
    Code:
    parentform := self.parent as TMainForm;
       Bauds.ItemIndex := 6;
      CheckBaud := parentform.ApdComPort1.Baud div 10;
    Of course, to use the above, you would need to uncomment the //PortSetupMain.Parent := self; in TMainForm, so that the Parent is set up correctly. Your call here .
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    I'll give it a go.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    Tried again. Same error as before.
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    Sorry, the best I could do was:

    Code:
    procedure TPortSetupMain.ProcessSettings;
    
    begin
    
         MainForm.ApdComPort1.Open := False;
         DelayTicks.Enabled := True;
      
         MainForm.ApdComPort1.Baud := LongInt(BaudValues[Bauds.ItemIndex]) * 10;
    
         MainForm.ApdComPort1.Open := True;
         DelayTicks.Enabled := False;
         end;
    but it seem to work.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo