You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.9 KiB
68 lines
1.9 KiB
7 years ago
|
import gex
|
||
|
|
||
7 years ago
|
CMD_WRITE = 0
|
||
|
CMD_SET = 1
|
||
|
CMD_CLEAR = 2
|
||
|
CMD_TOGGLE = 3
|
||
|
CMD_PULSE = 4
|
||
|
|
||
7 years ago
|
class DOut(gex.Unit):
|
||
|
"""
|
||
|
Digital output port.
|
||
|
Pins are represented by bits of a control word, right-aligned.
|
||
|
|
||
|
For example, if pins C6, C5 and C0 are selected for the unit,
|
||
|
calling the "set" function with a word 0b111 will set all three to 1,
|
||
|
0b100 will set only C6.
|
||
|
"""
|
||
|
|
||
|
def _type(self):
|
||
|
return 'DO'
|
||
|
|
||
7 years ago
|
def write(self, pins:int, confirm=True):
|
||
7 years ago
|
""" Set pins to a value - packed, as int """
|
||
7 years ago
|
pb = gex.PayloadBuilder()
|
||
|
pb.u16(pins)
|
||
7 years ago
|
self._send(CMD_WRITE, pb.close(), confirm=confirm)
|
||
7 years ago
|
|
||
7 years ago
|
def set(self, pins=1, confirm=True):
|
||
7 years ago
|
""" Set pins high - packed, int or list """
|
||
7 years ago
|
pb = gex.PayloadBuilder()
|
||
7 years ago
|
pb.u16(self.pins2int(pins))
|
||
7 years ago
|
self._send(CMD_SET, pb.close(), confirm=confirm)
|
||
7 years ago
|
|
||
7 years ago
|
def clear(self, pins=1, confirm=True):
|
||
7 years ago
|
""" Set pins low - packed, int or list """
|
||
7 years ago
|
pb = gex.PayloadBuilder()
|
||
7 years ago
|
pb.u16(self.pins2int(pins))
|
||
7 years ago
|
self._send(CMD_CLEAR, pb.close(), confirm=confirm)
|
||
7 years ago
|
|
||
7 years ago
|
def toggle(self, pins=1, confirm=True):
|
||
7 years ago
|
""" Toggle pins - packed, int or list """
|
||
7 years ago
|
pb = gex.PayloadBuilder()
|
||
7 years ago
|
pb.u16(self.pins2int(pins))
|
||
7 years ago
|
self._send(CMD_TOGGLE, pb.close(), confirm=confirm)
|
||
|
|
||
7 years ago
|
def pulse_ms(self, ms, pins=0b01, active=True, confirm=True):
|
||
7 years ago
|
""" Send a pulse with length 1-65535 ms on selected pins """
|
||
|
pb = gex.PayloadBuilder()
|
||
|
pb.u16(self.pins2int(pins))
|
||
|
pb.bool(active)
|
||
|
pb.bool(False)
|
||
7 years ago
|
pb.u16(ms)
|
||
7 years ago
|
self._send(CMD_PULSE, pb.close(), confirm=confirm)
|
||
|
|
||
7 years ago
|
def pulse_us(self, us, pins=1, active=True, confirm=True):
|
||
7 years ago
|
""" Send a pulse of 1-999 us on selected pins """
|
||
|
pb = gex.PayloadBuilder()
|
||
|
pb.u16(self.pins2int(pins))
|
||
|
pb.bool(active)
|
||
|
pb.bool(True)
|
||
7 years ago
|
pb.u16(us)
|
||
7 years ago
|
self._send(CMD_PULSE, pb.close(), confirm=confirm)
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|