Switch to desktop version  
Write successive registers in Modbus in one Modbus exchange - Printable Version

+- Ewon Technical Forum (https://techforum.ewon.biz)
+-- Forum: Development (https://techforum.ewon.biz/forum-50.html)
+--- Forum: Ewon Embedded Technology (https://techforum.ewon.biz/forum-51.html)
+---- Forum: Field Data Acquisition (https://techforum.ewon.biz/forum-2.html)
+---- Thread: Write successive registers in Modbus in one Modbus exchange (/thread-324.html)



Write successive registers in Modbus in one Modbus exchange - simon - 06-06-2017

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



RE: Write successive registers in Modbus in one Modbus exchange - insyncs - 10-06-2017

Hi Simon,

Thanks that will be useful. Can flexy read multiple registers into an array, can't find info in the manuals?

Cheers

Marcus


RE: Write successive registers in Modbus in one Modbus exchange - insyncs - 11-06-2018

Hi Simon,

Can this be adapted to read data from a RTU slave using the serial port, then write to another slave device via the same serial port ?

Cheers M


RE: Write successive registers in Modbus in one Modbus exchange - simon - 15-06-2018

Marcus,

1. I guess you mean reading multiple register by bloc ? Yes, eWON does that automatically (Default 10 registers in a bloc) and you can customize it using the advanced parameter "MaxDeltaRagX" where X must be replaced by the topic letter.
2. Yes you can do that. Just define the Tags for reading and then adapt the script (replace the 65535 by the Tag value) to write all the Tags in once in the other slave.


RE: Write successive registers in Modbus in one Modbus exchange - lgn@ltr@n - 06-11-2018

Hi,

Is it possible to write several holding registers, followed by a coil write (in this order), in JAVA, while still using integrated ModBus IO/server for other various reads ?

Other option, I only need to ensure the holding registers are written to ModBus slave before trying to write to coil, how long
shall I wait before writing to coil, using the ModBus IO server tags ? In other words, how often the IoServer/Modbus agent process the
write requests ? Is this somehow linked to the Modbus polling frequency ?

Rgds
Laurent


RE: Write successive registers in Modbus in one Modbus exchange - simon - 07-11-2018

Laurent,

Write operation are executed spontaneously when you update the Tag, independently of the polling cycle.
So if you do :
HoldingTag1 = 123
HoldingTag4 = 1234
CoilTag1 = 1

The write requests will then be processed in the same order.

Simon