Author Topic: modbus values?  (Read 4570 times)

drksam

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: modbus values?
« Reply #15 on: January 08, 2016, 11:40:08 AM »
After poking around in the automationdirect softare I found some conversions it can do to the data and going back to the url I posted I saw that the poster converted his data to BIN. The plc will make that conversion and the again converted output of the AHMI is now correct.

Sorry for all of the confusion and thank you guys for all the help.

rbelknap

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Re: modbus values?
« Reply #16 on: January 08, 2016, 12:01:50 PM »
This will basically do what the hex command does, but can't return any letters

Code: [Select]
MyBase.value = Val(Math.Truncate(e.Values(0) / 16) & (e.Values(0) Mod 16))

Again, this is assuming we are putting it in the correct spot.
To check, set mybase.value=1 or some other constant.
This should show if we can affect the value displayed.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: modbus values?
« Reply #17 on: January 08, 2016, 12:22:33 PM »
Example of what i found
1=1 2=2 3=3 4=4 5=5 6=6 7=7 8=8 9=9     10=16 11=17 12=18 13=19 14=20 15=21 16=22 17=23 18=24 19=25    20=32 21=33 the pattern continues like that so to shorten the list 30=48   40=64   50=80   60=96   70=112   80=128   90=144   100=256
This pattern is definitely BCD. Let me see what I can come up with to convert it.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: modbus values?
« Reply #18 on: January 08, 2016, 12:39:51 PM »
Here is a function that will convert the BCD to an integer value:
Code: [Select]
    Private Function BCDToInt(ByVal value As Integer) As Integer
        Dim BCDOut As Integer
        BCDOut = (value And &HF) + ((value And &HF0) >> 4) * 10 _
            + ((value And &HF00) >> 8) * 100 + ((value And &HF000) >> 12) * 1000

        Return BCDOut
    End Function

In your PollDataReturned you can then use this:

 MyBase.Value = BCDToInt(e.Values(0))

drksam

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: modbus values?
« Reply #19 on: January 08, 2016, 12:58:20 PM »
It seems to work i have only tried one but I will let you know if i have problems as more values change.

Thanks again and AWESOME project i cant wait to use it for more.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: modbus values?
« Reply #20 on: January 08, 2016, 01:03:07 PM »
I am going to implement BCD functionality into the next version. By preceding the address with a "B", it will return a BCD converted value.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: modbus values?
« Reply #21 on: February 21, 2016, 10:44:38 PM »
Version 3.99b is now available and supports BCD by preceding the address with a "B" (e.g. B40001)