• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
March 28, 2024, 11:06:02 am

News:

SMF - Just Installed!


Ignoring no device connected

Started by docwat, September 07, 2012, 07:49:39 am

Previous topic - Next topic

docwat

Hi,

I am trying to avoid my programme hanging when the device on my comport is unplugged is unplugged.

Any suggestions ?

Thanks,

Docwat.

procedure TAKWFRM1.READ_BUTTONClick(Sender: TObject);

var
    ReadCom:Array[0..4] of byte;
    i:Integer;
    Value:Integer;
    ReadStr:String;
    S:String;
    R:Array[0..19] of Byte;
begin


      for i:=0 to 19 do R:=0;
      InputDat.Text:='';
      nrComm1.SetStateDTR(True);
      nrComm1.SetStateRTS(True);

      nrComm1.Active:=True;

      if nrComm1.Active then
      nrSemaphore1.Checked:=True;
      application.processMessages;
      ReadCom[0]:=$01;
      ReadCom[1]:=$02;
      ReadCom[2]:=$08;
      ReadCom[3]:=$32;
      ReadCom[4]:=$38;

      nrComm1.SendData(@ReadCom[0],5);

      nrComm1.Read(@R[0],16);

      for i:=8 downto 3 do
             begin
             ReadStr:=IntToHex(R,2);
             InputDat.Text:=InputDat.Text+ReadStr;
             end;
             
      for i:=4 downto 3 do
              begin
              ReadStr:=IntToHex(R,2);
              S:=S+ReadStr;
              end;
              Value:= HexStringToInt(S);
              Channel.Text:=IntToStr(Value);

      nrSemaphore1.Checked:=False;
      nrComm1.Active:=False;

Roman Novgorodov

Hello

If you use USB2RS232 adapter (or something like that), you can handle OnClose event to catch serial port lost.
If you works with native RS232 port you need analyze DTR RTS lines if your device uses them.
If our device is connected over Tx,  Rx and GND only, you can only check timeouts on waiting device replies.

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

Thomashox

Hi Everyone

I have large network with around 250 switches and i want to know in switch which port is connected to which device..how can i do this???
pls reply if anyone knows.