Basic programming guide – Remote Processing BASIC for the CX-10 Modbus User Manual
Page 58

BASIC PROGRAMMING GUIDE
2-49
REGWRITE
Syntax:
REGWRITE address,data
Function:
Write a value to a modbus register
Mode:
Command, run
Use:
REGWRITE 7033,n
DESCRIPTION
REGWRITE function writes an integer or float to a modbus register. Variable type conversion is
automatically converted from a format compatible with Basic 52 (BCD floating point) to the register type.
address range can be between 1 and 65535. However, this is board dependent. Consult your board manual
for valid registers. Most boards have valid ranges and gaps between ranges and are not contiguous.
Values for data are register dependent. Registers that are integer type accept numbers between 0 - 65535.
Float registers accept numbers in the range of +/- E
127
. When you try to store a floating point number to an
integer, all numbers to the right of the decimal are truncated. Only the whole number is stored.
Floating point numbers stored in modbus registers are in IEE-754 format. This format is known as single
precision. Effectively 7 digits plus exponent can be stored in this format. There are some numbers that, when
stored using REGWRITE, will return a slightly different number.
For example, if you stored one of the original numbers below using REGWRITE, REGREAD will return a
slightly different number.
Original
REGREAD
80.3
80.30001
80.6
80.59999
For all intents and purposes the differences are not significant, less than 0.0001245%.
ERROR
BAD ARGUMENT - when address is not valid or out of range or when integer data is out of range.
EXAMPLE
100
REGWRITE 7033,A
120
PRINT REGEAD(7033)
>run
12