AdvancedHMI Software

General Category => Support Questions => Topic started by: drksam on January 07, 2016, 09:37:37 AM

Title: modbus values?
Post by: drksam on January 07, 2016, 09:37:37 AM
Hi everyone
I have a question about the data being returned to my hmi but first a little background. I have advanced hmi running perfectly connected to an arduino mega with an Ethernet shield. Everything works fine there the values it returns (0 to 50 Amp) are fine and the meters read the same as the serial out on the arduino. The problem comes when I try to talk to an automation direct plc I see the data from the correct register but it is formatted strange. example a value that should be 31 is 49 and a value that should be 16 is 22. In the automation direct software data view i can swap between data types and i see that when it is displayed correctly the data type is (BCD/Hex). I can change that to (Decimal) and i see the same thing Advance HMI is displaying. So i know that it is working properly but i need to be able to display the 31 and the 16 as 31 and 16. I have read around and found the modification to the .vb file that should work but in the version of Advanced HMI that i have line 326 in the panel meter vb file isnt the same as the example. Also it would be nice to be able to just modify one meter not a global meter change as I plan to use one HMI project to display and interface to 3 devices arduino automation direct plc and a delta plc (if possible).
Title: Re: modbus values?
Post by: Archie on January 07, 2016, 09:46:40 AM
Are you reading an integer, long, or floating point?
Title: Re: modbus values?
Post by: drksam on January 07, 2016, 09:56:50 AM
Well im not really sure. According to the direct soft map they are (WORD)s.
Title: Re: modbus values?
Post by: drksam on January 07, 2016, 03:05:05 PM
After doing some more reading i find that the WORDs are 16bit each and the manual calls them Holding Registers so i would think that they are longs but still not exactly sure. The automation direct plc has an addressing scheme that takes some getting used to but after playing around i find that the discreet ins and outs work fine i can send a button mash and i see the state of an input.
Title: Re: modbus values?
Post by: rbelknap on January 07, 2016, 03:50:11 PM
I'm pretty sure I was reading the same post you were in looking for the answer.

I see 2 options, Archie may provide more.

Option 1

Add the hex conversion code between Line 197 and Line 198 in the DigitalPanelMeter.
could also add a property to set if you want hex or not.

Code: [Select]
 
Private Sub PolledDataReturned(ByVal sender As Object, ByVal e As SubscriptionHandlerEventArgs)
     'Put the hex Code here.
End Sub

Option 2

Create a new control that would be for hex by doing this:
Create a new class in the purchased folder.
Copy all of the code form the DigitalPanelMeter control
Paste it into the new Class, Paste over everything in the new class
Rename At the top where is shows "Public Class DigitalPanelMeter" to Public Class DigitalPanelMeterHex
Then paste the Hex code as above
Once you re-compile, it You will have the DigitalPanelMeterHex in your toolbox

The line numbers I show assume you're using 399a.

Good Luck,

Rich


Title: Re: modbus values?
Post by: drksam on January 07, 2016, 08:19:53 PM
Ok i will give that a try. Just to clarify were you talking about the conversion code on http://advancedhmi.com/forum/index.php?topic=50.0
Also I am using the newest version of visual studio and advanced hmi.
Title: Re: modbus values?
Post by: drksam on January 08, 2016, 07:36:35 AM
Ok so i copied PanelMeter and edited it useing the code from that last url in the location that rbelknap gave. I had to play with it to get it to compile but i got it to load. I am pretty sure thats not the right code as it still returned the same value as the DigitalPanelMeter that had not been modified. I have not written much code for anything other than arduino and am lost when looking for a coding solution to do the conversion. I thought i had at some point seen something else on the forum here for converting but after much searching I am yet to find it.
Title: Re: modbus values?
Post by: rbelknap on January 08, 2016, 07:40:04 AM
Actually, I had seen this post:  http://advancedhmi.com/forum/index.php?topic=413.msg1671#msg1671 (http://advancedhmi.com/forum/index.php?topic=413.msg1671#msg1671)

