Skip to content

Reading and Writing

This page contains information on all functions present within read_write.py and aims to give a clear understanding both of what these functions do and the requirements for any data to be input into them.

Functions

read_write_control

Source code in actions\read_write.py
  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
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
class read_write_control():

    def __init__(self, arm:XArmAPI):
        self.arm = arm

    def read_coil_bits(self, addr, quantity):
        """
        ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Read Coils (0x01)

        Args:
            addr: the starting address of the register to be read

            quantity: number of registers

        Returns:
            out (tuple[int, list[int]]): tuple((code, bits)) returned result is only corrent when code is 0.

            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

                Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)

            bits (list[int]): values read from the registers
        """
        return self.arm.read_coil_bits(addr, quantity)

    def read_input_bits(self, addr, quantity):
        """
        ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Read Discrete Inputs (0x02)

        Args:
            addr: the starting address of the register to be read

            quantity: number of registers

        Returns:
            out (tuple[int, list[int]]): tuple((code, bits)) returned result is only corrent when code is 0.

            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

                Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)

            bits (list[int]): values read from the registers
        """
        return self.arm.read_input_bits(addr, quantity)

    def read_holding_registers(self, addr, quantity, is_signed=False):
        """
        ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Read Holding Registers (0x03)

        Args:
            addr: the starting address of the register to be read

            quantity: number of registers

            is_signed: whether to convert the read register value into a signed form

        Returns:
            out (tuple[int, list[int]]): tuple((code, bits)) returned result is only corrent when code is 0.

            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

                Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)

            bits (list[int]): values read from the registers
        """
        return self.arm.read_holding_registers(addr, quantity, is_signed)

    def read_input_registers(self, addr, quantity, is_signed=False):
        """
        ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Read Input Registers (0x04)

        Args:
            addr: the starting address of the register to be read

            quantity: number of registers

            is_signed: whether to convert the read register value into a signed form

        Returns:
            out (tuple[int, list[int]]): tuple((code, bits)) returned result is only corrent when code is 0.

            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

                Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)

            bits (list[int]): values read from the registers
        """
        return self.arm.read_input_registers(addr, quantity, is_signed)

    def write_single_coil_bit(self, addr, bit_val):
        """
        ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Write Single Coil (0x05)

        Args:
            addr: register address

            bit_val: the value to write (0/1)

        Returns:
            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

                Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)
        """
        return self.arm.write_single_coil_bit(addr, bit_val)

    def write_single_holding_register(self, addr, reg_val):
        """
        ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Write Single Holding Register (0x06)

        Args:
            addr: register address

            bit_val: the value to write

        Returns:
            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

                Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)
        """
        return self.arm.write_single_holding_register(addr, reg_val)

    def write_multiple_coil_bits(self, addr, bits):
        """
        ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Write Multiple Coils (0x0F)

        Args:
            addr: the starting address of the register to be written

            bits: array of values to write

        Returns:
            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

                Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)
        """
        return self.arm.write_multiple_coil_bits(addr, bits)

    def write_multiple_holding_registers(self, addr, regs):
        """
        ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Write Multiple Holding Registers (0x10)

        Args:
            addr: the starting address of the register to be written

            regs: array of values to write

        Returns:
            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

                Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)
        """
        return self.arm.write_multiple_holding_registers(addr, regs)

    def mask_write_holding_register(self, addr, and_mask, or_mask):
        """
        ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Mask Write Holding Register (0x16)

        Args:
            addr: register address

            and_mask: mask to be AND with

            or_mask: mask to be OR with

        Returns:
            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

                Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)
        """
        return self.arm.mask_write_holding_register(addr, and_mask, or_mask)

    def write_and_read_holding_registers(self, r_addr, r_quantity, w_addr, w_regs, is_signed=False):
        """
        ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Write and Read Holding Registers (0x17)

        Args:
            r_addr: the starting address of the register to be read

            r_quantity: number of registers to read

            w_addr: the starting address of the register to be written

            w_regs: array of values to write

            is_signed: whether to convert the read register value into a signed form

        Returns:
            out (tuple[int, tuple]): tuple((code, regs)) returned result is only corrent when code is 0.

            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

                Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)

            regs (tuple): register values
        """
        return self.arm.write_and_read_holding_registers(r_addr, r_quantity, w_addr, w_regs, is_signed)

mask_write_holding_register(addr, and_mask, or_mask)

