News:

  • April 29, 2026, 08:10:47 AM

Login with username, password and session length

Author Topic: Proper method of moving data in and out of modbus  (Read 9940 times)

AngrySparky

  • Newbie
  • *
  • Posts: 9
Proper method of moving data in and out of modbus
« on: November 25, 2024, 09:04:04 PM »
What is the proper method to move data from internal memory to the modbus memory blocks? Right now I'm testing some new radios and I'm using a BRX on each end to create modbus data and read and write it back and forth over the air. To create some data I have a counter incrementing off the second flasher bit, I then want to move that value into the modbus blocks. Are the modbus memory 16 bit integers? To move a R,D, CT.ACC, etc value into them do I need to do a data type conversion command? What's the best way to move data from internal memory to the modbus addresses?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: Proper method of moving data in and out of modbus
« Reply #1 on: November 26, 2024, 09:01:38 AM »
Yes, Modbus Registers (Input and Holding) are 16 bit values.  They are technically "typeless" and their interpretation is typically up to the server (in this case, the BRX PLC).  So for a 32 bit accumulator, you will need to utilize 2 contiguous Modbus registers as the slave, and the client will need to "read multiple" registers and interpret them as a 32 bit signed integer (since that's what a BRX counter .Acc value is).  You could have just an unsigned 16 bit word that maps well to a Modbus Register.  You could pack 16 bits into a single 16 bit register, or a 32 bit REAL into two contiguous registers, et. al.

MHR0 and MIR0 are off limits via the Modbus protocol, so do not utilize them.  MIR1 corresponds to the first Modbus Input Register 30001 and MHR1 corresponds to the first Modbus Holding Register 40001.  The MIR/MHR IDs are basically decimal offsets into the 3xxxx/4xxxx Modbus Address space.  Modbus Application Layer addresses are 1-based, but Do-more data blocks are 0-based.

PUBLISH and SUBSCRIB are best and allow you to do any conversions to what would help any Modbus Client interpret the value properly, along with "unaligned" memory reads/writes (don't worry about what this CISC microprocessor terminology means, it "just works" with PUBLISH and SUBSCRIB).  Read over those instructions' help topics.

Bolt

  • Hero Member
  • *****
  • Posts: 594
Re: Proper method of moving data in and out of modbus
« Reply #2 on: November 26, 2024, 02:10:19 PM »
The "easy" way would be to just use the COPY command with a cast. For example:

COPY R0 MHR2:R
COPY D0 MHR4:D
COPY CT0.Acc MHR6:D

This does not give you as much control as PUBLISH, but it helps to make it simple entries quick. But you do have to know how words align, etc.

As far as how trigger the action, you could use the delta contact to only trigger the COPY if the data has changed, etc. Or use ST1 and it will just COPY all the time, depending on your program, it may not hinder performance much at all.

AngrySparky

  • Newbie
  • *
  • Posts: 9
Re: Proper method of moving data in and out of modbus
« Reply #3 on: November 27, 2024, 10:04:13 AM »
Thanks for the help. Yesterday I figured out the publish and subscribe instructions as well as lots of other things with dealing with Modbus between the PLC and the radios. Bench tests have been very successful.