Recent

Author Topic: LazSerial: List of USB ports and virtual port issue  (Read 6957 times)

MoellerCLaus

  • Full Member
  • ***
  • Posts: 114
    • Vig Foreningsprogram
LazSerial: List of USB ports and virtual port issue
« on: July 13, 2021, 01:57:38 pm »
1. I am trying out LazSerial and read that "COM0" is a virtual port? If I try to open I get an error. For me virtual means you can send to it and receive the same text back. But maybe I misunderstood ::)

2. How can I get a list of avaiable USB ports on the PC? I found some examples where the registry was scanned - but did not when I tried.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: LazSerial: List of USB ports and virtual port issue
« Reply #1 on: July 13, 2021, 02:17:38 pm »
For me virtual means you can send to it and receive the same text back. But maybe I misunderstood ::)

In this context "virtual" means that there is not a real serial port behind it but some other type of hardware (e,g, a Bluetooth controller) or software simulating one.

What you describe is usually called a "loop device" and is normally a virtual, software-simulated port.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

MoellerCLaus

  • Full Member
  • ***
  • Posts: 114
    • Vig Foreningsprogram
Re: LazSerial: List of USB ports and virtual port issue
« Reply #2 on: July 13, 2021, 02:43:15 pm »
Thanks both for quick response.

Quote
if you haven't serial ports in your PC you can use virtual ports :
1 - WINDOWS
To simulate  a paired serial ports on  windows : com0com   
ex :
from LazSerial code.
Anyway I then need to communicate via 2 usb-ports on 2 PC's. My PC's has only USB-ports. USB is a bus but can LazSerial be used anyway?

@lucumar: Yes I know about the device manager. I wanted to give my users a combobox with options to select from.


Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: LazSerial: List of USB ports and virtual port issue
« Reply #3 on: July 13, 2021, 03:14:46 pm »
hello,
to see what is the COM0 port on Windows use the Device Manager.  Search for COM ports  and their properties ( see for example attachment).
With the test project coming with lazserial  (GPS simulator) package you can see the list of serial ports available :
click on the Port Settings button. In the setup window click on the Port ComboBox.
Friendly, J.P
« Last Edit: July 13, 2021, 03:38:02 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

ttomas

  • Full Member
  • ***
  • Posts: 245
Re: LazSerial: List of USB ports and virtual port issue
« Reply #4 on: July 13, 2021, 03:52:58 pm »
You will need some usb2serial device on your PC.

ttomas

  • Full Member
  • ***
  • Posts: 245
Re: LazSerial: List of USB ports and virtual port issue
« Reply #5 on: July 13, 2021, 03:57:11 pm »
For development on Windows you can use com0com virtual driver
http://com0com.sourceforge.net/
You can also use com2tcp to communicate between 2 PC in network.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: LazSerial: List of USB ports and virtual port issue
« Reply #6 on: July 13, 2021, 04:03:42 pm »
my two ports usb  RS232 serial  converter in attachment (COM10 , COM11 on my first message)
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

MoellerCLaus

  • Full Member
  • ***
  • Posts: 114
    • Vig Foreningsprogram
