Author Topic: ModbusRTU Write special case  (Read 1959 times)

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
ModbusRTU Write special case
« on: January 13, 2015, 04:03:04 PM »
I am working with a ModbusRTU Serial device that isn't quite standard.   This particular device does not allow single registers to be written by the x06 command.  If I execute a write function to a single register, all the drivers that I have tried so far want to use the x06 command for writing to single addresses.  I need a driver that will write to a single register using the x10 command.
 
For example: this is a typical read that works(read single register 0x1000 using command x03):
TX
01 03 10 00 00 01 80 CA   
RX
01 03 02 00 01 79 84
 

This is a typical Write that works(write value of “1” to single register 0x1000 using command x10):
TX
01 10 10 00 00 01 02 00 01 76 51
RX
01 10 10 00 00 01 05 09
 

This is a write that doesn’t work for my ModbusRTU Device(write value of “1” to single register 0x1000 using command x06):
TX
01 06 10 00 00 01 4C CA
RX
01 86 01 83 A0
 
 
So the question is, can your ModbusRTU write command be configured to use the x10 command for writing to single register?  I have allready tested it and it works fine writing to multiple consecutive registers, but I need to be able to write to a single register.

Thanks!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5280
    • View Profile
    • AdvancedHMI
Re: ModbusRTU Write special case
« Reply #1 on: January 13, 2015, 05:15:25 PM »
Try this to see if it uses function 10h

Dim values() as string={"123"}
ModbusRTUCom1.Write("40001",values)

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: ModbusRTU Write special case
« Reply #2 on: January 13, 2015, 07:14:15 PM »
I tried it in versions 3.93 and 3.97b today, and it still results in the 06h command.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5280
    • View Profile
    • AdvancedHMI
Re: ModbusRTU Write special case
« Reply #3 on: January 13, 2015, 08:03:05 PM »
I'm adding an ability to force function code by addressing like this:

16:00001

This writes element 1 with function code 16

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: ModbusRTU Write special case
« Reply #4 on: January 15, 2015, 09:36:29 AM »
Looking forward to seeing it.  Thanks!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5280
    • View Profile
    • AdvancedHMI
Re: ModbusRTU Write special case
« Reply #5 on: January 15, 2015, 11:50:29 AM »
I did not get to test it, but it should be working in version 3.97c

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: ModbusRTU Write special case
« Reply #6 on: January 15, 2015, 03:36:58 PM »
Thanks, works great.  I did not realize at first that you drop the 4 from the 40001 addressing in this special case. Below is the code I used to test it.

    Private Sub btn_WriteValue_Click(sender As Object, e As EventArgs) Handles btn_WriteSingleValue.Click
        Dim strValue1 As String
        Dim n_strMessage As String
        Dim strAddress As String

        Try
            ' the "16:" forces the 10h function code
            strAddress = "16:" & txtbxTargetBaseAddress.Text
            strValue1 = txtbox_ValueToWrite0.Text
            ModbusRTUCom1.Write(strAddress, strValue1)

        Catch ex As Exception
            n_strMessage = "Function frmModbusRTUtest: failed with error: " & vbCrLf & ex.Message
            MsgBox(n_strMessage)

        End Try
    End Sub

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: ModbusRTU Write special case
« Reply #7 on: January 20, 2015, 09:57:07 AM »
What's the easiest way to add the 3.97c Modbus update to my 3.97 version application?
Thanks!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5280
    • View Profile
    • AdvancedHMI
Re: ModbusRTU Write special case
« Reply #8 on: January 20, 2015, 10:10:58 AM »
The easiest way is to download the latest version, then replace the AdvancedHMI directory with the one from your previous project. Open the solution, Clean and Rebuild All

Another method is to open the latest solution, then right click AdvancedHMI project in Solution Explorer, then select Add Existing. Then browse to the .vb files from your previous project.