Recent

Author Topic: TLazSerial : serial port component for Lazarus (windows and linux).  (Read 435967 times)

CM630

  • Hero Member
  • *****
  • Posts: 1732
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #540 on: June 25, 2026, 09:17:26 am »
I think I would have a single onComChange event call back fun() and pass "connected" or "disconnected" as the 1st parameter. A 2nd parameter which includes "unknown" can be expanded on later...
Am I missing something from the concepts: It could simply have one parameter with 3 states: Connected/Disconnected/Unknown. Do you mean something special by later?
As far as I have observed and read, when something is plugged in or out, message DBT_DEVNODES_CHANGED is sent multiple times. After a while a BT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE is sent. If both BT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE are received, two events are generated, possibly  device(s) were unplugged, while another one(s) were plugged in.
Then actions shall be taken.
TSerialWatcher generates OnConnected and OnDisconnected.
TSerialSelector uses both of them to start refreshing.
But TLazSerial generates only an OnDisconnected event when the activated serial port is unplugged.
So having one event with parameters does not seem a better solution to me.



FYI mode: Depending on the PC dongle driver, I sometimes get some strange connect cycling with BT devices going in and out of range.  I think the driver was trying to say "reconnected" but my end was too simple to handle this new notification. I ended up closing the port and reopening it anyway (which worked). But this "new connect" trigged my code to re-download device mode setting so I would ended with more Comm traffic at a time when the connection was at it's weakest.
Mas
This is a good reminder, I have not tested (much) the behaviour with BT devices.
Windows assigns port names (two per dongle) (or they are rather assigned manually) when a dongle is connected, but it does not remove them when it is unplugged, so maybe it is not possible to detect if the dongle is available. And losing and restoring range shall be even trickier.
I have no idea how Linux handles these cases.
I intend to investigate these.
Лазар 4,8 32 bit (sometimes 64 bit); FPC3,2,2

mas steindorff

  • Hero Member
  • *****
  • Posts: 601
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #541 on: June 25, 2026, 11:22:01 pm »
My original post was for something like:
Code: Pascal  [Select][+][-]
  1. MyOnConnectChange( isConnected:Boolean; optional:TOptionalParam);
  2.  
then the simple code can stay simple and just use isConnected parameter and the later code can use the optional parameters. I was thinking this is were your "unKnown" info would be passed and the list of states can grown from there.

I did not realize you were getting both a connect and disconnect at the same time at the driver level so this may not work like I had envisioned. Maybe that accounts for some of the strangeness I was seeing. 
I also get 2 comm ports for each BT connection.  For the (now obsolete) SiLab radio, one was for the VCP and the other (normally ignored) port was used for configuration and OTA FW updates. At the time I was playing with it, I found the competitor's radio (don't recall it's name) did not generate this 2nd port.  I believe our latest radio does 2 as well but it's also dual mode (BT & BLE) and I'm still zeroing in on the configuration trying to disable it's BLE side to avoid end user confusion.
When the PC's RF USB dongle is removed, it takes all of the BT VCP history with it on my windows PC. It is not a comm port itself, more of a USB device unless your playing with uBOX parts.

Good luck!  MAS

« Last Edit: June 27, 2026, 11:09:51 pm by mas steindorff »
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

CM630

  • Hero Member
  • *****
  • Posts: 1732
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #542 on: July 06, 2026, 09:09:30 pm »
Here comes version 0.7.8, not tested much!

1. Windows: Switched form JP's WMI rotuines to Marcov's routines https://forum.lazarus.freepascal.org/index.php/topic,24490.msg585568.html#msg585568
2. Windows: TSerialSelector and TSerialWatch cause less or no lag of the GUI, mostly due to 1 combined with some other changes.
3. Windows: I was lucky and I got duplicated COM port names, which allowed some improvements.
So both (or more ???) serial ports are listed once, separated by an “OR” with a notification “Duplicated”, as seen on the screenshot.

Still sometimes the Lazarus IDE crashes when using the package, but I do not remember seing a standalone app  doing that.

I have done no investigations wit bluetooth yet.

EDIT: It occurs this version did not work in Linux, so I replaced it with a fixed one.
« Last Edit: July 08, 2026, 01:59:09 pm by CM630 »
Лазар 4,8 32 bit (sometimes 64 bit); FPC3,2,2

 

TinyPortal © 2005-2018