Re: LazSerial: List of USB ports and virtual port issue
« Reply #7 on: July 14, 2021, 08:48:58 am »
hello,
to see what is the COM0 port on Windows use the Device Manager.  Search for COM ports  and their properties ( see for example attachment).
With the test project coming with lazserial  (GPS simulator) package you can see the list of serial ports available :
click on the Port Settings button. In the setup window click on the Port ComboBox.
Friendly, J.P
Thanks for helping out and your LazSerial.
The LazSerial / Synapser find the avaiable com ports is via Registry
Code: Pascal  [Select][+][-]
  1. function GetSerialPortNames: string;
  2. var
  3.   reg: TRegistry;
  4.   l, v: TStringList;
  5.   n: integer;
  6. begin
  7.   l := TStringList.Create;
  8.   v := TStringList.Create;
  9.   reg := TRegistry.Create;
  10.  
  11.   try
  12. {$IFNDEF VER100}
  13. {$IFNDEF VER120}
  14.     reg.Access := KEY_READ;
  15. {$ENDIF}
  16. {$ENDIF}
  17.     reg.RootKey := HKEY_LOCAL_MACHINE;
  18.     reg.OpenKey('\HARDWARE\DEVICEMAP\SERIALCOMM\', false);
  19.     reg.GetValueNames(l);
  20.     for n := 0 to l.Count - 1 do
  21. // Modif J.P  03/2013
  22.       v.Add(Pchar(reg.ReadString(l[n])));
  23.     Result := v.CommaText ;
  24.   finally
  25.     reg.Free;
  26.     l.Free;
  27.     v.Free;
  28.   end;
  29. end;                      
On my Windows 10 machine the registry for \HARDWARE\DEVICEMAP\ is different have a look. So the Lazserial demo do not work on my setup.

MoellerCLaus

  • Full Member
  • ***
  • Posts: 114
    • Vig Foreningsprogram
Re: LazSerial: List of USB ports and virtual port issue
« Reply #8 on: July 14, 2021, 08:49:48 am »
For development on Windows you can use com0com virtual driver
http://com0com.sourceforge.net/
You can also use com2tcp to communicate between 2 PC in network.
Thanks I will try it.

MoellerCLaus

  • Full Member
  • ***
  • Posts: 114
    • Vig Foreningsprogram
Re: LazSerial: List of USB ports and virtual port issue
« Reply #9 on: July 14, 2021, 09:07:10 am »
There is a way to get the USB ports installed on the PC
Trough this link I installed a USBViewer made by Microsoft.
https://www.techrepublic.com/article/tracking-down-usb-devices-in-windows-10-with-microsofts-usb-device-viewer/

Here is the result
I will keep you posted how it can be done in Lazarus.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: LazSerial: List of USB ports and virtual port issue
« Reply #10 on: July 14, 2021, 09:41:31 am »
hello,
On my Windows 10 machine the registry for \HARDWARE\DEVICEMAP\ is different have a look. So the Lazserial demo do not work on my setup.
if you haven't a SERIALCOMM key in your registry it is because you have no serial com port in your computer.

See in attachment my registry ( windows 10) .

Friendly, J.P
« Last Edit: July 14, 2021, 09:43:33 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

MoellerCLaus

  • Full Member
  • ***
  • Posts: 114
    • Vig Foreningsprogram
Re: LazSerial: List of USB ports and virtual port issue
« Reply #11 on: July 14, 2021, 10:29:43 am »
Hi
You are so right ;) No serial port but I want to use USB with adapter for that.
By the way serial ports with 9-pins or 32-pins are rare on PC's these days.
I need to do a serial protocol called OSM6 on top of a RS-485 hardware setup.

Buttomline is that I want my users via a combox to select the usb ports avaiable on the computer.

MoellerCLaus

  • Full Member
  • ***
  • Posts: 114
    • Vig Foreningsprogram
Re: LazSerial: List of USB ports and virtual port issue
« Reply #12 on: July 14, 2021, 01:49:18 pm »
Hi JP
I found some more splendid code of yours; Utilwmi. Tried it out with the following code.

Code: Pascal  [Select][+][-]
  1. procedure TFormSerialTest.Button1Click(Sender: TObject);
  2. var
  3.   WMIResult         : TFPObjectList;
  4.   i                 : Integer;
  5.   PropNamesIndex    : Integer;
  6.   PropNames         : Array[0..22] of String =(
  7.    'Availability','Caption','ConfigManagerErrorCode','ConfigManagerUserConfig',
  8.    'CreationClassName', 'Description','DeviceID','ErrorCleared', 'ErrorDescription',
  9.    'InstallDate','LastErrorCode','Manufacturer','MaxNumberControlled','Name',
  10.    'PNPDeviceID','PowerManagementCapabilities','PowerManagementSupported',
  11.    'ProtocolSupported','Status','StatusInfo','SystemCreationClassName',
  12.    'SystemName','TimeOfLastReset');
  13.  
  14. (*  ( 'Availability','Caption','CreationClassName','Description','DeviceID',
  15.       'Name','PNPDeviceID','Status','SystemCreationClassName', 'SystemName');*)
  16. begin
  17.   Memo1.Clear;
  18.   WMIResult := GetWMIInfo('Win32_USBController', PropNames,'');
  19.   for i := 0 to Pred(WMIResult.Count) do
  20.   begin
  21.     Memo1.Append('=================');
  22.     for PropNamesIndex := Low(PropNames) to High(PropNames) do
  23.     begin
  24.       Memo1.Append(TStringList(WMIResult[i]).Names[PropNamesIndex] + ' : ' +
  25.               TStringList(WMIResult[i]).ValueFromIndex[PropNamesIndex]);
  26.     end;
  27.   end;
  28.   // Clean up
  29.   WMIResult.Free;
  30. end;      
  31.  
