Skip to content

Commit 53f932e

Browse files
committed
[feat] support all tgpio modbus api use 503 port
1 parent 0986871 commit 53f932e

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

xarm/core/wrapper/uxbus_cmd.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(self, set_feedback_key_tranid=None):
4242
self._last_modbus_comm_time = time.monotonic()
4343
self._feedback_type = 0
4444
self._set_feedback_key_tranid = set_feedback_key_tranid
45+
self.tgpio_set_modbus_func = self.tgpio_set_modbus
4546

4647
@property
4748
def last_comm_time(self):
@@ -881,15 +882,15 @@ def gripper_modbus_w16s(self, addr, value, count):
881882
txdata += convert.u16_to_bytes(count)
882883
txdata += bytes([count * 2])
883884
txdata += value
884-
ret = self.tgpio_set_modbus(txdata, count * 2 + 7)
885+
ret = self.tgpio_set_modbus_func(txdata, count * 2 + 7)
885886
return ret
886887

887888
def gripper_modbus_r16s(self, addr, count):
888889
txdata = bytes([XCONF.GRIPPER_ID])
889890
txdata += bytes([0x03])
890891
txdata += convert.u16_to_bytes(addr)
891892
txdata += convert.u16_to_bytes(count)
892-
ret = self.tgpio_set_modbus(txdata, 6)
893+
ret = self.tgpio_set_modbus_func(txdata, 6)
893894
return ret
894895

895896
def gripper_modbus_set_en(self, value):
@@ -1320,15 +1321,15 @@ def track_modbus_w16s(self, addr, value, length):
13201321
txdata += convert.u16_to_bytes(length)
13211322
txdata += bytes([length * 2])
13221323
txdata += value
1323-
ret = self.tgpio_set_modbus(txdata, length * 2 + 7, host_id=XCONF.LINEER_TRACK_HOST_ID, limit_sec=0.001)
1324+
ret = self.tgpio_set_modbus_func(txdata, length * 2 + 7, host_id=XCONF.LINEER_TRACK_HOST_ID, limit_sec=0.001)
13241325
return ret
13251326

13261327
def track_modbus_r16s(self, addr, length, fcode=0x03):
13271328
txdata = bytes([XCONF.TRACK_ID])
13281329
txdata += bytes([fcode])
13291330
txdata += convert.u16_to_bytes(addr)
13301331
txdata += convert.u16_to_bytes(length)
1331-
ret = self.tgpio_set_modbus(txdata, 6, host_id=XCONF.LINEER_TRACK_HOST_ID, limit_sec=0.001)
1332+
ret = self.tgpio_set_modbus_func(txdata, 6, host_id=XCONF.LINEER_TRACK_HOST_ID, limit_sec=0.001)
13321333
return ret
13331334

13341335
def iden_tcp_load(self, estimated_mass=0):

xarm/wrapper/xarm_api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,6 +3001,9 @@ def set_control_modbus_baudrate(self, baud):
30013001
"""
30023002
return self._arm.set_control_modbus_baudrate(baud)
30033003

3004+
def set_tgpio_modbus_use_503_port(self, use_503_port=True):
3005+
return self._arm.set_tgpio_modbus_use_503_port(use_503_port)
3006+
30043007
def getset_tgpio_modbus_data(self, datas, min_res_len=0, host_id=9, is_transparent_transmission=False, use_503_port=False, **kwargs):
30053008
"""
30063009
Send the modbus data to the tool gpio

xarm/x3/base.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,19 +2510,27 @@ def set_control_modbus_baudrate(self, baud):
25102510
self.log_api_info('API -> set_control_modbus_baudrate -> code={}'.format(code), code=code)
25112511
return code
25122512

2513+
def set_tgpio_modbus_use_503_port(self, use_503_port=True):
2514+
if use_503_port:
2515+
if not self.connected_503 and self.connect_503() != 0:
2516+
self.arm_cmd.tgpio_set_modbus_func = self.arm_cmd.tgpio_set_modbus
2517+
self.log_api_info('API -> set_tgpio_modbus_use_503_port -> code={}'.format(APIState.RET_IS_INVALID), code=APIState.RET_IS_INVALID)
2518+
return APIState.RET_IS_INVALID
2519+
self.arm_cmd.tgpio_set_modbus_func = self.arm_cmd_503.tgpio_set_modbus
2520+
else:
2521+
self.arm_cmd.tgpio_set_modbus_func = self.arm_cmd.tgpio_set_modbus
2522+
return 0
2523+
25132524
def getset_tgpio_modbus_data(self, datas, min_res_len=0, ignore_log=False, host_id=XCONF.TGPIO_HOST_ID, is_transparent_transmission=False, use_503_port=False, **kwargs):
25142525
if not self.connected:
25152526
return APIState.NOT_CONNECTED, []
25162527
is_tt = kwargs.get('is_tt', is_transparent_transmission)
2517-
if is_tt:
2518-
if use_503_port:
2519-
if not self.connected_503 and self.connect_503() != 0:
2520-
return APIState.NOT_CONNECTED, []
2521-
ret = self.arm_cmd_503.tgpio_set_modbus(datas, len(datas), host_id=host_id, is_transparent_transmission=True)
2522-
else:
2523-
ret = self.arm_cmd.tgpio_set_modbus(datas, len(datas), host_id=host_id, is_transparent_transmission=True)
2528+
if use_503_port:
2529+
if not self.connected_503 and self.connect_503() != 0:
2530+
return APIState.NOT_CONNECTED, []
2531+
ret = self.arm_cmd_503.tgpio_set_modbus_func(datas, len(datas), host_id=host_id, is_transparent_transmission=is_tt)
25242532
else:
2525-
ret = self.arm_cmd.tgpio_set_modbus(datas, len(datas), host_id=host_id)
2533+
ret = self.arm_cmd.tgpio_set_modbus_func(datas, len(datas), host_id=host_id, is_transparent_transmission=is_tt)
25262534
ret[0] = self._check_modbus_code(ret, min_res_len + 2, host_id=host_id)
25272535
if not ignore_log:
25282536
self.log_api_info('API -> getset_tgpio_modbus_data -> code={}, response={}'.format(ret[0], ret[2:]), code=ret[0])

0 commit comments

Comments
 (0)