-
Notifications
You must be signed in to change notification settings - Fork 112
/
3006-standard_modbus_tcp.py
66 lines (51 loc) · 1.76 KB
/
3006-standard_modbus_tcp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
# Software License Agreement (BSD License)
#
# Copyright (c) 2023, UFACTORY, Inc.
# All rights reserved.
#
# Author: Vinman <[email protected]> <[email protected]>
"""
Description: standard modbus tcp example
1. requires firmware 2.1.0 and above support
"""
import os
import sys
import time
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../..'))
from xarm.wrapper import XArmAPI
#######################################################
"""
Just for test example
"""
if len(sys.argv) >= 2:
ip = sys.argv[1]
else:
try:
from configparser import ConfigParser
parser = ConfigParser()
parser.read('../robot.conf')
ip = parser.get('xArm', 'ip')
except:
ip = input('Please input the xArm ip address:')
if not ip:
print('input error, exit')
sys.exit(1)
########################################################
arm = XArmAPI(ip, is_radian=True)
arm.motion_enable(enable=True)
arm.set_mode(0)
arm.set_state(state=0)
code, ret = arm.read_input_bits(0x00, 16)
print('cgpio_digital_input, code={}, ret={}'.format(code, ret))
code = arm.write_multiple_coil_bits(0x00, [0] * 16)
print('write_multiple_coil_bits, code={}'.format(code))
code, ret = arm.read_coil_bits(0x00, 16)
print('cgpio_digital_output, code={}, ret={}'.format(code, ret))
code = arm.write_multiple_coil_bits(0x00, [1, 0, 1, 0, 1, 1, 0, 1])
print('write_multiple_coil_bits, code={}'.format(code))
code, ret = arm.read_coil_bits(0x00, 16)
print('cgpio_digital_output, code={}, ret={}'.format(code, ret))
code, ret = arm.read_input_registers(0x40, 9, is_signed=True)
ret = ret if code != 0 else list(map(lambda x: x / 10, ret))
print('x/y/z/roll/pitch/yaw/rx/ry/rz, code={}, ret={}'.format(code, ret))