• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 

Reopen (keep open) serial port after plugin RS232 (USB,BT,IrDA) adapter

Started by Roman Novgorodov, June 30, 2008, 02:30:39 pm

Previous topic - Next topic

Roman Novgorodov

Hello

You can add following method into main form of application for monitor the WM_DEVICECHANGE:


procedure WMDeviceChange(var Msg:TMessage); message WM_DEVICECHANGE;


You can see such methods in several Demo projects of nrComm Lib distribution.

After that you can use following handler for reopen serial port after it will appear in the system again:


procedure TForm1.WMDeviceChange(var Msg: TMessage);
begin
  nrComm1.WMDeviceChange(Msg);
  if (nrComm1.DeviceIndex > 0) and (not nrComm1.Active)
    then
      try
        nrComm1.Active := True;
        Memo2.Lines.Add('port is reopened');
      except
        on e:Exception do Memo2.Lines.Add(e.Message);
      end;
end;


Please note that at least once before this, the nrComm1 should have a correct selected serial port (DeviceIndex value).

Good luck!

Roman Novgorodov
DeepSoftware.Com

Quote
Hi,

I am trying to monitor the connection(s) of a USB -> Serial adaptor to the
USB ports. I wish to have the first adaptor connected attach to nrComm1,
and the next one to nrComm2.

If one is disconnected, the program needs to be able to reconnect to that
nrComm component when a USB connection is made again, without affecting
the other port assignment.

I am having trouble managain to do this. Do you have any thoughts that
would help?

I am attachign somne sample code I have tried to  use. port 1 & port 2 are
string variables.
....
(skipped)
...


DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.