Skip to content

Commit 5649bca

Browse files
authored
Merge pull request #3 from Mesh-ch/pulse_digital
pulse digital IO
2 parents a15f00b + c6c1c5a commit 5649bca

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/abb_robot_client/rws.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,19 @@ def set_digital_io(self, signal: str, value: Union[bool, int], network: str = "L
432432
lvalue = "1" if bool(value) else "0"
433433
payload = {"lvalue": lvalue}
434434
_res = self._do_post("rw/iosystem/signals/" + network + "/" + unit + "/" + signal + "?action=set", payload)
435+
436+
def pulse_digital_io(self, signal: str, duration: int, network: str = "", unit: str = ""):
437+
"""
438+
Pulse a digital IO signal for a specified duration. The signal will be set to ON for the duration and then set back to OFF.
435439
440+
:param signal: The name of the signal
441+
:param duration: Duration of the pulse in milliseconds
442+
:param network: The network the signal is on. The default `Local` will work for most signals.
443+
:param unit: The drive unit of the signal. The default `DRV_1` will work for most signals.
444+
"""
445+
payload = {"lvalue": "1", "mode": "pulse", "Pulses": "1", "ActivePulse": duration}
446+
_res = self._do_post("rw/iosystem/signals/" + network + "/" + unit + "/" + signal + "?action=set", payload)
447+
436448
def get_analog_io(self, signal: str, network: str = "Local", unit: str = "DRV_1") -> float:
437449
"""
438450
Get the value of an analog IO signal.

src/abb_robot_client/rws2.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,22 @@ def set_digital_io(self, signal: str, value: bool | int, network: str = "", unit
367367
else:
368368
url = f"rw/iosystem/signals/{signal}/set-value?mastership=implicit"
369369
_res = self._do_post(url, payload)
370+
371+
def pulse_digital_io(self, signal: str, duration: int, network: str = "", unit: str = ""):
372+
"""
373+
Pulse a digital IO signal for a specified duration. The signal will be set to ON for the duration and then set back to OFF.
374+
375+
:param signal: The name of the signal
376+
:param duration: Duration of the pulse in milliseconds
377+
:param network: The network the signal is on. The default `Local` will work for most signals.
378+
:param unit: The drive unit of the signal. The default `DRV_1` will work for most signals.
379+
"""
380+
payload = {"lvalue": "1", "mode": "pulse", "Pulses": "1", "ActivePulse": duration}
381+
if network and unit:
382+
url = f"rw/iosystem/signals/{network}/{unit}/{signal}/set-value?mastership=implicit"
383+
else:
384+
url = f"rw/iosystem/signals/{signal}/set-value?mastership=implicit"
385+
_res = self._do_post(url, payload)
370386

371387
def get_analog_io(self, signal: str, network: str = "", unit: str = "") -> float:
372388
"""

src/abb_robot_client/rws_mock.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ def get_digital_io(self, signal: str, network: str = "", unit: str = "") -> int:
154154
def set_digital_io(self, signal: str, value: bool | int, network: str = "", unit: str = "") -> None:
155155
self._dio[signal] = 1 if bool(value) else 0
156156

157+
def pulse_digital_io(self, signal: str, duration: int, network: str = "", unit: str = ""):
158+
self._dio[signal] = 1
159+
# In a real implementation you'd wait `duration` ms, but for a mock we just reset immediately
160+
self._dio[signal] = 0
161+
157162
def get_analog_io(self, signal: str, network: str = "", unit: str = "") -> float:
158163
return float(self._aio.get(signal, 0.0))
159164

0 commit comments

Comments
 (0)