Author Topic: Multiple Socket Support  (Read 15736 times)

EDGAR

  • Jr. Member
  • Posts: 60
  • Automating concepts around the world!
    • View Profile
    • Kinemics
Multiple Socket Support
« on: October 28, 2014, 04:27:06 AM »
Hi, I have 2 questions.

1. When communicating with other devices via ethernet, is it possible to use multiple sockets? I.e. Normally we use Print #4 "Data" it will be nice if we can use Print #5 or #19, etc.

2. If number 1 is not available, what's the minimum delay we can use when closing and reopening connections when communicating with multiple devices? I have used delay 1000 and 2000  after closing connection but still get communication errors and unable to connect.

Thanks,
Ed
Low cost Modbus OPC DA Server, supporting Modbus RTU, ASCII, and TCP. Download your demo today! Go to www.kinemics.com/modbus.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3177
    • View Profile
    • Internet Programmable PLCs
Re:Multiple Socket Support
« Reply #1 on: October 28, 2014, 09:14:07 AM »
There is only 1 client socket available for making outgoing connection.

Normally immediately after the socket is closed (i.e. after STATUS(3) returns a zero, not after PRINT #4 "</>") you can make a new connection to another server.  In our tests we are able to open and close connection in a round robin manner with multiple PLCs many times a second. You should check what was the issue when making a connection by using the INPUT$(4) command to read the status string. Was it because a previous connection was not properly closed?
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

EDGAR

  • Jr. Member
  • Posts: 60
  • Automating concepts around the world!
    • View Profile
    • Kinemics
Re:Multiple Socket Support
« Reply #2 on: October 28, 2014, 03:26:48 PM »
Thank You, I added the bolded while loop after finishing with the connection and it seems to be working fine now.


Code:

PRINT #4 "<MBTCPCONNECT "+I$+":502>"
Call Wait4conn  //WAIT FOR CONNECTION
S = STATUS(3)  //S=1 = CONNECTED, S=0 = NOT CONNECTED
   
   IF(S = 1) THEN
      setlcd 2,1, "READING REMOTE DEV..."
      READMB2 4,Q,1000+(O-1),DM[N],VAL(M$)
       IF STATUS(2) = 0 THEN
          setlcd 2,1, "BAD READ ADDRESS..."
          save_eep$ "ERROR READING "+STR$(1000+(O-1)) +":" + STR$(VAL(M$))+" AT " + I$+"."+STR$(Q), 40+L
       ELSE
          setlcd 2,1, "GOOD READ ADDRESS..."
          save_eep$ "GOOD READING "+STR$(1000+(O-1))  +":" + STR$(VAL(M$))+" AT " + I$+"."+STR$(Q), 40+L
       ENDIF
       REFRESH  //REFRESH IO'S    
   ELSE
       setlcd 2,1, "UNABLE TO CONN REM..."
       save_eep$  "ERROR: "+INPUT$(4)+", UNABLE TO CONNECT "+I$+"."+STR$(Q), 40+L
   ENDIF


PRINT #4 "</>"  
while status(3) <> 0
//do nothing...
endwhile



Function Wait4Conn:
I = 1

while STATUS(3) <> 1 OR I > 1000
I = I + 1
ENDWHILE
S = STATUS(3)
I = 1
RETURN


Thanks,
Ed
Low cost Modbus OPC DA Server, supporting Modbus RTU, ASCII, and TCP. Download your demo today! Go to www.kinemics.com/modbus.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3177
    • View Profile
    • Internet Programmable PLCs
Re:Multiple Socket Support
« Reply #3 on: October 29, 2014, 09:21:37 AM »
Thank you for sharing your code and we are glad it works out for you.

However, do be aware that putting an endless While..ENDWHILE loop can sometime resulted in difficult to track bugs because the PLC appears frozen while running in the endless loop. Although you can still communicate with it using iTRiLOGI other parts of the PLC program is not running.

You can find an example of Modbus TCP program that checks for closed connection and automatically reconnect back to the server. You can modify it to connect to multiple Modbus TCP servers as well.

C:\TRiLOGI\TL6\usr\samples\Ethernet\ModbusTCPTest.PC6

You can also refer to the following forum thread:

http://www.triplc.com/yabbse/index.php?board=2;action=display;threadid=2080
« Last Edit: October 29, 2014, 09:24:03 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

EDGAR

  • Jr. Member
  • Posts: 60
  • Automating concepts around the world!
    • View Profile
    • Kinemics
Re:Multiple Socket Support
« Reply #4 on: October 29, 2014, 01:30:42 PM »
Thank you! For now I will use the loop just like the Wait4Conn function shown on the previous post. I will also give the sample a try to see performace and how can we adopt it to our program.

Thanks again,
Ed

Low cost Modbus OPC DA Server, supporting Modbus RTU, ASCII, and TCP. Download your demo today! Go to www.kinemics.com/modbus.