Issue with?IP socket to keep connected all the time
vincen
Posts: 526
Hi
I made a little piece of code to keep open an IP connection for some devices that I control in IP and don't want to bother to keep connection open. Unhappy when connection is broken (device offline or cable disconnected), the module goes in a loop of IP Socket already closed and never succeeds to get connection back online or if it does, just a very short time. I'm killing my head on this as I don't see the issue in my code.
Any ideas ? I guess it's something obvious but not seeing for now
Vinc?n
I made a little piece of code to keep open an IP connection for some devices that I control in IP and don't want to bother to keep connection open. Unhappy when connection is broken (device offline or cable disconnected), the module goes in a loop of IP Socket already closed and never succeeds to get connection back online or if it does, just a very short time. I'm killing my head on this as I don't see the issue in my code.
Any ideas ? I guess it's something obvious but not seeing for now
Vinc?n
MODULE_NAME='socket-ip' (dev dvSocket_IP,CHAR IP[30],CONSTANT INTEGER PORT) (***********************************************************) (* DEVICE NUMBER DEFINITIONS GO BELOW *) (***********************************************************) DEFINE_DEVICE dvMaster = 0:1:0 (***********************************************************) (* VARIABLE DEFINITIONS GO BELOW *) (***********************************************************) DEFINE_VARIABLE CONSTANT INTEGER ID_Timeline = 1 LONG TEMPS[1] = {2000} INTEGER ETAT // 1: Connect?, 2:Erreur (***********************************************************) (* MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW *) (***********************************************************) DEFINE_MUTUALLY_EXCLUSIVE (***********************************************************) (* THE EVENTS GO BELOW *) (***********************************************************) DEFINE_EVENT DATA_EVENT[dvMaster] { ONLINE: { ETAT = 2 TIMELINE_CREATE(ID_Timeline,TEMPS,1,TIMELINE_RELATIVE,TIMELINE_REPEAT) IP_CLIENT_OPEN(dvSocket_IP.Port,IP,Port,1) } } DATA_EVENT[dvSocket_IP] { ONLINE: { ETAT = 1 TIMELINE_SET(ID_Timeline,0) } OFFLINE: { ETAT = 2 // d?connect? IP_CLIENT_CLOSE(dvSocket_IP.Port) WAIT 5 { TIMELINE_SET(ID_Timeline,0) IP_CLIENT_OPEN(dvSocket_IP.Port,IP,Port,1) } } ONERROR: { ETAT = 2 // d?connect? IP_CLIENT_CLOSE(dvSocket_IP.Port) WAIT 5 { TIMELINE_SET(ID_Timeline,0) IP_CLIENT_OPEN(dvSocket_IP.Port,IP,Port,1) } } } TIMELINE_EVENT[ID_Timeline] { SWITCH(ETAT) { CASE 1: // Connect? { TIMELINE_SET(ID_Timeline,0) } CASE 2: // D?connect? { IP_CLIENT_CLOSE(dvSocket_IP.Port) WAIT 5 { IP_CLIENT_OPEN(dvSocket_IP.Port,IP,Port,1) TIMELINE_SET(ID_Timeline,0) } } } } (*****************************************************************) (* END OF PROGRAM *) (* *) (* !!! DO NOT PUT ANY CODE BELOW THIS COMMENT !!! *) (* *) (*****************************************************************)
0
Comments
ONERROR handler closes the port, then the timeline event closes it again, which will trigger an error.
Also I don't think OFFLINE handler needs to close the port as it is triggered by the closing of a port.
0 disabled
1 offline
2 pending
3 online
4 communication established
so that if I issue an open I set the flag to pending so if I have an error reconnect or any other type of reconnect I can check my tracking and not attempt a reconnect unless I'm offline or disable. If my var is 2 or above I do nothing except timeout the pending var after say 5 seconds if I get no online event.
Paul
JasonS: Would you mind to share your IP com modules ?
Due to contractual obligations I cannot share the actual code. But I am happy to help any other way.
Try this module. All settings are made through code so connections can be changed on the fly. Also, it can be used in conjunction with NetLinx comm modules to handle their IP connections. I've also added a main.axs file to show how to incorporate the module.
Sorry to jump in late - but I notice you chose IP port 1 in the code. Isn't port 1 in sue by the master firmware? I usually start my IP ports at 3.