adam6060 module

filename:adam6060.py
author:per@tordivel.no
version:1.0
copyright:2000-2015 Tordivel AS
license:Tordivel AS’ Scorpion Python Module License

Adam6060 is an Ethernet IO module The module has 6 Relay outputs and 6 DI inputs

This Class implements ModbusTcp messages ForceCoils and ReadCoils for relay and di access

The 6060 implements the coil addresses at 1-6 (DI) and 17-22 (Relay) but this Class translates the addresses to 0 for both types of io

Sockets are used for communication and the implementation relies on Python 2.3.3 in order to make use of timeouts

Use the Adam Etehernet IO utility to set up the module with a proper IO address In this utility you may also define the polarity of the DIs

The class implements a proxy thread which you can use to debug the protocol The Adam test programs (VB and Delphi) may be set up to use the host address while the class forwards the traffic to the module and relays the replies back.

The traffic is stored in a proxytrace list for inspection

The default operation is to open a socket and keep it open during the full session. This may be overrided in the constructor. Then sockets will be opened and closed after each transaction

properties:
  ip
  timeout (default 1.0s)
  ipproxy
  portproxy
  proxytrace

methods:
  proxy( ip,port )
  proxykill()
  ReadDI(ch)
  ReadRelay(ch)
  ReadDIs()
  ReadRelays()
  WriteRelay(ch,value)
  close()

constructor:
   a=Adam6060(ip,KeepOpen=1)

Usage, assuming the module is set up with IP address:

a=Adam6060('10.0.0.1',502,1)
ok,txt,DIs=a.ReadDIs()
ok,txt,Relays=a.ReadRelays()
ok,txt,msg = a.WriteRelay(0,1)
ok,txt,msg = a.WriteRelay(1,1)
ok,txt,msg = a.WriteRelay(2,1)
ok,txt,msg = a.WriteRelay(3,1)
ok,txt,msg = a.WriteRelay(4,1)
ok,txt,msg = a.WriteRelay(5,1)
ok,txt,val = a.ReadDI(0)
ok,txt,val = a.ReadDI(1)
ok,txt,val = a.ReadDI(2)
ok,txt,val = a.ReadDI(3)
ok,txt,val = a.ReadDI(4)
ok,txt,val = a.ReadDI(5)
a.close()
adam6060.l2str(l)
adam6060.str2l(s)
class adam6060.Adam6060(ip, KeepOpen=1)
proxykill()

kill thre proxy thread. open a socket and let it time out. the thread terminates after 1s

proxy(ip)

start the proxy thread

close()

close the socket if open

WriteRelay(ch, val)

write value val to relay channel ch

ReadRelay(ch)

read relay value for channel

ReadDI(ch)

read specified DI channel

ReadRelays()

read all relay values

ReadDIs()

read all DI channels