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

Release Notes
 

  

 
Advantech API

NOTE: There is a new Bionic API, which is built on BioDAQ SDK that replaced 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 PCI 1730 and the USB-47xx modules.  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.

Advantech PCI-1730 and USB-47xx 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 advantechapi
    io=advantechapi.AdvantechAPI()
    if io.okdevice==advantechapi.R_OK:
      print " device ok"
      PropFeatures=io.DEVICEFEATURES
      for feature in prop:
        print feature,Propfeature[feature]
except:
    print 'install advantech module and sw'    
Central.Stop
io.close()
Example Scripts
1. read isolated digital inputs and ttl inputs

   # read bit 0 isolated input
   ok,txt,err_or_val = io.di_readbit( advantechapi.PORT_ID,0)
   if ok==0:
      print 'isolated input 0 is %d' % err_or_val
   else:
     print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)

   # read bit 8 isolated input
   ok,txt,err_or_val = io.di_readbit( advantechapi.PORT_ID+1,0)
   if ok==0:
      print 'isolated input 8 is %d' % err_or_val
   else:
     print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)

   # read bit 0 ttl input
   ok,txt,err_or_val = io.di_readbit( advantechapi.PORT_TTL,0)
   if ok==0:
      print 'ttl input 0 is %d' % err_or_val
   else:
     print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)

   # read bit 8 ttl input
   ok,txt,err_or_val = io.di_readbit( advantechapi.PORT_TTL+1,0)
   if ok==0:
      print 'ttl input 8 is %d' % err_or_val
   else:
     print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)

   # read byte 0 isolated output
   ok,txt,err_or_val = io.di_readbyte( advantechapi.PORT_ID)
   if ok==0:
      print 'isolated input byte 0 is %d' % err_or_val
   else:
     print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)

   # read byte 1 isolated output
   ok,txt,err_or_val = io.di_readbyte( advantechapi.PORT_ID+1)
   if ok==0:
      print 'isolated input byte 1 is %d' % err_or_val
   else:
     print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)

   # read byte 0 ttl output
   ok,txt,err_or_val = io.di_readbyte( advantechapi.PORT_TTL)
   if ok==0:
      print 'ttl input byte 0 is %d' % err_or_val
   else:
     print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)

   # read byte 1 ttl output
   ok,txt,err_or_val = io.di_readbyte( advantechapi.PORT_TTL+1)
   if ok==0:
      print 'isolated input byte 1 is %d' % err_or_val
   else:
     print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)

2.write isolated outputs and ttl outputs

   # write bit 0 isolated output
   ok,txt,err_or_val = io.do_writebit( advantechapi.PORT_ID,0,1)
   if ok==0:
      print 'isolated output 0 is %d' % 1
   else:
     print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)

   # write bit 8 isolated output
   ok,txt,err_or_val = io.do_writebit( advantechapi.PORT_ID+1,0,1)
   if ok==0:
      print 'isolated output 8 is %d' % 1
   else:
     print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)

   # write bit 0 ttl output
   ok,txt,err_or_val = io.do_writebit( advantechapi.PORT_TTL,0,1)
   if ok==0:
      print 'ttl output 0 is %d' % 1
   else:
     print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)

   # write bit 8 ttl output
   ok,txt,err_or_val = io.do_writebit( advantechapi.PORT_TTL+1,0,1)
   if ok==0:
      print 'ttl output 8 is %d' % 1
   else:
     print "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( advantechapi.PORT_ID,0xff,1)
   if ok==0:
      print 'isolated output byte (bits 0..7) is %d (00000001)' % 1
   else:
     print "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( advantechapi.PORT_ID+1,0xff,1)
   if ok==0:
     print 'isolated output byte (bits 8..15) is %d (00000001)' % 1
   else:
     print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)

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

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

3. Analog IO
   da_writeanalog(channel,value):
      'ok,txt,error = pci.da_writeanalog(channel,value) - write analog value to specified channel'

   ad_readanalog(channel):
      'ok,txt,error|value = pci.ad_readanalog(channel) - read analog value from channel'

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

  • Python 2.3.3 or higher 
  • Python Windows Extensions

All the modules are located on the Scorpion CD.


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