(Standard Modbus TCP) Mask Write Holding Register (0x16)

Parameters:

Name Type Description Default
addr

register address

required
and_mask

mask to be AND with

required
or_mask

mask to be OR with

required

Returns:

Name Type Description
code int

See the API Code Documentation for details.

Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to Standard Modbus TCP

Source code in actions\read_write.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def mask_write_holding_register(self, addr, and_mask, or_mask):
    """
    ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Mask Write Holding Register (0x16)

    Args:
        addr: register address

        and_mask: mask to be AND with

        or_mask: mask to be OR with

    Returns:
        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)
    """
    return self.arm.mask_write_holding_register(addr, and_mask, or_mask)

read_coil_bits(addr, quantity)

(Standard Modbus TCP) Read Coils (0x01)

Parameters:

Name Type Description Default
addr

the starting address of the register to be read

required
quantity

number of registers

required

Returns:

Name Type Description
out tuple[int, list[int]]

tuple((code, bits)) returned result is only corrent when code is 0.

code int

See the API Code Documentation for details.

Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to Standard Modbus TCP

bits list[int]

values read from the registers

Source code in actions\read_write.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def read_coil_bits(self, addr, quantity):
    """
    ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Read Coils (0x01)

    Args:
        addr: the starting address of the register to be read

        quantity: number of registers

    Returns:
        out (tuple[int, list[int]]): tuple((code, bits)) returned result is only corrent when code is 0.

        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)

        bits (list[int]): values read from the registers
    """
    return self.arm.read_coil_bits(addr, quantity)

read_holding_registers(addr, quantity, is_signed=False)

(Standard Modbus TCP) Read Holding Registers (0x03)

Parameters:

Name Type Description Default
addr

the starting address of the register to be read

required
quantity

number of registers

required
is_signed

whether to convert the read register value into a signed form

False

Returns:

Name Type Description
out tuple[int, list[int]]

tuple((code, bits)) returned result is only corrent when code is 0.

code int

See the API Code Documentation for details.

Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to Standard Modbus TCP

bits list[int]

values read from the registers

Source code in actions\read_write.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def read_holding_registers(self, addr, quantity, is_signed=False):
    """
    ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Read Holding Registers (0x03)

    Args:
        addr: the starting address of the register to be read

        quantity: number of registers

        is_signed: whether to convert the read register value into a signed form

    Returns:
        out (tuple[int, list[int]]): tuple((code, bits)) returned result is only corrent when code is 0.

        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)

        bits (list[int]): values read from the registers
    """
    return self.arm.read_holding_registers(addr, quantity, is_signed)

read_input_bits(addr, quantity)

(Standard Modbus TCP) Read Discrete Inputs (0x02)

Parameters:

Name Type Description Default
addr

the starting address of the register to be read

required
quantity

number of registers

required

Returns:

Name Type Description
out tuple[int, list[int]]

tuple((code, bits)) returned result is only corrent when code is 0.

code int

See the API Code Documentation for details.

Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to Standard Modbus TCP

bits list[int]

values read from the registers

Source code in actions\read_write.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def read_input_bits(self, addr, quantity):
    """
    ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Read Discrete Inputs (0x02)

    Args:
        addr: the starting address of the register to be read

        quantity: number of registers

    Returns:
        out (tuple[int, list[int]]): tuple((code, bits)) returned result is only corrent when code is 0.

        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)

        bits (list[int]): values read from the registers
    """
    return self.arm.read_input_bits(addr, quantity)

read_input_registers(addr, quantity, is_signed=False)

(Standard Modbus TCP) Read Input Registers (0x04)

Parameters:

Name Type Description Default
addr

the starting address of the register to be read

required
quantity

number of registers

required
is_signed

whether to convert the read register value into a signed form

False

Returns:

Name Type Description
out tuple[int, list[int]]

tuple((code, bits)) returned result is only corrent when code is 0.

code int

See the API Code Documentation for details.

Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to Standard Modbus TCP

bits list[int]

values read from the registers

Source code in actions\read_write.py
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def read_input_registers(self, addr, quantity, is_signed=False):
    """
    ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Read Input Registers (0x04)

    Args:
        addr: the starting address of the register to be read

        quantity: number of registers

        is_signed: whether to convert the read register value into a signed form

    Returns:
        out (tuple[int, list[int]]): tuple((code, bits)) returned result is only corrent when code is 0.

        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)

        bits (list[int]): values read from the registers
    """
    return self.arm.read_input_registers(addr, quantity, is_signed)