The values that you want are Hex, The values that you're getting are decimal.
Read through the last page of that thread and it should make sense.
Title: Re: modbus values?
Post by: rbelknap on January 08, 2016, 08:08:04 AM
You put this code there?
Code: [Select]
   
        Try
            MyBase.Value = Hex(e.Values(0))
        Catch ex As Exception
            DisplayError("INVALID VALUE RETURNED!" & e.Values(0))
        End Try

oh, and you're sure that you're using the new control?
You would need to compile the controls before putting the new one on the form.

Title: Re: modbus values?
Post by: drksam on January 08, 2016, 08:57:10 AM
With that code in the existing private sub i get an error building. If i use the private sub from the 4th page of the post you linked and your code it builds fine but it still doesn't change the value on the meter. Also i have tried several other combinations of the code some built some didn't but nothing seems to change the value of the output.  I think I am using the correct one after making a change I have been removing the old test meter rebuilding/building iv tried both then adding a new DigitalPanelMeterHEX.
Title: Re: modbus values?
Post by: rbelknap on January 08, 2016, 09:10:26 AM
unfortunately I don't have a PLC to try it out with.

Perhaps Archie can help.

drksam, Post the subroutine where your trying to change the value. 
Title: Re: modbus values?
Post by: Archie on January 08, 2016, 09:19:02 AM
In your DigitalPanelMeterHex, check the first line of code and make sure the name was changed there also:

Public Class DigitalPanelMeterHex


I'm not sure this is going to work because the DigitalPanelMeter cannot display the letters A-F for the hext values.
Title: Re: modbus values?
Post by: drksam on January 08, 2016, 09:29:50 AM
Yes I had to change the name to get it to build after i copied it.

Ok that should be fine its not that i want to see it in hex like 1F4 or something like that. The output im looking for looks like decimal ie. 16 is a normal number for a counter that makes sure a line has between 15 and 17 parts on it. In the automationdirect software it shows it as 16 on the counter and in the v memory location where it is stored for modbus. The automationdirect software lets you change the "data format" when looking at data in a data view thats where i found that the option "BCD/Hex" showed the correct value as 16 (also with other numbers it still dont show data like example 1F4). when i switch the "data format" to decimal i see the same thing that the AHMI shows. i just dont know how to get it to show the original number.
Title: Re: modbus values?
Post by: drksam on January 08, 2016, 09:41:25 AM
Here it is with a little extra just to show where it was

Code: [Select]
  '***************************************
    '* Call backs for returned data
    '***************************************
    Private OriginalText As String

    Private Sub PolledDataReturnedValue(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        Try
            MyBase.Value = Hex(e.Values(0))
        Catch ex As Exception
            DisplayError("INVALID VALUE RETURNED!" & e.Values(0))
        End Try
    End Sub



    Private Sub DisplaySubscribeError(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        DisplayError(e.ErrorMessage)
    End Sub
Title: Re: modbus values?
Post by: drksam on January 08, 2016, 10:22:49 AM
I wrote a small program on the automationdirect plc to slowly count up one at a time from 0 to 105 and wrote down the output of the the counter (the real number i want) and of the digital meter (also the same as "data format" decimal in automationdirect software). The pattern kinda looks like binary and not like hex knowing nothing about BCD i assume that the data is in BCD. 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

If it is not possible to convert the data is it maybe possible for me to create a table or even a long list of if than statements that could do what i need the system never counts higher than 200 so it could even just go to 200 then say error or something.
Title: Re: modbus values?
Post by: drksam 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.
Title: Re: modbus values?
Post by: rbelknap 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.
Title: Re: modbus values?
Post by: Archie 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.
Title: Re: modbus values?
Post by: Archie 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))
Title: Re: modbus values?
Post by: drksam 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.
Title: Re: modbus values?
Post by: Archie 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.
Title: Re: modbus values?
Post by: Archie 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)