Jump to content

Monitoring status of COM port (connected or disconnected)


vlkc

Recommended Posts

Hello,

Does anybody know how to monitor COM? Here is the sample:

{ 
  Some applications need to know when the user inserts or 
  removes a compact disc or DVD from a CD-ROM drive without 
  polling for media changes. Windows provide a way to notify these 
  applications through the WM_DEVICECHANGE message. 
}

 type
   TForm1 = class(TForm)
   private
     procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
   public

   end;

 {...}

 implementation

 {$R *.DFM}

 procedure TForm1.WMDeviceChange(var Msg: TMessage);
 const
   DBT_DEVICEARRIVAL = $8000; // system detected a new device 
  DBT_DEVICEREMOVECOMPLETE = $8004;  // device is gone 
var
   myMsg: string;
 begin
   inherited;
   case Msg.wParam of
     DBT_DEVICEARRIVAL: myMsg  := 'CD inserted!';
     DBT_DEVICEREMOVECOMPLETE: myMsg := 'CD removed!';
   end;
   ShowMessage(myMsg);
 end;

 

How to realize it in UniGui ServerModule?

 

{ 
  Some applications need to know when the user inserts or 
  removes a compact disc or DVD from a CD-ROM drive without 
  polling for media changes. Windows provide a way to notify these 
  applications through the WM_DEVICECHANGE message. 
}

 type
   TUniServerModule = class(TUniGUIServerModule)
   private
     procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
   public

   end;

 {...}

 implementation

 {$R *.DFM}

 procedure TUniServerModule.WMDeviceChange(var Msg: TMessage);
 const
   DBT_DEVICEARRIVAL = $8000; // system detected a new device 
  DBT_DEVICEREMOVECOMPLETE = $8004;  // device is gone 
var
   myMsg: string;
 begin
   inherited;
   case Msg.wParam of
     DBT_DEVICEARRIVAL: myMsg  := 'CD inserted!';
     DBT_DEVICEREMOVECOMPLETE: myMsg := 'CD removed!';
   end;
   ShowMessage(myMsg);
 end;

I this way does not work :) Please help.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...