Up | Adam-6000 Series | Adam-4000 Series | Adam-6060

Release Notes
 

  

 
Adam-4000 Series

ADAM 4000 EXAMPLE CODE
The modules must be configured with baudrate, optional checksum and module id.  This is done with the ADAM configuration utility shipped with the product.  The Adam.py module has an Auto detect method which will browse the RS-485 network and detect all modules with configured baud rate, checksum and module id.  Note that for the 4000 series digital input is normally in inverse logic.  No signal on an input channel is reported as 1.

from adam import *
PortCOM1=0
MaxModules=4
a=Adam( PortCOM1 )
ok,txt,baud,cs,modules = a.AutoDetect(MaxModules)
if ok:
  print 'Adam network found','Baud:',baud,'Checkum:',cs
  for module in modules:
      print 'Module[%d]' % module['Module'],module['Name']
else:
  print 'No Adam network found' 
# assume 4050 module as module 1, 4060 module as module 2, 4021 module as module 3
# digital output on module 1
# set the bits 0,1,2 to 1,0,1 - equvivalent to 0x5
ok,txt,msg=a.DigDataOut1Ch( 1, 0, 1 )
ok,txt,msg=a.DigDataOut1Ch( 1, 1, 0 )
ok,txt,msg=a.DigDataOut1Ch( 1, 2, 1 )
# set the value directly to 0x5 with one single call
ok,txt,msg=a.DigDataOutXCh( 1, 5 )

# digital input on module 1, returns outputs and inputs
ok,txt,outs,ins=a.DigDataInXCh( 1)

# digital output on module 2
# set the relay 0 and 3 to high, set relay 1,2 to low
ok,txt,msg= a.DigDataOut1Ch( 2, 0, 1 )
ok,txt,msg= a.DigDataOut1Ch( 2, 3, 1 )
ok,txt,msg= a.DigDataOut1Ch( 2, 1, 0 )
ok,txt,msg= a.DigDataOut1Ch( 2, 2, 0 ) 
# analog output on module 3
# assume the unit is configured for 0-10V, set the module to 5.5V
ok,txt,msg=a.AnaDataOutAsFloat( 3, 5.0 )
# done - terminate all IO
a.close()

Example 1 - DEALING WITH BITS
Here is some useful code to handle bit values


# The 4050 module returns inverted bit values for inputs.  
def inpinv( module ):
  ok,txt,outs,ins = a.DigDataIn( module )
  return ok,outs, (~ins) & 0x7f
# How to test for a high bit?
def bithi( v, bit): return v & ( 1 << bit)

# convert a byte to a string showing the bit values
def v2b( v ):
  s=''
  b=0x80
  for i in range(8):
      if bithi(v,7-i): s=s+'1'
      else:s=s+'0'
      b=b >> 1
  return s

Scorpion Vision Version XII : Build 646 - Date: 20170225
Scorpion Vision Software® is a registered trademark of Tordivel AS.
Copyright © 2000 - 2017 Tordivel AS.