Recent

Author Topic: list of serial ports in combobox  (Read 17099 times)

luk2009

  • Jr. Member
  • **
  • Posts: 51
list of serial ports in combobox
« on: February 02, 2017, 02:07:57 am »
Hi

In Delphi
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2.  var
  3.  reg:  TRegistry;
  4.  I:Integer;
  5. begin
  6.    Reg := TRegistry.Create;
  7.   try
  8.     Reg.RootKey := HKEY_LOCAL_MACHINE;
  9.     if Reg.OpenKey('HARDWARE\DEVICEMAP\SERIALCOMM', false) then
  10.     begin
  11.       Reg.GetValueNames(ComboBox1.Items);
  12.       for I := 0 to ComboBox1.Items.Count - 1 do
  13.           ComboBox1.Items[i] := Reg.ReadString(ComboBox1.Items[i]);
  14.     end;
  15.     ComboBox1.Sorted := true;
  16.   finally
  17.     Reg.Free;
  18.   end;
  19. end;  

How Can I do this on lazarus?



molly

  • Hero Member
  • *****
  • Posts: 2330
Re: list of serial ports in combobox
« Reply #1 on: February 02, 2017, 02:26:24 am »

Paul Breneman

  • Sr. Member
  • ****
  • Posts: 290
    • Control Pascal
Re: list of serial ports in combobox
« Reply #2 on: February 02, 2017, 03:16:42 am »
How Can I do this on lazarus?

You might take a look at the bottom of the SynaSer.pas unit (that unit lists the ports in Windows and Linux) here: www.CtrlTerm.com
Regards,
Paul Breneman
www.ControlPascal.com

luk2009

  • Jr. Member
  • **
  • Posts: 51
Re: list of serial ports in combobox
« Reply #3 on: February 02, 2017, 03:46:40 am »
How Can I do this on lazarus?

You might take a look at the bottom of the SynaSer.pas unit (that unit lists the ports in Windows and Linux) here: www.CtrlTerm.com

thanks Paul

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   ports : string;
  4.  
  5. begin
  6.   ports := GetSerialPortNames;
  7.   ComboBox1.Items.Add(ports);
  8.  
  9. end;    
« Last Edit: February 02, 2017, 04:04:57 am by luk2009 »

luk2009

  • Jr. Member
  • **
  • Posts: 51
Re: list of serial ports in combobox
« Reply #4 on: February 02, 2017, 04:01:48 am »
How Can I do this on lazarus?
(Almost) exactly the same:)

Thanks molly
uses   .....  registry;
Code: Pascal  [Select][+][-]
  1. var
  2. I:integer;
  3. reg:tregistry;
  4.  
  5. begin
  6.    Reg := TRegistry.Create;
  7.   try
  8.     Reg.RootKey := HKEY_LOCAL_MACHINE;
  9.     if Reg.OpenKeyReadOnly('HARDWARE\DEVICEMAP\SERIALCOMM') then
  10.     begin
  11.       Reg.GetValueNames(ComboBox1.Items);
  12.       for I := 0 to ComboBox1.Items.Count - 1 do
  13.           ComboBox1.Items[i] := Reg.ReadString(ComboBox1.Items[i]);
  14.     end;
  15.     ComboBox1.Sorted := true;
  16.   finally
  17.     Reg.Free;
  18.   end;              
« Last Edit: February 02, 2017, 04:04:29 am by luk2009 »

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: list of serial ports in combobox
« Reply #5 on: February 02, 2017, 05:11:21 am »
@luk2009,
Excellent  :)

Thank you for posting your answers. Great spirit that allows others to learn from  :-*

uses   .....  registry;
For the life of me i can't remember what we had to use for delphi to use the registry.... does it matter ? nope !  :D

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1272
Re: list of serial ports in combobox
« Reply #6 on: February 02, 2017, 06:28:32 am »
hello,
with the Tlazserial component, you have a  form for settings of the serial port. In this form, you can choose your port from a combobox filled with the serial ports of your system (see attachment). You can try the sertest example of the component to see how this works.
in this form To list the serial port in the combobox , the function    GetSerialPortNames of synaser is used like this :
Code: Pascal  [Select][+][-]
  1. ComComboBox1.Items.CommaText :=  GetSerialPortNames();  

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

luk2009

  • Jr. Member
  • **
  • Posts: 51
Re: list of serial ports in combobox
« Reply #7 on: February 02, 2017, 06:34:08 pm »
jurassic

thanks for the info

That seems a better way to do it.

The answers that I put were for tests

Stan17

  • Newbie
  • Posts: 6
Re: list of serial ports in combobox
« Reply #8 on: April 06, 2017, 12:24:01 pm »
hello,
with the Tlazserial component, you have a  form for settings of the serial port. In this form, you can choose your port from a combobox filled with the serial ports of your system (see attachment). You can try the sertest example of the component to see how this works.
in this form To list the serial port in the combobox , the function    GetSerialPortNames of synaser is used like this :
Code: Pascal  [Select][+][-]
  1. ComComboBox1.Items.CommaText :=  GetSerialPortNames();  

Friendly, J.P
When there is no COM ports available, it still shows COM1 :(

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: list of serial ports in combobox
« Reply #9 on: April 06, 2017, 12:36:21 pm »
When there is no COM ports available, it still shows COM1 :(
I'm guessing - but from a solid technical background - that although you may not have a physical Com port outlet on the back of your PC there is one on the motherboard  -  just waiting for a cable to be attached.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12314
  • FPC developer.
Re: list of serial ports in combobox
« Reply #10 on: April 06, 2017, 01:06:00 pm »
See also http://stackoverflow.com/questions/16100798/serial-com-ports-name-or-identification

Virtual comports of webcams touchscreens and the like make it sometimes difficult, specially on laptops.

 

TinyPortal © 2005-2018