This is an example on how you can make Adam 6060 modules handle disconnect
without stopping More information about Advantech -
Adam modules
# Central Start
# -------------------------------------------
class Globals:
pass
globals=Globals()
from adam6060 import * #Adam6060.py must be in the Python directory
try:
globals.io=Adam6060('10.0.0.1')
except:
print 'No connection'
globals.IoOK=0
else:
print 'Adam connected'
globals.IoOK=1
#Read Digital Input 0
ok,txt,val=globals.io.ReadDI(0)
globals.Cur=val
#Reset all output relays
#ResetOutputRelays()
# Central Stop
# ------------------------------------------
io.close()
def IsTrigger():
# ------------------------------------------
if globals.IoOK:
try:
ok,txt,val=globals.io.ReadDI(0)
if ok==0:
globals.IoOK=0
print 'lost connection to Adam'
else:
RisingEdge=val-globals.Cur
globals.Cur=val
if RisingEdge==1:
print 'trigger detected'
ResetOutputRelays()
ExecuteCmd('GrabExecute','')
except:
globals.IoOK=0
print 'lost connection to Adam'
if not globals.IoOK:
ReconnectAdam(1)
def ReconnectAdam(a):
# ------------------------------------------
try:
globals.io=Adam6060('10.0.0.1')
print 'try to connect'
except:
print ' No connection with Adam6060'
globals.IoOK=0
else:
globals.IoOK=1
print ' Adam reconnected ','IoOK=',globals.IoOK
if globals.IoOK==1:
if a == 0:
ResetOutputRelays()
if a == 1:
IsTrigger()
if a == 2:
SetOutputRelays()
def ResetOutputRelays():
# ------------------------------------------
if globals.IoOK:
try:
ok,txt,msg=globals.io.WriteRelay(0,0)
ok,txt,msg=globals.io.WriteRelay(1,0)
ok,txt,msg=globals.io.WriteRelay(2,0)
ok,txt,msg=globals.io.WriteRelay(3,0)
ok,txt,msg=globals.io.WriteRelay(4,0)
ok,txt,msg=globals.io.WriteRelay(5,0)
if ok==0:
globals.IoOK=0
else:
print 'Reset relays, output =0 0 0 0 0 0'
except:
globals.IoOK=0
if not globals.IoOK:
ReconnectAdam(0)
def SetOutputRelays():
# ------------------------------------------
a=int(GetValue('Pass1.Value'))
b=int(GetValue('Fault1.Value'))
c=int(GetValue('Pass2.Value'))
d=int(GetValue('Fault2.Value'))
e=int(GetValue('Pass3.Value'))
f=int(GetValue('Fault3.Value'))
if globals.IoOK:
try:
ok,txt,msg=globals.io.WriteRelay(0,a)
ok,txt,msg=globals.io.WriteRelay(1,b)
ok,txt,msg=globals.io.WriteRelay(2,c)
ok,txt,msg=globals.io.WriteRelay(3,d)
ok,txt,msg=globals.io.WriteRelay(4,e)
ok,txt,msg=globals.io.WriteRelay(5,f)
if ok==0:
globals.IoOK=0
else:
print 'New relay output',a,b,c,d,e,f
except:
print ' cannot connect'
globals.IoOK=0
if not globals.IoOK:
ReconnectAdam(2)
|