LazSerial: List of USB ports and virtual port issue lazarus / 62-General ---------------------------------------------------------------------- MoellerCLaus · 2021-07-13 11:57 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 · 2021-07-13 12:17 Quote from: MoellerCLaus on July 13, 2021, 01:57:38 pmFor 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. ---------------------------------------------------------------------- MoellerCLaus · 2021-07-13 12:43 Thanks both for quick response. Quoteif 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 · 2021-07-13 13:14 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 ---------------------------------------------------------------------- ttomas · 2021-07-13 13:52 You will need some usb2serial device on your PC. ---------------------------------------------------------------------- ttomas · 2021-07-13 13:57 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 · 2021-07-13 14:03 my two ports usb  RS232 serial  converter in attachment (COM10 , COM11 on my first message) ---------------------------------------------------------------------- MoellerCLaus · 2021-07-14 06:48 Quote from: Jurassic Pork on July 13, 2021, 03:14:46 pmhello, 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function GetSerialPortNames: string;var  reg: TRegistry;  l, v: TStringList;  n: integer;begin  l := TStringList.Create;  v := TStringList.Create;  reg := TRegistry.Create;   try{$IFNDEF VER100}{$IFNDEF VER120}    reg.Access := KEY_READ;{$ENDIF}{$ENDIF}    reg.RootKey := HKEY_LOCAL_MACHINE;    reg.OpenKey('\HARDWARE\DEVICEMAP\SERIALCOMM\', false);    reg.GetValueNames(l);    for n := 0 to l.Count - 1 do// Modif J.P  03/2013      v.Add(Pchar(reg.ReadString(l[n])));    Result := v.CommaText ;  finally    reg.Free;    l.Free;    v.Free;  end;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 · 2021-07-14 06:49 Quote from: ttomas on July 13, 2021, 03:57:11 pmFor 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 · 2021-07-14 07:07 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 · 2021-07-14 07:41 hello, Quote from: MoellerCLaus on July 14, 2021, 08:48:58 amOn 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 ---------------------------------------------------------------------- MoellerCLaus · 2021-07-14 08:29 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 · 2021-07-14 11:49 Hi JP I found some more splendid code of yours; Utilwmi. Tried it out with the following code. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFormSerialTest.Button1Click(Sender: TObject);var  WMIResult         : TFPObjectList;  i                 : Integer;  PropNamesIndex    : Integer;  PropNames         : Array[0..22] of String =(   'Availabilit y','Caption','ConfigManagerErrorCode','ConfigManagerUserConfig',   'CreationClassName', 'Description','DeviceID','ErrorCleared', 'ErrorDescription',   'InstallDate','LastErrorCode','Manufacturer','Ma xNumberControlled','Name',   'PNPDeviceID','PowerManagementCapabilitie s','PowerManagementSupported',   'ProtocolSupported','Status','StatusInfo','SystemCreationClassName',   'SystemName','TimeOfLastReset'); (*  ( 'Availability','Caption','Crea tionClassName','Description','DeviceID',      'Name','PNPDeviceID','Status','SystemCreationClassName', 'SystemName');*)begin  Memo1.Clear;  WMIResult := GetWMIInfo('Win32_USBController', PropNames,'');  for i := 0 to Pred(WMIResult.Count) do  begin    Memo1.Append('=================');    for PropNamesIndex := Low(PropNames) to High(PropNames) do    begin      Memo1.Append(TStringList(WMIResult[i]).Names[PropNamesIndex] + ' : ' +              TStringList(WMIResult[i]).ValueFromIndex[PropNamesIndex]);    end;  end;  // Clean up  WMIResult.Free;end;       Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i =================Availability : Caption : Intel(R) USB 3.1 eXtensible Host Controller - 1.10 (Microsoft)ConfigManagerErrorCode : 0ConfigManagerUserConfig : FalseCreationClassName : Win32_USBControllerDescription : USB xHCI-kompatibel værtscontrollerDeviceID : PCI\VEN_8086&DEV_02ED&SUBSYS_370C17AA&REV_00 \3&11583659&1&A0ErrorCleared : ErrorDescription : InstallDate : LastErrorCode : Manufacturer : Generisk USB xHCI-værtscontrollerMaxNumberControlled : Name : Intel(R) USB 3.1 eXtensible Host Controller - 1.10 (Microsoft)PNPDeviceID : PCI\VEN_8086&DEV_02ED&SUBSYS_370C17AA&REV_00\ 3&11583659&1&A0PowerManagementCapabilities : PowerManagementSupported : ProtocolSupported : 16Status : OKStatusInfo : SystemCreationClassName : Win32_ComputerSystemSystemName : CLAUS-PCTimeOfLastReset : Gives a lot of info. But not really what I was looking for. Maybe some one can use it? ---------------------------------------------------------------------- dseligo · 2021-07-14 12:28 Quote from: MoellerCLaus on July 14, 2021, 10:29:43 amHi 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 · 2021-07-14 12:51 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  // Uses Utilwmiprocedure TFormSerialTest.Button1Click(Sender: TObject);var  WMIResult         : TFPObjectList;  i                 : Integer;  PropNamesIndex    : Integer;  PropNames         : Array[0..2] of String =(  'DeviceId','PNPDeviceID','Description'); begin  Memo1.Clear;  WMIResult := GetWMIInfo('Win32_USBHub', PropNames,'');  for i := 0 to Pred(WMIResult.Count) do  begin    Memo1.Append('=================');    for PropNamesIndex := Low(PropNames) to High(PropNames) do    begin      Memo1.Append(TStringList(WMIResult[i]).Names[PropNamesIndex] + ' : ' +              TStringList(WMIResult[i]).ValueFromIndex[PropNamesIndex]);    end;  end;  // Clean up  WMIResult.Free;end;   Here the field description gives the ansver. ---------------------------------------------------------------------- alpine · 2021-07-14 13:09 Quote from: MoellerCLaus on July 14, 2021, 10:29:43 amHi 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. As far as I understand you want to connect 2 PCs with USB/RS-232 dongles. In that case you don't need USB ports scanned, you'll need to list the available serial ports. The common case with the contemporary computers with no serial ports included, there is a big chance to have only one serial port available - namely that of the dongle. You can use QueryDosDevice() (in Windows) for searching: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Windows, Math {for IfThen}; const  BUFSIZE = 1024; function EnumComPorts: TStringList;var  lpTargetPath: PChar;  I: Integer;begin  lpTargetPath := GetMem(BUFSIZE);  try    Result := TStringList.Create;    for I := 1 to 99 do      if QueryDosDeviceA(PChar('COM' + IntToStr(I)), lpTargetPath, BUFSIZE) > 0 then        Result.Add(IfThen(I < 10, '', '\\.\') + 'COM' + IntToStr(I));  finally    FreeMem(lpTargetPath);  end;end; Edit: As long for RS-485 - If your communication is half-duplex and you don't have a dedicated hardware, you can't expect nominal operation since in Windows there is no adequate way to control the direction of the RS-485 trancievers. ---------------------------------------------------------------------- MoellerCLaus · 2021-07-15 05:56 Hi y.ivanov Thanks for helping. Just to be clear it is RS-485; similar but not the same as RS-232. Your code scans for serial ports and will on my system find nothing - because nothing is plugged in yet. The code in my previous post will show which USB's the user can choose from. ---------------------------------------------------------------------- alpine · 2021-07-15 07:33 Quote from: MoellerCLaus on July 15, 2021, 07:56:32 amJust to be clear it is RS-485; similar but not the same as RS-232. It is clear. I wrote in my previous post about difficulties handling the RS-485 direction control in Windows.  Quote from: MoellerCLaus on July 15, 2021, 07:56:32 amYour code scans for serial ports and will on my system find nothing - because nothing is plugged in yet. The code in my previous post will show which USB's the user can choose from. Sorry, but I didn't get that. How you'd expect it to work when it is not plugged? Why the user should choose from USB ports as long as they're made (more or less) equal? ---------------------------------------------------------------------- MoellerCLaus · 2021-07-15 08:29 QuoteSorry, but I didn't get that. How you'd expect it to work when it is not plugged? Why the user should choose from USB ports as long as they're made (more or less) equal? You have a point. With the posted code I can detect if any USB port is free. This is actually a problem because newer smaller PC comes only with 2 or even 1 USB port. Further when plugged it can be detected which one. So no need for a combo .