Code: Pascal  [Select][+][-]
  1. =================
  2. Availability : <null>
  3. Caption : Intel(R) USB 3.1 eXtensible Host Controller - 1.10 (Microsoft)
  4. ConfigManagerErrorCode : 0
  5. ConfigManagerUserConfig : False
  6. CreationClassName : Win32_USBController
  7. Description : USB xHCI-kompatibel værtscontroller
  8. DeviceID : PCI\VEN_8086&DEV_02ED&SUBSYS_370C17AA&REV_00\3&11583659&1&A0
  9. ErrorCleared : <null>
  10. ErrorDescription : <null>
  11. InstallDate : <null>
  12. LastErrorCode : <null>
  13. Manufacturer : Generisk USB xHCI-værtscontroller
  14. MaxNumberControlled : <null>
  15. Name : Intel(R) USB 3.1 eXtensible Host Controller - 1.10 (Microsoft)
  16. PNPDeviceID : PCI\VEN_8086&DEV_02ED&SUBSYS_370C17AA&REV_00\3&11583659&1&A0
  17. PowerManagementCapabilities : <null>
  18. PowerManagementSupported : <null>
  19. ProtocolSupported : 16
  20. Status : OK
  21. StatusInfo : <null>
  22. SystemCreationClassName : Win32_ComputerSystem
  23. SystemName : CLAUS-PC
  24. TimeOfLastReset : <null>

Gives a lot of info. But not really what I was looking for. Maybe some one can use it? ;)

dseligo

  • Hero Member
  • *****
  • Posts: 1182
Re: LazSerial: List of USB ports and virtual port issue
« Reply #13 on: July 14, 2021, 02:28:34 pm »
Hi
You are so right ;) No serial port but I want to use USB with adapter for that.
By the way serial ports with 9-pins or 32-pins are rare on PC's these days.
I need to do a serial protocol called OSM6 on top of a RS-485 hardware setup.

Buttomline is that I want my users via a combox to select the usb ports avaiable on the computer.

Can you be more specific how do you plan to connect two PCs? Do you already have hardware or are you in planning phase? What hardware is that?
AFAIK, you can't just connect two computers via USB - you need some 'adapter' in between.

MoellerCLaus

  • Full Member
  • ***
  • Posts: 114
    • Vig Foreningsprogram
Re: LazSerial: List of USB ports and virtual port issue
« Reply #14 on: July 14, 2021, 02:51:38 pm »
Hi
I need to test my implementation of the protocol. Therefore it could be could to have virtual ports on one PC. One application sending another receiving. This can now be done with COM0COM approach.

Hardware: there is a USB to RS-485 adapter between PC an the box with 9-pin RS-485 interface.

 :) I hope I should be well off with this approach.

I struckled until a minute ago to find about which USB-devices on the PC is doing what.
Code: Pascal  [Select][+][-]
  1.  
  2. // Uses Utilwmi
  3. procedure TFormSerialTest.Button1Click(Sender: TObject);
  4. var
  5.   WMIResult         : TFPObjectList;
  6.   i                 : Integer;
  7.   PropNamesIndex    : Integer;
  8.   PropNames         : Array[0..2] of String =(
  9.   'DeviceId','PNPDeviceID','Description');
  10.  
  11. begin
  12.   Memo1.Clear;
  13.   WMIResult := GetWMIInfo('Win32_USBHub', PropNames,'');
  14.   for i := 0 to Pred(WMIResult.Count) do
  15.   begin
  16.     Memo1.Append('=================');
  17.     for PropNamesIndex := Low(PropNames) to High(PropNames) do
  18.     begin
  19.       Memo1.Append(TStringList(WMIResult[i]).Names[PropNamesIndex] + ' : ' +
  20.               TStringList(WMIResult[i]).ValueFromIndex[PropNamesIndex]);
  21.     end;
  22.   end;
  23.   // Clean up
  24.   WMIResult.Free;
  25. end;
  26.  
  27.  

Here the field description gives the ansver.

 

TinyPortal © 2005-2018