Author Topic: How to detect a new serial port has been created ...  (Read 1775 times)

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
How to detect a new serial port has been created ...
« on: April 25, 2008, 06:04:54 pm »
Hello

Every time when your windows system changes its hardware configuration, it sends WM_DEVICECHANGE message for all runned applications.

You can process this message in your main form like it is done in the following code:

Code: [Select]

unit Unit1;
interface
  ...
Type
  TForm1 = class(TForm)
   ...
  public       
    procedure WMDeviceChange(var Msg:TMessage); message WM_DEVICECHANGE;     
  end;

implementation

{$R *.dfm}
...

procedure TForm1.WMDeviceChange(var Msg: TMessage);
begin
  nrComm1.WMDeviceChange(Msg);
end;

end.


The TnrComm class and most of other classes from nrComm Lib have method WMDeviceChange() that helps to process WM_DEVICECHANGE message and reloads internal device list of component.

Roman Novgorodov
DeepSoftware.Com

Quote
is there a way for the application to detect a new port has been
created, like when a USB-RS232 cable is plugged in?  Or should I just poll
for it?
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.