Author Topic: PRINT #4 Shutting down  (Read 13179 times)

jbryant87

  • Newbie
  • Posts: 11
  • I'm a llama!
    • View Profile
PRINT #4 Shutting down
« on: January 09, 2018, 07:06:04 AM »
I use the below code to allow a leak test device to print data into strings to evaluate.
The device will send several lines, but the PLC will shut down the port after recieving the first line.
is there a way to keep the port open and recieve all the data?
This is the code used below:

G$=""
J$=""
G=0
H=0


while G=0 and H<20
   PRINT #4 "<TCPCONNECT 192.168.100.004:10001>"
   J$=""
   DELAY 200
   if status(3)=1 then
      I=0
      while G=0 and I<=20
         delay 200
         J$=INPUT$(4)
   if len(J$)>0 then
            G=1
           G$=J$
endif
I=I+1
endwhile
ENDIF
PRINT #4 "</>"    ' close connection before reconnecting
H=H+1
   '
IF G=0 THEN
DELAY 500
ENDIF
endwhile

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PRINT #4 Shutting down
« Reply #1 on: January 16, 2018, 07:45:10 PM »
It appears that your code exited the WHILE loop after receiving the first line and then you execute the PRINT #4 "</>" command, which then close the connection.

So you may need to change the program a bit. Yet you do not want the CPU to be stuck in the WHILE loop inside one custom function all the time. So you should implement a state machine so that the ladder program get to continue to execute and this custom function is then re-enter on the next ladder logic scan.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS