adam6000 module

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

Allows access to Adam 6050, 6051, 6017 and other 6000 series cards

methods:
  ReadInput(ch)                - read one digital input, specified by ch
  ReadOutput(ch)               - read one digital output, specifed by ch
  WriteOutput(ch,val)          - write one digital output, specifed by ch and val
  ReadWord(addr)               - read word starting at byte 0 + addr, in bytes
  WriteWord(addrOff,data)      - addressOffset - use 0 for 00001-000016 addresses values or 2 for 00017-00XXX values;
                                 data - write word starting at byte 0 + addr, in bytes
  ReadRegisterWord(addr)       - read word starting at address 40000 + addr, in words
  WriteRegisterWord(addr, val) - write word starting at address 40000 + addr, in words
  ResetCounter(counterNo)      - counter function, only for ADAM-6051
  ReadCounter(counterNo)       - counter function, only for ADAM-6051
  close()

constructor:

  a=Adam6000(ip='10.0.0.1',KeepOpen=1,timeout=1.0,unit=1,port=502)
   KeepOpen - if 1 keep socket open until close() is called
   timeout  - socket read timeout value
   ip,port  - Adam IP,port
   unit     - unit number. Use default 1

Usage samples:

try:
  a=Adam6000('10.0.0.1',1)
  ok,txt,msg = a.WriteOutput(0,1)
  ok,txt,val = a.ReadInput(0)
except:
  print "exception"

Revision history:

1.0.0.4  - 25Jun2015, RL: fixed ReadRelay
1.0.0.3  - 10Jun2015, RL: supports Scorpion IO Interface, SIO (added Read/WriteRelay, ReadDI, ReadDIs, ReadRelays)
1.0.0.2  - 31Jan2011, RL: direct access to advantech memory and registers - enables to control all 6000 series cards
1.0.0.1  - 28Jan2011, PB: initial version
class adam6000.Adam6000(ip='10.0.0.1', KeepOpen=1, timeout=1.0, unit=1, port=502)
proxykill()

kill the 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

WriteWord(addrOffset, data)
Writes two bytes (word) starting at address 0 plus addrOffset
addrOffset - address offset in bytes data - two bytes of data to write

lowest bit is coil 0, highest is coil 15 example: to turn on both coil 0 and 1, call WriteOutputsWord(3)

ReadWord(addr)

Reads word starting at address 0

ReadCounter(counterNo)

Reads counter value index starts with 0

ResetCounter(counterNo)

Resets counter value index starts with 0

WriteOutput(ch, val)

Write value to output channel ch if val == 0 then output is off else on

ReadOutput(ch)

Read output value for channel :returns: 1 if on

0 if off (touple index 2)
ReadInput(ch)

Read specified input channel :returns: 1 if on

0 if off (touple index 2)
ReadRegisterWord(addr)

read one byte at speciufied address

WriteRegisterWord(addr, val)

write ome byte at specified address

WriteRelay(ch, val)

SIO wrapper for doWriteBit

ReadRelay(ch)

SIO wrapper for doReadBit

ReadDI(ch)

SIO wrapper for diReadBit

ReadRelays()

SIO wrapper for doReadByte

ReadDIs()

SIO wrapper for diReadByte