Author Topic: Reading of multiple Modbus RTU bit registers  (Read 2072 times)

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Reading of multiple Modbus RTU bit registers
« Reply #15 on: March 25, 2020, 12:36:56 PM »
You should turn off your packet monitoring since it doesn't really do good to your troubleshooting within AHMI.

Go back to your reply #2 and try those things again since you stated that you got a correct response.

I don't have any other suggestions for you.


juanma1364

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Reading of multiple Modbus RTU bit registers
« Reply #16 on: March 25, 2020, 04:54:06 PM »
Ok Godra, Thank you very much for your answers.

I don't always use the serial port monitor, only when AdvancedHMI doesn't give me the frame I need and I want to see what it's sending.

Also the serial monitor in this case was not causing me problems.

It was just that it was necessary to send the correct frame requested by the PLC Manufacturer.

I already managed to find the solution, modify this:

 "Private Sub MainForm_Load (sender As Object, and As EventArgs) Handles MyBase.Load
    Dim Q1 () As String
    Q1 = ModbusRTUCom1.Read ("1: 11313", 16)
    Label2.Text = Q1 (1)
    End Sub "

For this:

 "Private Sub MainForm_Load (sender As Object, and As EventArgs) Handles MyBase.Load
    Dim Q1 () As String
    Q1 = ModbusRTUCom1.Read ("011313", 16)
    Label2.Text = Q1 (1)
    End Sub "

This last one correctly sends me the frame I need and I get the response from the PLC at Bit level.

I can only optimize the code

Thanks and regards

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Reading of multiple Modbus RTU bit registers
« Reply #17 on: March 25, 2020, 05:00:56 PM »
If that works then the DataReceived event has to work as well.

juanma1364

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Reading of multiple Modbus RTU bit registers
« Reply #18 on: March 25, 2020, 05:03:53 PM »
Surely godra

At this moment I am proceeding to implement the event "DataReceived" with the necessary modifications and I test.

Thank you very much again Godra

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Reading of multiple Modbus RTU bit registers
« Reply #19 on: March 25, 2020, 05:13:49 PM »
You need to understand that your code is executed only when you run the program.

If you want to receive values continuously then you need to subscribe to reading them and that's when you should consider using the DataSubscriber2 component and its Datareceived or DataChanged event.


juanma1364

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Reading of multiple Modbus RTU bit registers
« Reply #20 on: March 25, 2020, 05:21:33 PM »

Right Godra,
The code is in the

"Private Sub MainForm_Load"

I only did it as proof.

Now I am going to use the AdvancedHMI components to carry out the continuous execution of the program at BITS level.

Godra..you are a genius.

If you have an example code for me that you want to share, I would appreciate it

Thank you

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Reading of multiple Modbus RTU bit registers
« Reply #21 on: March 25, 2020, 05:31:24 PM »
The example code is already in the reply #5.


juanma1364

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Reading of multiple Modbus RTU bit registers
« Reply #22 on: March 25, 2020, 05:35:12 PM »
Ok Godra..I will try to use that with the associated events.

juanma1364

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Reading of multiple Modbus RTU bit registers
« Reply #23 on: March 25, 2020, 06:58:13 PM »

Godra, I've tried the component
"Data Subscriber 21" and the following code:

 Private Qs As String = ""
    Private Sub DataSubscriber21_DataReturned (As Object sender, and As Drivers.Common.PlcComEventArgs)
        If e.ErrorId = 0 Then
            If e.PlcAddress = "011313,16" Then
                Me.Label9.Text = ""
                Qs = ""
                For i = 0 To e.Values.Count - 1
                    If i = e.Values.Count - 1 Then
                        Qs & = "Q" & (i + 1) & "=" & e.Values ​​(i)
                    Else
                        Qs & = "Q" & (i + 1) & "=" & e.Values ​​(i) & ","
                    End If
                Next
                Me.Label9.Text = Qs
            End If
        End If
    End Sub

    Private QQs As String = ""
    Private Sub ModbusRTUCom1_DataReceived (sender As Object, and As Drivers.Common.PlcComEventArgs) Handles ModbusRTUCom1.DataReceived
        If e.ErrorId = 0 Then
            If e.PlcAddress = "011313.6" Then
                Me.Label10.Text = ""
                QQs = ""
                For i = 0 To e.Values.Count - 1
                    If i = e.Values.Count - 1 Then
                        QQs & = "Q" & (i + 1) & "=" & e.Values ​​(i)
                    Else
                        QQs & = "Q" & (i + 1) & "=" & e.Values ​​(i) & ","
                    End If
                Next
                Me.Label10.Text = Qs
            End If
        End If
    End Sub


And I still don't get the plot I need.

this gives me the following data output:

"05 01 2C 30 00 01 F4 D1"

And I need this data output:

"05 01 2C 30 00 10 34 DD"

I have this problem with several AdvancedHMI components in their Property "PLCAddressValue", the Modbus function "01" with the address "011313,16" does not support me

The only thing that works for me is the code:

"ModbusRTUCom1.Read (" 011313 ", 16)"

I hope I don't bother with so many questions.

Greetings and thanks

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Reading of multiple Modbus RTU bit registers
« Reply #24 on: March 25, 2020, 08:42:48 PM »
You are too new to AHMI and just doing bunch of weird things.


This is the format for the Read function:

ModbusRTUCom1.Read (PLCAddress, NumberOfElements) and that's why you have it as ModbusRTUCom1.Read (" 011313 ", 16)

So, PLC Address = "011313" and NumberOfElements = 16 and you don't combine these together into "011313,16".


Most controls are designed for 1 element only and don't have the NumberOfElements property.

DataSubscriber2 allows you to enter the NumberOfElements separately, so it should not be added to its PLCAddress as well.

« Last Edit: March 25, 2020, 09:06:58 PM by Godra »

juanma1364

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Reading of multiple Modbus RTU bit registers
« Reply #25 on: March 25, 2020, 10:00:01 PM »
Godra you're right, this is my first experience with AdvancedHMI.

The idea is precisely to know it to get to use it more frequently.

I take advantage of your comments and all your answers to move forward.

Thank you very much Godra