MATES / Modular Automatic Test Equipment System API  2.5.0.0
mates_test_18.py
1 import mates
2 
3 
4 class Dio3(mates.Mates):
5  """Represents one MATES-DIO3-MK1 node."""
6 
7  def __init__(self):
8  super(Dio3, self).__init__("proxy.mon", 1)
9  self.node = None
10  for node in (self.mates_dio3_mk1_1, self.mates_dio3_mk1_2):
11  # Find first DIO3 node accessible on the bus.
12  if self.discover_node(node):
13  self.node = node
14  break
15 
16  def get_din(self, channel):
17  return super(Dio3, self).get_din(self.node, channel)
18 
19  def set_dout(self, channel, value):
20  super(Dio3, self).set_dout(self.node, channel, value)
21 
22  def __getitem__(self, idx):
23  return self.get_din(idx)
24 
25  def __setitem__(self, idx, val):
26  self.set_dout(idx, val)
27 
28 
29 # First, make sure the node we are using is connected.
30 m = mates.Mates("proxy.mon", 1)
31 if m.discover_node(m.mates_dio3_mk1_1):
32  m.close()
33 
34  # The with statement below handles opening and closing of
35  # the MATES handle. See Mates class constructor for details.
36  with Dio3() as d:
37  print("First channel: {0}".format(d[0]))
38  print("Second channel: {0}".format(d[1]))
39  d[2] = 0
40  d[3] = 1
41  # If we have loopback, then the values below will be
42  # the same as the ones set.
43  print(d[2])
44  print(d[3])
45 else:
46  m.close()