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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |