Author Topic: Status(3) function  (Read 12087 times)

Philippe Parmentier

  • Newbie
  • Posts: 29
  • new in plc
    • View Profile
Status(3) function
« on: March 22, 2014, 09:37:09 AM »
I'm trying to use the status(3) function to get the status of the following command

PRINT #4 "<TCPCONNECT 10.10.20.100:514>"

even after a delay the status(3) is still returning 0
but after id i do some PRINT #4
the text of the print is well sended via TCPIP.

Do i missunderstand how the status(3) is working?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Status(3) function
« Reply #1 on: March 23, 2014, 08:36:50 PM »
It depends on how long it takes for your network to make the TCP connection from the PLC to the server. Only when the connection is made will the STATUS(3) return a 1.

You can use  a simple wait loop to wait for status(3) to become 1 like the example below.


S = STATUS(3)
IF S    ' last connection is open
   PRINT #4 "</>"
   SETLCD 1,1, "Closing Last connection"
   FOR I = 1 to 30
      S = STATUS(3)
      IF S = 0
         SETLCD 1,1, "Connection Closed    "
       GOTO @10
     ENDIF
      DELAY 100
   NEXT
   SETLCD 1,1, "Fail to close. Retry"
   RETURN
ENDIF



@10
PRINT #4 "<TCPCONNECT 192.168.1.101:9080>"

FOR I = 1 to 30
  S = STATUS(3)
  IF S EXIT: ENDIF
  DELAY 100
NEXT

SETLCD 1,1, "Connected to server    "
A$ = INPUT$(4)


A better way is to use a state machine, which is by starting a timer after you send the PRINT #4 "<TCPCONNECT xxx.xxx.xxx.yyy:zzz>" command and when the timer times out it then check for the connection and do the necessary communication stuff. This will not cause the CPU to waste time waiting for the connection.
« Last Edit: May 04, 2014, 06:39:45 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS