Author Topic: ModbusRTU Serial: writing multiple values  (Read 2478 times)

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
ModbusRTU Serial: writing multiple values
« on: December 23, 2014, 07:00:30 PM »
What is the syntax for writing multiple values with ModbusRTU Serial?  My ModbusRTU device only supports writing to holding registers with the 0x10(16) function code.


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusRTU Serial: writing multiple values
« Reply #1 on: December 23, 2014, 07:32:01 PM »
See if this code works:

        Dim values(2) As String
        values(0) = "123"
        values(1) = "345"
        values(2) = "678"
        Dim address As New MfgControl.AdvancedHMI.Drivers.Modbus.ModbusAddress("40001")
        ModbusRTUCom1.Write(address, values)

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: ModbusRTU Serial: writing multiple values
« Reply #2 on: December 29, 2014, 06:18:44 PM »
Hope you all had a good Christmas.  I am still working with this write procedure.

Unfortunately my ModbusRTU device does not support the 0x06(06) function code for writing.

Here is some code I tried and the results

     strAddress="44097"
     strValue1(0) = "1"
     ModbusRTUCom1.Write(strAddress, strValue1(0))

The data sent to the modbus device by the above code: 01 06 10 00 00 01 4C CA



What I need to be sent is:  01 10 10 00 00 01 02 00 01 76 51



I also tried sending a two register array two registers of data, "44097 - 44098"

     Dim strAddress As String = "44097"
     Dim strWriteValues2(1) As String
     Dim modbusAddress As New MfgControl.AdvancedHMI.Drivers.Modbus.ModbusAddress(strAddress)

     strWriteValues2(0) = "1"
     strWriteValues2(1) = "0"
     ModbusRTUCom1.Write(modbusAddress, strWriteValues2)                             

What was sent was: 01 06 10 00 00 01 00 00 B4 97


Any more suggestions that would result in a function 0x10 write code?

Thanks!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusRTU Serial: writing multiple values
« Reply #3 on: December 29, 2014, 06:41:22 PM »
I did a quick test with the version that is still in testing using this code:


        Dim Values() As String = {"1", "2"}
        ModbusRTUCom1.Write("40001", Values)


And this is the packet sent:

01 10 00 00 00 02 04 00 01 00 02 23 AE

So it is using the function code 10h (16 decimal) for the multiple write. Maybe this will be resolved in the next release.

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: ModbusRTU Serial: writing multiple values
« Reply #4 on: December 30, 2014, 07:32:50 AM »
Would a single value character string array also result in a function code 10h packet?  If it does, then it would be useful to me.  Thanks!

        Dim Values() As String = {"1"}
        ModbusRTUCom1.Write("40001", Values)