06-06-2017, 11:33 AM
Hi
if you want to specifically write 6 successive registers in Modbus, you can only do it by using BASIC scripting.
Indeed if you try to do it by simply writing values into Modbus Tags as quick as possible (through BASIC, OPCUA,...), the eWON will perform the writings one by one.
Here is an example using the BASIC functions IOSend/IORcv to trigger a modbus writing to multiple sucessive registers (here 6 registers) :
if you want to specifically write 6 successive registers in Modbus, you can only do it by using BASIC scripting.
Indeed if you try to do it by simply writing values into Modbus Tags as quick as possible (through BASIC, OPCUA,...), the eWON will perform the writings one by one.
Here is an example using the BASIC functions IOSend/IORcv to trigger a modbus writing to multiple sucessive registers (here 6 registers) :
Code:
Write6Regiter:
REM ****************************************************************
REM WriteModbusRegister --> Modbus function 16
REM B$ is the Slave address of the device
REM WriteRegAddr is the register address to Write
REM Z$ is the DATA to write (multiple of 16bits)
REM ****************************************************************
B$ = "100,192.168.120.98"
WriteRegAddr = 19
Z$ = SFMT 1234,10,2 //Value1 = 1234
Z$ = Z$ + SFMT 456,10,2
Z$ = Z$ + SFMT 65535,10,2
Z$ = Z$ + SFMT 65535,10,2
Z$ = Z$ + SFMT 65535,10,2
Z$ = Z$ + SFMT 65535,10,2//Value
WriteModbusRegister:
debug = 1
A$ = Chr$(16)
a% = WriteRegAddr
a% = a% AND 65535
A$ = A$ + Chr$(a%/256)+Chr$(a% MOD 256)
a% = LEN(Z$)
A$ = A$ + Chr$(0)+Chr$(a%/2) //Quantity
A$ = A$ + Chr$(a%) //Byte Count
A$ = A$ + Z$
a% = Iosend "MODBUS",B$,A$
if (debug) then
for i%=1 to LEN(A$)
j%=ASCII(A$(i%))
X$ = SFMT j%,30,0,"%X"
print X$;" ";
next i%
print ""
print B$
endif
Wait_IO_End_2:
b% = Iorcv a%,1
If b%=-1 Then
Goto Wait_IO_End_2
Endif
B$ = Iorcv a%
if (B$=A$(1 to 5)) then
print "Write OK"
else
print "Write Failed"
endif
if (debug) then
Print Len(B$);" bytes received"
for i%=1 to LEN(B$)
j%=ASCII(B$(i%))
X$ = SFMT j%,30,0,"%X"
print X$;" ";
next i%
print ""
endif