30 ahioDriverInfo.AVAILABLE =
False 44 def __exit__(self, exc_type, exc_value, traceback):
89 def setup(self, address, rack=0, slot=1, port=102):
90 self.
_client = snap7.client.Client()
91 self.
_client.connect(address, rack, slot, port)
96 def _set_pin_direction(self, pin, direction):
98 if direction != d
and not (type(d)
is list
and direction
in d):
99 raise RuntimeError(
'Port %s does not support this Direction' % pin)
101 def _pin_direction(self, pin):
103 'D': [ahio.Direction.Input, ahio.Direction.Output],
104 'M': [ahio.Direction.Input, ahio.Direction.Output],
105 'Q': ahio.Direction.Output,
106 'I': ahio.Direction.Input
109 def _set_pin_type(self, pin, ptype):
110 raise RuntimeError(
'Hardware does not support changing the pin type')
112 def _pin_type(self, pin):
113 raise RuntimeError(
'Hardware does not support querying the pin type')
115 def _write(self, pin, value, pwm):
117 raise RuntimeError(
'Pin does not support PWM')
119 raise RuntimeError(
'Can not write to Input')
122 ahio.LogicValue.High: 1,
123 ahio.LogicValue.Low: 0
127 def _read(self, pin):
132 0: ahio.LogicValue.Low,
133 1: ahio.LogicValue.High
141 def _set_analog_reference(self, reference, pin):
142 raise RuntimeError(
'Hardware does not support setting analog ref')
144 def _analog_reference(self, pin):
147 def _set_pwm_frequency(self, frequency, pin):
149 'Setting PWM frequency is not supported by hardware')
151 def _parse_port_name(self, s):
154 'D': snap7.snap7types.S7AreaDB,
155 'M': snap7.snap7types.S7AreaMK,
156 'Q': snap7.snap7types.S7AreaPA,
157 'I': snap7.snap7types.S7AreaPE
159 length = {
'X': 1,
'B': 1,
'W': 2,
'D': 4}[s[1]]
160 start = int(s.split(
'.')[0][2:])
161 bit = int(s.split(
'.')[1])
if s[1] ==
'X' else None 164 'get':
lambda m: snap7.util.get_bool(m, 0, bit),
165 'set':
lambda m, v: snap7.util.set_bool(m, 0, bit, v)
168 'get':
lambda m: snap7.util.get_int(m, 0),
169 'set':
lambda m, v: snap7.util.set_int(m, 0, v)
172 'get':
lambda m: snap7.util.get_int(m, 0),
173 'set':
lambda m, v: snap7.util.set_int(m, 0, v)
176 'get':
lambda m: snap7.util.get_dword(m, 0),
177 'set':
lambda m, v: snap7.util.set_dword(m, 0, v)
180 return (area, dtype, start, length)
182 def _get_memory(self, mem):
183 m = self._client.read_area(mem[0], 0, mem[2], mem[3])
184 return mem[1][
'get'](m)
186 def _set_memory(self, mem, value):
187 m = self._client.read_area(mem[0], 0, mem[2], mem[3])
188 mem[1][
'set'](m, value)
189 self._client.write_area(mem[0], 0, mem[2], m)
def __exit__(self, exc_type, exc_value, traceback)
def _set_memory(self, mem, value)
def _pin_direction(self, pin)
Abstract class containing information about the driver.
def _get_memory(self, mem)
def analog_references(self)
def _parse_port_name(self, s)
Contains abstract classes that should be implemented by drivers.
def setup(self, address, rack=0, slot=1, port=102)
Connects to a Siemens S7 PLC.