Author Topic: Help Reading Float Value from PLC  (Read 2198 times)

sajidhh

  • Newbie
  • *
  • Posts: 7
    • View Profile
Help Reading Float Value from PLC
« on: December 04, 2017, 10:44:28 PM »
i have just download AdvancedHMI 3.99 few days back. seeing the video tutorial i just deveolpe first application in which i place DigitalDsiplayMeter and assigned the PLC address register 40001 to it.when i run the application i just got the 2 bytes value  stored in the first register. i am using  PLC simulator with modbus TCP/IP protocol. the address register on this plc simulator are of two bytes length. it mean each flot (real) value is stored in two consecutive register e.g. say i entered 50.5689 at address 40001 then this value will be stored at 40001 and 40002. my problem is that i want to display the same on DigitalDisplayMeter but i dont know what address to entered at PLCAddressValue property of this control if entered F40001 it read nothing wjen i entered  40001 then it read back only part of float that is stored in first two bytes that is at 40001 (but only binary value of stored number not in float form).can SOME one please  guide me how to read float from plc in float form. i have also try to read float on simple BasicLabel control but again give garbage value. please tell me how to tell software to read two consecutive regsiters. i have use this simulator with other HMI it works fine. i simply give addres of first register and hmi show complete float value.
waiting for your reply. please also tell me what is significance of property ValueScaleFactor.
sajid

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Help Reading Float Value from PLC
« Reply #1 on: December 04, 2017, 10:59:00 PM »
If you use a BasicLabel and enter F40001 into PLCAddressValue, what will it display?

sajidhh

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Help Reading Float Value from PLC
« Reply #2 on: December 04, 2017, 11:13:27 PM »
it show on the label -151732604633088 .
i have entered 2.56 on first address that is  F40001 .
and numeric format property is set to  0.0
the 2.56 at first first address is not appearing

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Help Reading Float Value from PLC
« Reply #3 on: December 04, 2017, 11:28:28 PM »
Try different combinations of Swap Words and Swap bytes on the driver instance

sajidhh

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Help Reading Float Value from PLC
« Reply #4 on: December 05, 2017, 12:53:15 AM »
thanks for your quick reply. the problem has been solved. i was giving entering wrong address.
please can you tell me how to generate latch type switch in AdvancedHMI software.

Godra

  • Hero Member
  • *****
  • Posts: 1437
    • View Profile
Re: Help Reading Float Value from PLC
« Reply #5 on: December 05, 2017, 01:42:48 AM »
BasicButton, MomentaryButton and SquareIlluminatedButton controls have the OutputType property that can be set to "Toggle", which is very similar to latch.

Some other controls might have that same property as well.

sajidhh

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Help Reading Float Value from PLC
« Reply #6 on: December 05, 2017, 05:30:51 AM »
thanks for quick reply it works well can you please tell me how to change the BasicButton image to my choice on off action

Godra

  • Hero Member
  • *****
  • Posts: 1437
    • View Profile
Re: Help Reading Float Value from PLC
« Reply #7 on: December 05, 2017, 11:17:29 PM »
You would create 2 images, ImageON.png and ImageOFF.png, add them to the AdvancedHMI project resources and then in the Designer you can set one of these images as the initial BackgroundImage for the BasicButton (probably ImageOFF.png as the off state is the most common to start with). The examples below use the BasicButton3 name which you would replace with the name of your button.

Then, if you just want these images to change with every click of the button, you can add to the MainForm a code similar to this:

Code: [Select]
    Private flagImage As Boolean
    Private Sub BasicButton3_Click(sender As Object, e As EventArgs) Handles BasicButton3.Click
        If Me.flagImage Then
            Me.BasicButton3.BackgroundImage = My.Resources.Image_OFF
            Me.flagImage = False
        Else
            Me.BasicButton3.BackgroundImage = My.Resources.Image_ON
            Me.flagImage = True
        End If
    End Sub

If you want to set images as per the state of a certain boolean address then you can add to the MainForm a code similar to this:

Code: [Select]
    Private Sub BasicButton3_Click(sender As Object, e As EventArgs) Handles BasicButton3.Click
        If CBool(Me.ModbusTCPCom1.Read("00001", 1)(0)) Then
            Me.BasicButton3.BackgroundImage = My.Resources.Image_ON
        Else
            Me.BasicButton3.BackgroundImage = My.Resources.Image_OFF
        End If
    End Sub

This code above is using a driver from the MainForm, in this case ModbusTCPCom1, to read that specific address.
« Last Edit: December 05, 2017, 11:21:00 PM by Godra »

sajidhh

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Help Reading Float Value from PLC
« Reply #8 on: December 07, 2017, 03:36:06 AM »
thanks a lot it works fine