ahio  1.0.0
I/O Communication Library
ahio.drivers.snap7.Driver Class Reference
Inheritance diagram for ahio.drivers.snap7.Driver:
ahio.abstract_driver.AbstractDriver object

Public Member Functions

def __enter__ (self)
 
def __exit__ (self, exc_type, exc_value, traceback)
 
def setup (self, address, rack=0, slot=1, port=102)
 Connects to a Siemens S7 PLC. More...
 
def available_pins (self)
 
def analog_references (self)
 
- Public Member Functions inherited from ahio.abstract_driver.AbstractDriver
def available_pins (self)
 Returns available pins. More...
 
def map_pin (self, abstract_pin_id, physical_pin_id)
 Maps a pin number to a physical device pin. More...
 
def mapped_pins (self)
 Returns a dictionary containing the mapped pins. More...
 
def set_pin_interpolation (self, pin, read_min, read_max, write_min, write_max)
 Interpolates input and output values for pin. More...
 
def set_pin_direction (self, pin, direction)
 Sets pin pin to direction. More...
 
def pin_direction (self, pin)
 Gets the ahio.Direction this pin was set to. More...
 
def set_pin_type (self, pin, ptype)
 Sets pin pin to type. More...
 
def pin_type (self, pin)
 Gets the ahio.PortType this pin was set to. More...
 
def write (self, pin, value, pwm=False)
 Sets the output to the given value. More...
 
def read (self, pin)
 Reads value from pin pin. More...
 
def analog_references (self)
 Possible values for analog reference. More...
 
def set_analog_reference (self, reference, pin=None)
 Sets the analog reference to reference More...
 
def analog_reference (self, pin=None)
 Returns the analog reference. More...
 
def set_pwm_frequency (self, frequency, pin=None)
 Sets PWM frequency, if supported by hardware. More...
 

Detailed Description

Definition at line 38 of file snap7.py.

Member Function Documentation

§ __enter__()

def ahio.drivers.snap7.Driver.__enter__ (   self)

Definition at line 41 of file snap7.py.

§ __exit__()

def ahio.drivers.snap7.Driver.__exit__ (   self,
  exc_type,
  exc_value,
  traceback 
)

Definition at line 44 of file snap7.py.

§ analog_references()

def ahio.drivers.snap7.Driver.analog_references (   self)

Definition at line 138 of file snap7.py.

§ available_pins()

def ahio.drivers.snap7.Driver.available_pins (   self)

Definition at line 93 of file snap7.py.

§ setup()

def ahio.drivers.snap7.Driver.setup (   self,
  address,
  rack = 0,
  slot = 1,
  port = 102 
)

Connects to a Siemens S7 PLC.

Connects to a Siemens S7 using the Snap7 library. See the snap7 documentation for supported models and more details.

It's not currently possible to query the device for available pins, so available_pins() returns an empty list. Instead, you should use map_pin() to map to a Merker, Input or Output in the PLC. The internal id you should use is a string following this format: '[DMQI][XBWD][0-9]+.?[0-9]*' where:

  • [DMQI]: D for DB, M for Merker, Q for Output, I for Input
  • [XBWD]: X for bit, B for byte, W for word, D for dword
  • [0-9]+: Address of the resource
  • [0-9]*: Bit of the address (type X only, ignored in others)

For example: 'IB100' will read a byte from an input at address 100 and 'MX50.2' will read/write bit 2 of the Merker at address 50. It's not allowed to write to inputs (I), but you can read/write Outpus, DBs and Merkers. If it's disallowed by the PLC, an exception will be thrown by python-snap7 library.

For this library to work, it might be needed to change some settings in the PLC itself. See the snap7 documentation for more information. You also need to put the PLC in RUN mode. Not however that having a Ladder program downloaded, running and modifying variables will probably interfere with inputs and outputs, so put it in RUN mode, but preferably without a downloaded program.

  • address IP address of the module.
  • rack rack where the module is installed.
  • slot slot in the rack where the module is installed.
  • port port the PLC is listenning to.
Exceptions
RuntimeErrorif something went wrong
anyexception thrown by snap7's methods.

Definition at line 89 of file snap7.py.


The documentation for this class was generated from the following file: