Author Topic: ModbusTCP reading float register  (Read 4057 times)

BLFTech

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • BLF-Tech LLC Website
ModbusTCP reading float register
« on: June 09, 2015, 11:48:18 AM »
I am testing the ModbusTCP driver with the Automation Direct PAC 3000 controller. I can write a float value with the basic label but the value it reads back is a random number. I added the F prefix on both Modbus addresses as needed for float values.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusTCP reading float register
« Reply #1 on: June 09, 2015, 11:59:14 AM »
Try various combinations of byte swap and word swap settings on the driver.

BLFTech

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • BLF-Tech LLC Website
Re: ModbusTCP reading float register
« Reply #2 on: June 09, 2015, 12:17:41 PM »
That did not fix the issue. When I first run the App it briefly shows the correct value and then shows a very large number. Reading bits and longs work OK.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusTCP reading float register
« Reply #3 on: June 09, 2015, 12:36:27 PM »
Does it occur if you have just 1 BasicLabel on the form?

BLFTech

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • BLF-Tech LLC Website
Re: ModbusTCP reading float register
« Reply #4 on: June 09, 2015, 12:50:51 PM »
Yes, it does.

BLFTech

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • BLF-Tech LLC Website
Re: ModbusTCP reading float register
« Reply #5 on: June 09, 2015, 12:51:49 PM »
I meant to say yes, it works correctly with only one label.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusTCP reading float register
« Reply #6 on: June 09, 2015, 01:19:28 PM »
I only have a Modbus simulator to test with and I am not able to reproduce this. I'm fairly sure I know what is causing the problem. After the initial reads, the driver will group together reads to make things more efficient. The first read shows the correct number, but after they are grouped, something is not parsed correctly.

To test this, open ModbusBase.vb and go to line 470

                    ((SubscriptionList(index + ItemCountToGroup + 1).Address.Element + SubscriptionList(index + ItemCountToGroup + 1).Address.NumberOfElements) - SubscriptionList(index).Address.Element) < 20


At the end of the line, change that 20 to a 1

BLFTech

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • BLF-Tech LLC Website
Re: ModbusTCP reading float register
« Reply #7 on: June 09, 2015, 01:23:54 PM »
After changing it to 1 it works correctly.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusTCP reading float register
« Reply #8 on: June 09, 2015, 01:32:00 PM »
This gives me an idea of about where the problem is. I'll dig more into this.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusTCP reading float register
« Reply #9 on: June 09, 2015, 02:11:32 PM »
Here is something else to try...

- Make sure that value of 20 is set back to 20
- In ModbusBase.vb, go to line 581
                                    ValueIndex = Convert.ToInt32((SubscriptionList(i).Address.Element - Requests(TNSByte).Element) / 2 + index)

- Comment out that line

BLFTech

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • BLF-Tech LLC Website
Re: ModbusTCP reading float register
« Reply #10 on: June 09, 2015, 02:36:25 PM »
After doing these changes the label displays 0 and does not change. It still allows me to write to the tag.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusTCP reading float register
« Reply #11 on: June 09, 2015, 02:39:52 PM »
What addresses are you using that cause the problem? I'll see if I can replicate using the same addresses.

BLFTech

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • BLF-Tech LLC Website
Re: ModbusTCP reading float register
« Reply #12 on: June 09, 2015, 02:48:59 PM »
I am reading a long from 400001-400002 and reading a float from 400003-400004

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusTCP reading float register
« Reply #13 on: June 09, 2015, 02:58:10 PM »
That's got me going in the right direction. My long is ok, but my float is not good.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusTCP reading float register
« Reply #14 on: June 09, 2015, 03:08:37 PM »
ModbusBase.vb  Line 467, change to this:

                While (index + ItemCountToGroup + 1) < SubscriptionList.Count AndAlso _
                    SubscriptionList(index + ItemCountToGroup).Address.ReadFunctionCode = SubscriptionList(index + ItemCountToGroup + 1).Address.ReadFunctionCode AndAlso _
                    SubscriptionList(index + ItemCountToGroup).Address.BitsPerElement = SubscriptionList(index + ItemCountToGroup + 1).Address.BitsPerElement AndAlso _
                    ((SubscriptionList(index + ItemCountToGroup + 1).Address.Element + SubscriptionList(index + ItemCountToGroup + 1).Address.NumberOfElements) - SubscriptionList(index).Address.Element) < 20 AndAlso
                    SubscriptionList(index + ItemCountToGroup).Address.Address.Substring(0, 1).ToUpper = SubscriptionList(index + ItemCountToGroup + 1).Address.Address.Substring(0, 1).ToUpper
« Last Edit: June 09, 2015, 03:26:47 PM by Archie »