Up | Python Module - Adam | Advantech API | Advantech Bionic API | OPC | Python Module - Scl

Release Notes
 

  

 
Advantech Bionic API

NOTE: This Advantech Bionic API replaces Advantech API, that is based on Advantech Device Manager.

WHAT IS Advantech?
Advantech www.advantech.com  manufactures distributed IO modules.  The modules comes in various flavors supporting several different IO requirements such as analog input/output, digital input/output. 

Advantech IO Modules AND SCORPION
Advantech mix very well due to Scorpion's Python scripting support.  Scorpion is shipped with Python classes capable of communicating the IO modules via Bionic SDK.  The Python classes are shipped as is with full source code, empowering users to modify or extend the existing support.

More information on Python Scripting.

The Advantech BionicAPI module requires the following modules to be installed in addition to Scorpion:

Demo test profile: BionicTest - Windows 7_010.zip (requires Scorpion 8.5.0.490 or newer).

NOTE: module was tested only with device USB-4750.

Advantech USB-4750 EXAMPLE CODE

WHERE DO I PUT THE SCRIPTS FOR IO?
A structured way of setting up IO scripting is:

Central.Start
Open the connections here.  If unsuccessful initialization set a global variable for access elsewhere
Central.Stop
Close communication here.
Central.Scripts
In central you can define a number of useful scripts.  You can simplify syntax by defining your own access functions.
Actions
It is useful to define a set of event handlers that will call your user defined scripts.  
Scheduler
The scheduler mat be set up to periodically call one of the defined actions.


Central.Start
try:
  import bionicapi
  deviceNumber = 1
  io=bionicapi.BionicAPI(deviceNumber)
  print 'io'
  if io.okdevice == bionicapi.R_OK:
    print 'device ok'
    propFeatures = io.DEVICEFEATURES
    for feature in propFeatures:
      print feature, propFeatures[feature]
  else:
    print bionicapi.R_OK
except:
  print 'install advantech module and sw'
 
Central.Stop
io.close()


Example Scripts
1. Read isolated digital inputs
# read bit 0 isolated input 
#ok,txt,error|value = pci.do_readbit(port,bit) - read specified bit from specified port
ok,txt,err_or_val = io.di_readbit(bionicapi.PORT_ID, 0)
if ok==0:
  print 'di_readbit: isolated input 0 is %d' % err_or_val
else:
  print 'di_readbit: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)


# read bit 8 isolated input
#ok,txt,error|value = pci.do_readbit(port,bit) - read specified bit from specified port
ok,txt,err_or_val = io.di_readbit(bionicapi.PORT_ID+1, 0)
if ok==0:
  print 'di_readbit: isolated input 8 is %d' % err_or_val
else:
  print 'di_readbit: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)

# read bit 13 isolated input
#ok,txt,error|value = pci.do_readbit(port,bit) - read specified bit from specified port
ok,txt,err_or_val = io.di_readbit(bionicapi.PORT_ID+1, 5)
if ok==0:
  print 'di_readbit: isolated input 8 is %d' % err_or_val
else:
  print 'di_readbit: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)

    
2. Write isolated outputs
# write bit 2 isolated output to 1
mask = 0b00000010 # Write the binary mask of 00000010
ok,txt,err_or_val = io.do_writebit(bionicapi.PORT_ID, mask, 1)
if ok==0:
  print 'do_writebit: isolated output 0 is %d' % 1
else:
  print 'do_writebit: error %s, subcode %d when writing' % (io.OPCODES[ok], err_or_val)


# write bits 3 and 4 isolated output to 1
mask = 0b00001100 # Write the binary mask of 00001100
ok,txt,err_or_val = io.do_writebit(bionicapi.PORT_ID, mask, 1)
if ok==0:
  print 'do_writebit: isolated output 0 is %d' % 1
else:
  print 'do_writebit: error %s, subcode %d when writing' % (io.OPCODES[ok], err_or_val)

# write byte 0 isolated output
ok,txt,err_or_val = io.do_writebyte( bionicapi.PORT_ID,0xff,1)
if ok==0:
  print 'do_writebyte: isolated output byte (bits 0..7) is %d' % 1
else:
  print 'do_writebyte: error %s, subcode %d when writing' % (io.OPCODES[ok], err_or_val)

# write byte 1 isolated output
ok,txt,err_or_val = io.do_writebyte( bionicapi.PORT_ID+1,0xff,1)
if ok==0:
  print 'do_writebyte: isolated output byte (bits 8..15) is %d' % 1
else:
  print 'do_writebyte: error %s, subcode %d when writing' % (io.OPCODES[ok], err_or_val)
    

    
3. Analog IO
# read analog input value from 0. channel
ok,txt,err_or_val = io.ad_readanalog(0)
if ok==0:
  print 'ad_readanalog: 0. channel analog input value is %d' % err_or_val
else:
  print 'ad_readanalog: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)
  
# read analog input value from 2. channel
ok,txt,err_or_val = io.ad_readanalog(2)
if ok==0:
  print 'ad_readanalog: 2. channel analog input value is %d' % err_or_val
else:
  print 'ad_readanalog: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)
  
# write analog value to 0. output channel
ok,txt,err_or_val = io.da_writeanalog(0, 1)
if ok==0:
  print 'da_writeanalog: 0. channel analog output value is %f' % 1
else:
  print 'da_writeanalog: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)
  
# write analog value to 1. output channel
ok,txt,err_or_val = io.da_writeanalog(1, 5.5)
if ok==0:
  print 'da_writeanalog: 1. channel analog output value is %f' % 5.5
else:
  print 'da_writeanalog: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)
    
4. Close device
io.close()
    

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