write_and_read_holding_registers(r_addr, r_quantity, w_addr, w_regs, is_signed=False)

(Standard Modbus TCP) Write and Read Holding Registers (0x17)

Parameters:

Name Type Description Default
r_addr

the starting address of the register to be read

required
r_quantity

number of registers to read

required
w_addr

the starting address of the register to be written

required
w_regs

array of values to write

required
is_signed

whether to convert the read register value into a signed form

False

Returns:

Name Type Description
out tuple[int, tuple]

tuple((code, regs)) returned result is only corrent when code is 0.

code int

See the API Code Documentation for details.

Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to Standard Modbus TCP

regs tuple

register values

Source code in actions\read_write.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
def write_and_read_holding_registers(self, r_addr, r_quantity, w_addr, w_regs, is_signed=False):
    """
    ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Write and Read Holding Registers (0x17)

    Args:
        r_addr: the starting address of the register to be read

        r_quantity: number of registers to read

        w_addr: the starting address of the register to be written

        w_regs: array of values to write

        is_signed: whether to convert the read register value into a signed form

    Returns:
        out (tuple[int, tuple]): tuple((code, regs)) returned result is only corrent when code is 0.

        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)

        regs (tuple): register values
    """
    return self.arm.write_and_read_holding_registers(r_addr, r_quantity, w_addr, w_regs, is_signed)

write_multiple_coil_bits(addr, bits)

(Standard Modbus TCP) Write Multiple Coils (0x0F)

Parameters:

Name Type Description Default
addr

the starting address of the register to be written

required
bits

array of values to write

required

Returns:

Name Type Description
code int

See the API Code Documentation for details.

Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to Standard Modbus TCP

Source code in actions\read_write.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def write_multiple_coil_bits(self, addr, bits):
    """
    ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Write Multiple Coils (0x0F)

    Args:
        addr: the starting address of the register to be written

        bits: array of values to write

    Returns:
        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)
    """
    return self.arm.write_multiple_coil_bits(addr, bits)

write_multiple_holding_registers(addr, regs)

(Standard Modbus TCP) Write Multiple Holding Registers (0x10)

Parameters:

Name Type Description Default
addr

the starting address of the register to be written

required
regs

array of values to write

required

Returns:

Name Type Description
code int

See the API Code Documentation for details.

Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to Standard Modbus TCP

Source code in actions\read_write.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
def write_multiple_holding_registers(self, addr, regs):
    """
    ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Write Multiple Holding Registers (0x10)

    Args:
        addr: the starting address of the register to be written

        regs: array of values to write

    Returns:
        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)
    """
    return self.arm.write_multiple_holding_registers(addr, regs)

write_single_coil_bit(addr, bit_val)

(Standard Modbus TCP) Write Single Coil (0x05)

Parameters:

Name Type Description Default
addr

register address

required
bit_val

the value to write (0/1)

required

Returns:

Name Type Description
code int

See the API Code Documentation for details.

Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to Standard Modbus TCP

Source code in actions\read_write.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
def write_single_coil_bit(self, addr, bit_val):
    """
    ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Write Single Coil (0x05)

    Args:
        addr: register address

        bit_val: the value to write (0/1)

    Returns:
        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)
    """
    return self.arm.write_single_coil_bit(addr, bit_val)

write_single_holding_register(addr, reg_val)

(Standard Modbus TCP) Write Single Holding Register (0x06)

Parameters:

Name Type Description Default
addr

register address

required
bit_val

the value to write

required

Returns:

Name Type Description
code int

See the API Code Documentation for details.

Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to Standard Modbus TCP

Source code in actions\read_write.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def write_single_holding_register(self, addr, reg_val):
    """
    ([Standard Modbus TCP](./UF_ModbusTCP_Manual.md)) Write Single Holding Register (0x06)

    Args:
        addr: register address

        bit_val: the value to write

    Returns:
        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            Note: code 129~144 means modbus tcp exception, the actual modbus tcp exception code is (code-0x80), refer to [Standard Modbus TCP](./UF_ModbusTCP_Manual.md)
    """
    return self.arm.write_single_holding_register(addr, reg_val)