Author Topic: Force a value from HMI into plc address  (Read 6811 times)

Darrell

  • Full Member
  • ***
  • Posts: 198
  • Electrician / PLC Technician
    • View Profile
Force a value from HMI into plc address
« on: October 18, 2014, 10:39:30 PM »
Great Program , started playing with this a week ago and can't leave it alone.

Very new to VB , not sure how I can force a value into a PLC address from HMI , I'm using a Micro logix 1400

I want to us a button to force a number into and integer file or anolog output for testing puposes.

thanks
Darrell
« Last Edit: October 18, 2014, 10:42:00 PM by jazzman448899 »

Noe

  • Full Member
  • ***
  • Posts: 205
    • View Profile
Re: Force a value from HMI into plc address
« Reply #1 on: October 20, 2014, 09:51:54 AM »
You can use a write, the way to use is:

Code: [Select]
                   ResDBClientPN = "94939291"

                    'Writes the value to PLC string and then to STATUS integer register
                    Try
                        EthernetIPforCLXCom1.Write("ResTestData", ResDBClientPN)
                        EthernetIPforCLXCom1.Write("ResTestStatus", 15)
                    Catch ex As System.Exception
                        System.Windows.Forms.MessageBox.Show(ex.Message)
                    End Try

I wrote two different values, the fisrt one is a string ("ResTestData") followed by the value you want to write (ResDBClienPN), I used a variable as an example, but you can write text directly, depending on what you want to do. The second value is an integer label ("ResTestStatus") into who I wrote a value of 15.
Remember to do all this inside a Try...Catch, as it will prevent your application from frozing with an error when the PLC is offline, if you want you can write a message like "Cannot write values to PLC, must be offline" or alike to warn the user, into the message box, but this is totally up to you.

Remember you are not "forcing" values, think of this program as exactly how it works an HMI in real life, so you are reading and writing values like any other device into the PLC.

The same applies to .Read method, but you only specify the tag or direct address like N7:0 that you want to read.

There is a topic related to this method to be an asynchronous way to write and read, and can lock the user interface from a moment to several time, not being the best method. To read a value from the PLC use basic labels, or better a datasubscriber (it does not generate a visible control if you do not want the user to see something) and will be much more efficient in communication use as is designed with that in mind, basic labels have datasubscribers embedded. I am not aware if Archie added a different method to write values, but so far this has worked fine for me.

A lot of good information is spreaded in here in the forums and you need to read a lot to get it, but it is worth it.
« Last Edit: October 20, 2014, 10:09:28 AM by Sprungmonkey »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Force a value from HMI into plc address
« Reply #2 on: October 20, 2014, 08:33:55 PM »
If you are wanting to do a "force" as done in RSLogix, it is not supported by the AdvancedHMI drivers.

Darrell

  • Full Member
  • ***
  • Posts: 198
  • Electrician / PLC Technician
    • View Profile
Re: Force a value from HMI into plc address
« Reply #3 on: October 20, 2014, 10:08:19 PM »
No I'm using to do some testing of some belimo actuators for positioning , when i need to force a different value into an analog output . I make my output rung always false and the force the value into the output directly . This just makes it easier for me , than constantly entering a value by hand  in my testing stages.

But a way to force an output would be a nice option for me in my line of work.

Thanks
Darrell

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Force a value from HMI into plc address
« Reply #4 on: October 20, 2014, 10:21:20 PM »
As long as your rung that moves the value into the output is false, you should be able to use a BasicLabel with PLCAddressKeypad set to the output address, then run the app and click on the BasicLabel to enter a new value.

Darrell

  • Full Member
  • ***
  • Posts: 198
  • Electrician / PLC Technician
    • View Profile
Re: Force a value from HMI into plc address
« Reply #5 on: November 03, 2014, 12:55:10 PM »
I'm using a trackbar with a range  from   0 to 16383  , I also have the value display in a label , then using a button click the value is forced into the integer in the code below. what I would like is to have the value go into N14:50 automatically from the trackbar and not have to use the button to force the value.

        'Writes the value from TrackBar1 into the PLC address N14:50

        Try
            EthernetIPforPLCSLCMicroCom1.Write("N14:50", TrackBar1.Value)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try



This is the code I used for the TrackBar & the Label

 Private Sub TrackBar1_Scroll(sender As System.Object, e As System.EventArgs) Handles TrackBar1.Scroll

    End Sub

    Private Sub TrackBar1_ValueChanged(sender As Object, e As System.EventArgs) Handles TrackBar1.ValueChanged
        Label11.Text = "Analog Out = " &
           Format(TrackBar1.Value, "#")

    End Sub

    Private Sub Label12_Click(sender As System.Object, e As System.EventArgs) Handles Label12.Click
        TrackBar1.Value = CInt(CType(sender, Label).Text)
    End Sub


Darrell
« Last Edit: November 03, 2014, 04:11:16 PM by Darrell »