Author Topic: Ignoring no device connected  (Read 1574 times)

docwat

  • Newbie
  • *
  • Posts: 3
    • View Profile
Ignoring no device connected
« on: September 07, 2012, 10:49:39 am »
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

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Ignoring no device connected
« Reply #1 on: January 16, 2014, 07:25:45 am »
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

  • Guest
Ignoring no device connected
« Reply #2 on: December 15, 2014, 06:23:44 am »
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.

RichardKeri

  • Newbie
  • *
  • Posts: 2
    • View Profile
Ignoring no device connected
« Reply #3 on: May 17, 2016, 08:08:11 am »
but after all, what we should do the test so that if the device is not connected to the USB port, the user is advised?

In the examples shown so far, even if the device is not connected, the user receives information that yes.

Thanks.