Wiki source code of 08 Communication

Last modified by Iris on 2025/07/24 15:23

Hide last authors
Leo Wei 1.1 1 The VD2 series servo drive has Modbus communication function, which could cooperate with the host computer for parameter modification, parameter query, monitoring volume servo status query and control. The servo drive is used as a slave device.
2
3 = **Modbus communication** =
4
Stone Wu 10.1 5 == Hardware wiring ==
Leo Wei 1.1 6
7 The position of RS485 communication port (take VD2B as an example) is as the figure below.
8
Joey 1.2 9 (% style="text-align:center" %)
Stone Wu 10.1 10 [[image:image-20220608154248-1.png||class="img-thumbnail"]]
Leo Wei 1.1 11
12 Figure 8-1 The position of RS485 communication port of VD2B drive
13
Stone Wu 8.1 14 For the position of the RS485 communication port of other models, see __[[4.5 Communication signal wiring>>https://docs.we-con.com.cn/bin/view/Servo/Manual/02%20VD2%20SA%20Series/04%20Wiring/#HCommunicationsignalwiring]]__.
Leo Wei 1.1 15
16 The servo drive adopts RS485 half-duplex communication mode. The 485 bus should adopt the hand-in-hand structure instead of the star structure or the bifurcated structure. The star structure or bifurcation structure will produce reflected signals, which will affect the 485 communication.
17
18 (% class="table-bordered" %)
Stone Wu 10.1 19 (% class="warning" %)|(% style="text-align:center; vertical-align:middle" %)[[image:image-20220611153134-1.png]]
Leo Wei 1.1 20 |(((
21 ✎The wiring must use shielded twisted pair, stay away from strong electricity, do not run in parallel with the power line, let alone bundle it together!
22
23 ✎In a half-duplex connection, only one servo drive can communicate with the host computer at the same time. If two or more servo drives upload data at the same time, bus competition will occur. Not only will it lead to communication failure, it may also cause some components to generate large currents and damage the components.
24 )))
25
Joey 1.2 26 (% style="text-align:center" %)
Stone Wu 10.1 27 [[image:image-20220608174415-1.png||class="img-thumbnail"]]
Leo Wei 1.1 28
29 Figure 8-2 RS485 communication network wiring diagram
30
31 The terminal of RS485 network should use a terminating resistors of 120Ω to weaken the reflection of the signal. Intermediate networks cannot use terminating resistors.
32
33 No point in the RS485 network can be directly grounded. All devices in the network must be well grounded through their own grounding terminals.
34
35 (% class="table-bordered" %)
Stone Wu 10.1 36 (% class="warning" %)|(% style="text-align:center; vertical-align:middle" %)[[image:image-20220611153144-2.png]]
Iris 15.1 37 |(((
38 The grounding wire cannot form a closed loop under no circumstances.
39 )))
Leo Wei 1.1 40
41 When wiring, consider the drive capability of the computer/PLC and the distance between the computer/PLC and the servo drive. If the drive capacity is insufficient, a repeater is needed.
42
43 = **Modbus communication protocol analysis** =
44
Stone Wu 10.1 45 == Modbus data frame format ==
Leo Wei 1.1 46
47 The VD2 series servo drives currently support the RTU communication format. The typical data frame format is shown in the table.
48
49 (% class="table-bordered" %)
Stone Wu 9.1 50 |=(% rowspan="2" scope="row" style="text-align: center; vertical-align: middle; width: 425px;" %)**There should be a message interval not less than 3.5 characters at the beginning**|=(% style="text-align: center; vertical-align: middle; width: 166px;" %)**Address**|=(% style="text-align: center; vertical-align: middle; width: 189px;" %)**Function code**|=(% style="text-align: center; vertical-align: middle; width: 155px;" %)**Data**|=(% style="text-align: center; vertical-align: middle; width: 158px;" %)**CRC check code**
Leo Wei 1.1 51 |(% style="text-align:center; vertical-align:middle; width:166px" %)1 byte|(% style="text-align:center; vertical-align:middle; width:189px" %)1 byte|(% style="text-align:center; vertical-align:middle; width:155px" %)N bytes|(% style="text-align:center; vertical-align:middle; width:158px" %)2 bytes
52
Stone Wu 10.1 53 == Supported function codes ==
Leo Wei 1.1 54
55 The host reads and writes data to the servo through Modbus RTU format (03, 06 function codes). The corresponding Modbus function codes are as follows:
56
57 (% class="table-bordered" %)
Stone Wu 9.1 58 |=(% style="text-align: center; vertical-align: middle;" %)**Operate**|=(% style="text-align: center; vertical-align: middle;" %)**Command code**
Stone Wu 4.7 59 |(% style="text-align:center; vertical-align:middle" %)Read 16-bit/32-bit function code|(% style="text-align:center; vertical-align:middle" %)0x03
Leo Wei 1.1 60 |(% style="text-align:center; vertical-align:middle" %)Write 16-bit function code|(% style="text-align:center; vertical-align:middle" %)0x06
Stone Wu 4.7 61 |(% style="text-align:center; vertical-align:middle" %)Write 32-bit function code|(% style="text-align:center; vertical-align:middle" %)0x10
Leo Wei 1.1 62
Stone Wu 4.7 63 **Read function code: 0x03**
Leo Wei 1.1 64
65 Request format:
66
Stone Wu 10.1 67 |=(% rowspan="2" %)**Address**|=(% rowspan="2" %)**Function code**|=(% colspan="2" %)**Initial address**|=(% colspan="2" %)**Number of reads**|=(% rowspan="2" %)**CRC check code**
68 |=**high byte**|=**low byte**|=**high byte**|=**low byte**
Stone Wu 4.7 69 |1 byte|03|1 byte|1 byte|1 byte|1 byte|2 bytes
Leo Wei 1.1 70
71 Correct response format:
72
Stone Wu 9.1 73 (% style="width:1055px" %)
Stone Wu 10.1 74 |=(% rowspan="2" %)**Address**|=(% rowspan="2" %)**Function code**|=(% rowspan="2" style="width: 279px;" %)**Number of bytes of returned data**|=(% colspan="2" style="width: 274px;" %)**Register 1**|=(% rowspan="2" style="width: 98px;" %)**…**|=(% rowspan="2" %)**CRC check code**
75 |=(% style="width: 160px;" %)**high byte**|=(% style="width: 114px;" %)**low byte**
Stone Wu 9.1 76 |1 byte|03|(% style="width:279px" %)1 byte|(% style="width:160px" %)1 byte|(% style="width:114px" %)1 byte|(% style="width:98px" %)…|2 bytes
Leo Wei 1.1 77
Stone Wu 4.7 78 **Write function code: 0x06**
Leo Wei 1.1 79
80 Request format:
81
Stone Wu 4.8 82 |(% rowspan="2" %)**Address**|(% rowspan="2" %)**Function code**|(% colspan="2" %)(((
83 **Register address**
84 )))|(% colspan="2" %)**Data**|(% rowspan="2" %)**CRC check code**
Stone Wu 4.7 85 |**high byte**|**low byte**|**high byte**|**low byte**
86 |1 byte|06|1 byte|1 byte|1 byte|1 byte|2 bytes
Leo Wei 1.1 87
88 Response format:
89
Stone Wu 10.1 90 |=(% rowspan="2" %)**Address**|=(% rowspan="2" %)**Function code**|=(% colspan="2" %)**Register address**|=(% colspan="2" %)**Data**|=(% rowspan="2" %)**CRC check code**
91 |=**high byte**|=**low byte**|=**high byte**|=**low byte**
Stone Wu 4.7 92 |1 byte|06|1 byte|1 byte|1 byte|1 byte|2 bytes
Leo Wei 1.1 93
94 If the setting is successful, the original is returned
95
Stone Wu 10.1 96 |=(% rowspan="2" style="width: 551px;" %)**There should be a message interval not less than 3.5 characters at the beginning**|=(% style="width: 114px;" %)**Address**|=(% style="width: 127px;" %)**Function code**|=(% style="width: 104px;" %)**Data**|=(% style="width: 180px;" %)**CRC check code**
Stone Wu 9.1 97 |(% style="width:114px" %)1 byte|(% style="width:127px" %)1 byte|(% style="width:104px" %)N bytes|(% style="width:180px" %)2 bytes
Leo Wei 1.1 98
Stone Wu 10.1 99 == (% style="color:inherit; font-family:inherit; font-size:26px" %)CRC check(%%) ==
Leo Wei 1.1 100
101 The servo uses a 16-bit CRC check, and the host computer must also use the same check rule, otherwise the CRC check will make mistake. When transmitting, the low bit is in the front and the high bit is at the back. The CRC code are as follows:
102
103 {{code language="LUA"}}
Iris 15.2 104 Uint16 CRC16_Calc(Uint8 *pBuf, Uint16 uLen)
Leo Wei 1.1 105 {
106
107     Uint16 crc = 0xffff;
108
109     Uint16 i;
110
111
112
113   while(uLen--)
114
115   {
116
117     crc ^=(Uint16) *pBuf++;
118
119     for(i=0; i<8; i++)
120
121     {
122
123       if(crc & 0x0001)
124
125 {
126
127 crc = (crc >> 1) ^ 0xa001;
128
129 }
130
131 else
132
133 {
134
135 crc = crc >> 1;
136
137 }
138
Iris 15.2 139 }
Leo Wei 1.1 140
141     }
142
143   }
144
145   return crc;
146
147 }
148
149 {{/code}}
150
151 == **Error response frame** ==
152
153 (% class="table-bordered" %)
Stone Wu 9.1 154 |=(% style="text-align: center; vertical-align: middle;" %)**Address**|=(% style="text-align: center; vertical-align: middle;" %)**Function code**|=(% style="text-align: center; vertical-align: middle;" %)**Error code**|=(% style="text-align: center; vertical-align: middle;" %)**CRC check code**
Leo Wei 1.1 155 |(% style="text-align:center; vertical-align:middle" %)1 byte|(% style="text-align:center; vertical-align:middle" %)Command code+0x80|(% style="text-align:center; vertical-align:middle" %)Error code|(% style="text-align:center; vertical-align:middle" %)2 bytes
156
157 When an error occurs, set the function code bit7 issued by the host to 1, and return (for example, 0x03 returns 0x83, 0x06 returns 0x86); the description of the error code are as follows.
158
159 (% class="table-bordered" %)
Stone Wu 9.1 160 |=(% style="text-align: center; vertical-align: middle;" %)**Error code**|=(% style="text-align: center; vertical-align: middle;" %)**Coding description**
Leo Wei 1.1 161 |(% style="text-align:center; vertical-align:middle" %)0x0001|(% style="text-align:center; vertical-align:middle" %)Illegal command code
162 |(% style="text-align:center; vertical-align:middle" %)0x0002|(% style="text-align:center; vertical-align:middle" %)Illegal data address
163 |(% style="text-align:center; vertical-align:middle" %)0x0003|(% style="text-align:center; vertical-align:middle" %)Illegal data
164 |(% style="text-align:center; vertical-align:middle" %)0x0004|(% style="text-align:center; vertical-align:middle" %)Slave device failure
165
166 == **Communication example** ==
167
Stone Wu 4.10 168 **03 Function code read**
169
Leo Wei 1.1 170 Read the monitoring volume U0-31 bus voltage, the Modbus register address corresponding to this variable is 7716 (0x1E24)
171
172 Request format:
173
Stone Wu 10.1 174 |=(% rowspan="2" %)**Address**|=(% rowspan="2" %)**Function code**|=(% colspan="2" %)**Register address**|=(% colspan="2" %)**Data**|=(% rowspan="2" %)**CRC check code**
175 |=**high byte**|=**low byte**|=**high byte**|=**low byte**
Stone Wu 4.10 176 |01|03|1E|24|00|01|C2 29
Leo Wei 1.1 177
178 The slave responds normally:
179
Stone Wu 10.1 180 |=(% rowspan="2" %)**Address**|=(% rowspan="2" %)**Function code**|=(% rowspan="2" %)**Number of bytes**|=(% colspan="2" %)**Data**|=(% rowspan="2" %)**CRC high byte**
181 |=**high byte**|=**low byte**
Stone Wu 4.10 182 |01|03|02|0C|4F|FC B0
Leo Wei 1.1 183
Stone Wu 4.10 184 For example: The value read is 0x0C4F, which means that the voltage is 315.1V.
Leo Wei 1.1 185
186 **06 Function Code Write**
187
Stone Wu 4.11 188 P1-10 the maximum speed threshold is set to 3000rpm. This variable corresponds to the Modbus address: 266 (0x010A)
Leo Wei 1.1 189
190 Request format:
191
Stone Wu 10.1 192 |=(% rowspan="2" %)**Address**|=(% rowspan="2" %)**Function code**|=(% colspan="2" %)**Register address**|=(% colspan="2" %)**Data**|=(% rowspan="2" %)**CRC check code**
193 |=**high byte**|=**low byte**|=**high byte**|=**low byte**
Stone Wu 4.11 194 |01|06|01|0A|0B|B8|AF, 76
Leo Wei 1.1 195
196 The slave responds normally:
197
Stone Wu 10.1 198 |=(% rowspan="2" %)**Address**|=(% rowspan="2" %)**Function code**|=(% colspan="2" %)**Register address**|=(% colspan="2" %)**Data**|=(% rowspan="2" %)**CRC check code**
199 |=**high byte**|=**low byte**|=**high byte**|=**low byte**
Stone Wu 4.11 200 |01|06|01|0A|0B|B8|AF, 76
Leo Wei 1.1 201
Stone Wu 4.14 202 **10 Function code write**
203
204 P07-09 set the 1st segment position to 2000, and this variable corresponds to the Modbus address: 1801 (0x0709).
205
206 Request format:
207
Stone Wu 10.1 208 |=(% rowspan="2" %)**Address**|=(% rowspan="2" %)**Function code**|=(% colspan="2" %)**Initial address**|=(% colspan="2" %)**Number of register**|=(% rowspan="2" %)**Number of data**|=(% colspan="2" %)**Data 1**|=(% colspan="2" %)**Data 2**|=(% colspan="2" %)**CRC check code**
209 |=**high byte**|=**low byte**|=**high byte**|=**low byte**|=**high byte**|=**low byte**|=**high byte**|=**low byte**|=**high byte**|=**low byte**
Stone Wu 4.14 210 |01|10|07|09|00|02|04|00|00|07|D0|16|59
211
212 The slave responds normally:
213
Stone Wu 10.1 214 |=(% rowspan="2" %)**Address**|=(% rowspan="2" %)**Function code**|=(% colspan="2" %)**Register address**|=(% colspan="2" %)**Data**|=(% colspan="2" %)**CRC check code**
215 |=**high byte**|=**low byte**|=**high byte**|=**low byte**|=**high byte**|=**low byte**
Stone Wu 4.14 216 |01|10|07|09|00|02|90|BE
217
Leo Wei 1.1 218 = **Servo communication parameter setting** =
219
Joey 1.2 220 (% style="text-align:center" %)
Stone Wu 10.1 221 (((
222 (% class="wikigeneratedid img-thumbnail" style="display:inline-block" %)
223 [[Figure 8-3 Modbus communication parameter setting process>>image:image-20220608174504-2.png||id="Iimage-20220608174504-2.png"]]
224 )))
Leo Wei 1.1 225
Stone Wu 9.1 226 **Set the servo address P12-1**
Leo Wei 1.1 227
228 When multiple servos are in network communication, each servo can only have a unique address, otherwise it will cause abnormal communication and fail to communicate.
229
Stone Wu 9.1 230 **Set the serial port baud rate P12-2**
Leo Wei 1.1 231
232 The communication rate of the servo and the communication rate of the host computer must be set consistently, otherwise the communication cannot be carried out.
233
Stone Wu 9.1 234 **Set the serial port data format P12-3**
Leo Wei 1.1 235
236 The data bit check methods of servo communication are:
237
Stone Wu 4.15 238 * Odd parity
239 * Even parity
240 * No parity
241 * The stop bit: 1 stop bit and 2 stop bits.
Leo Wei 1.1 242
243 The data frame format of the servo and the host computer must be consistent, otherwise the communication cannot be carried out.
244
Stone Wu 9.1 245 **Set that whether the function code changed by Modbus communication is written into EEPROM in real time [P12-4]**
Leo Wei 1.1 246
247 When the host computer modifies the servo function code through communication, it can choose to store it in EEPROM in real time, which has the function of power-off storage.
248
249 If the value of the function code only needs to be rewritten once, and the value is used later, the function of real-time writing of the function code to EEPROM can be enabled.
250
251 If you need to change the value of the function code frequently, it is recommended to turn off the function of real-time writing to EERPOM of function code, otherwise the EEPROM will be shortened due to frequent erasing and writing of the EEPROM.
252
253 (% class="table-bordered" %)
Stone Wu 10.1 254 (% class="warning" %)|(% style="text-align:center; vertical-align:middle" %)[[image:image-20220611153214-3.png]]
Iris 17.1 255 |After the EEPROM is damaged, the servo will have an non-resettable fault!
Leo Wei 1.1 256
Stone Wu 9.1 257 **Set the high and low order of the 32-bit monitoring data**
Leo Wei 1.1 258
259 Part of the monitoring volume is 32-bit length and occupies 2 consecutive bias numbers. The user needs to set the order of the data high bit and low bit correctly, otherwise it will cause data reading and writing errors!
260
261 For example, U0-54 (position within 1 circle of absolute encoder) occupies two consecutive offset numbers, which are 0x1E3D and 0x1E3E respectively. Assuming the value of U0-54 is 0x12345678, the correct data sequence bit should be 0x1E3D=0x5678 , 0x1E3E=0x1234 (little endian mode: low byte first, high byte behind.)
262
263 The description of related function codes are as follows.
264
265 (% class="table-bordered" %)
Stone Wu 9.1 266 |=(% style="text-align: center; vertical-align: middle; width: 121px;" %)**Function code**|=(% style="text-align: center; vertical-align: middle; width: 165px;" %)**Name**|=(% style="text-align: center; vertical-align: middle; width: 148px;" %)(((
Leo Wei 1.1 267 **Setting method**
Stone Wu 9.1 268 )))|=(% style="text-align: center; vertical-align: middle; width: 165px;" %)(((
Leo Wei 1.1 269 **Effective time**
Stone Wu 9.1 270 )))|=(% style="text-align: center; vertical-align: middle; width: 109px;" %)**Default value**|=(% style="text-align: center; vertical-align: middle; width: 85px;" %)**Range**|=(% style="text-align: center; vertical-align: middle; width: 224px;" %)**Definition**|=(% style="text-align: center; vertical-align: middle; width: 69px;" %)**Unit**
271 |(% style="text-align:center; vertical-align:middle; width:121px" %)P12-02|(% style="text-align:center; vertical-align:middle; width:165px" %)Baud rate|(% style="text-align:center; vertical-align:middle; width:148px" %)(((
Leo Wei 1.1 272 Operation setting
Stone Wu 9.1 273 )))|(% style="text-align:center; vertical-align:middle; width:165px" %)(((
Leo Wei 1.1 274 Effective immediately
Mora Zhou 13.1 275 )))|(% style="text-align:center; vertical-align:middle; width:109px" %)2|(% style="text-align:center; vertical-align:middle; width:85px" %)0 to 6|(% style="width:224px" %)(((
276 0: 2400bps
277
278 1: 4800bps
279
280 2: 9600bps
281
282 3: 19200bps
283
284 4: 38400bps
285
286 5: 57600bp
287
288 6:115200bps
Stone Wu 9.1 289 )))|(% style="text-align:center; vertical-align:middle; width:69px" %)-
290 |(% style="text-align:center; vertical-align:middle; width:121px" %)P12-03|(% style="text-align:center; vertical-align:middle; width:165px" %)Serial data format|(% style="text-align:center; vertical-align:middle; width:148px" %)(((
Leo Wei 1.1 291 Operation setting
Stone Wu 9.1 292 )))|(% style="text-align:center; vertical-align:middle; width:165px" %)(((
Leo Wei 1.1 293 Effective immediately
Stone Wu 9.1 294 )))|(% style="text-align:center; vertical-align:middle; width:109px" %)0|(% style="text-align:center; vertical-align:middle; width:85px" %)0 to 3|(% style="width:224px" %)(((
Mora Zhou 13.1 295 0: 1 stop bit, no parity
296
297 1: 1 stop bit, odd parity
298
299 2: 1 stop bit, even parity
300
301 3: 2 stop bits, no parity
Stone Wu 9.1 302 )))|(% style="text-align:center; vertical-align:middle; width:69px" %)-
303 |(% style="text-align:center; vertical-align:middle; width:121px" %)P12-04|(% style="text-align:center; vertical-align:middle; width:165px" %)Modbus communication data is written into EEPROM|(% style="text-align:center; vertical-align:middle; width:148px" %)(((
Leo Wei 1.1 304 Operation setting
Stone Wu 9.1 305 )))|(% style="text-align:center; vertical-align:middle; width:165px" %)(((
Leo Wei 1.1 306 Effective immediately
Stone Wu 9.1 307 )))|(% style="text-align:center; vertical-align:middle; width:109px" %)0|(% style="text-align:center; vertical-align:middle; width:85px" %)0 to 1|(% style="width:224px" %)(((
Mora Zhou 13.1 308 0: Do not write to EEPROM, and do not store after power failure;
309
310 1: Write to EEPROM, power-down storage.
Stone Wu 9.1 311 )))|(% style="text-align:center; vertical-align:middle; width:69px" %)-
Mora Zhou 12.1 312 |P12-06|Modbus 32-bit variable big endian and little endian|(((
313 Operation
Leo Wei 1.1 314
Mora Zhou 12.1 315 setting
316 )))|(((
317 Effective
318
319 immediately
320 )))|0|0-1|(((
321 0: Big-endian mode, the lower address stores the higher 16 bits of data, and the higher address stores the lower 16 bits of data
322
323 1: Little-endian mode, the lower address stores the lower 16 bits of data, and the higher address stores the higher 16 bits of data
324 )))|-
325
Leo Wei 1.1 326 = **Modbus communication variable address and value** =
327
Stone Wu 10.1 328 == **Variable address** ==
Leo Wei 1.1 329
330 Modbus registers are divided into two categories:
331
Stone Wu 4.15 332 1. The first category is servo function code parameters (address: 0x0001 to 0x0D08), this part of the register is readable and writable (that is, 0x03 and 0x06 are supported);
333 1. The second category is the monitoring volume of the servo (address: 0x1E01 to 0x2010), this part of the register is only readable (0x03 function is supported).
Leo Wei 1.1 334
335 **Servo function code representation: PXX-YY.**
336
Stone Wu 4.15 337 * XX: represents the function code group number,
338 * YY: represents the bias within the function code group;;
Leo Wei 1.1 339
340 During servo communication, the communication address of the function code is a 16-bit address, which is composed of the function code group number (high 8 bits) + group bias (low 8 bits), for example, the Modbus address corresponding to P12-1 (servo address) is 0x0C01.
341
342 **Servo monitor volume representation: Uxx-yy.**
343
Stone Wu 4.15 344 * xx: represents the monitoring volume group number,
345 * yy: represents the bias within the monitoring volume group;
Leo Wei 1.1 346
347 During Modbus communication, the starting address of the monitoring volume is 0x1E01, and the conversion relationship of the address is similar to the representation way of the function code.
348
349 For example, U0-01 (servo status) corresponds to the Modbus address is 0x1E01.
350
351 In order to facilitate actual use, this manual provides both decimal and hexadecimal address identification, it is shown in the following table:
352
353 (% class="table-bordered" %)
Stone Wu 9.1 354 |=(% style="text-align: center; vertical-align: middle; width: 162px;" %)**Function code**|=(% style="text-align: center; vertical-align: middle; width: 302px;" %)(((
355 **Modbus address (Hexadecimal)**
356 )))|=(% style="text-align: center; vertical-align: middle; width: 278px;" %)(((
357 **Modbus address (Decimal)**
358 )))|=(% style="text-align: center; vertical-align: middle; width: 192px;" %)**Category**|=(% style="text-align: center; vertical-align: middle; width: 142px;" %)**Name**
Mora Zhou 13.2 359 |(% style="text-align:center; vertical-align:middle; width:162px" %)P00-01|(% style="text-align:center; vertical-align:middle; width:302px" %)0x0001|(% style="text-align:center; vertical-align:middle; width:278px" %)1|(% style="text-align:center; vertical-align:middle; width:192px" %)Basic settings|(% style="text-align:center; vertical-align:middle; width:142px" %)Control mode
Leo Wei 1.1 360
Stone Wu 7.1 361 For detailed parameter addresses, please refer to __[["11.1 Lists of parameters".>>https://docs.we-con.com.cn/bin/view/Servo/Manual/02%20VD2%20SA%20Series/11%20Appendix/#HListsofparameters]]__
Leo Wei 1.1 362
Stone Wu 10.1 363 == **Variable value type** ==
Leo Wei 1.1 364
365 When writing function codes with signed numbers, you need to convert the pre-written data into hexadecimal complements. The conversion rules are as follows:
366
Stone Wu 4.15 367 1. The data is positive or 0: complement code = original code
368 1. The data is negative: complement code = 0xFFFF-absolute value of data + 0x0001
Leo Wei 1.1 369
Stone Wu 4.15 370 For example:
Leo Wei 1.1 371
Stone Wu 4.15 372 * The 16-bit signed positive number +100, the original code is 0x0064, and the complement is: 0x0064.
373 * The 16-bit signed positive number -100, its hexadecimal complement is: 0xFFFF-0x0064 + 0x0001 = 0xFF9C.
374 * If it is an unsigned number, just pass it directly according to its original code. For example, if the decimal number is 32768, write 0x8000 directly.
Leo Wei 1.1 375
376 == **Numerical unit description** ==
377
378 Some values have units and decimals, such as 0.1%, 0.1Hz, 0.01ms, and the corresponding value conversion is required when reading and writing. The methods are as follows:
379
Stone Wu 4.15 380 1. When the unit is 0.1%: 1 represents 0.1%, 10 represents 1.0%, 1000 represents 100.0%. Therefore, writing 1000 means setting to 100.0%; on the contrary, if it is reading 1000, it means that the value is 100.0%;
Stone Wu 4.16 381 1. When the unit is 0.01ms: 1 means 0.01ms, 50 means 0.5ms, 10000 means 100ms. Therefore, writing 1000 means setting to 10.00ms; on the contrary, if 1000 is read, it means 10.00ms;
382
383 The other units can be deduced by this, and integer remains unchanged.