Author Topic: Unable to set polling interval of PLC through c# application  (Read 4065 times)

thug_

  • Newbie
  • *
  • Posts: 30
    • View Profile
Unable to set polling interval of PLC through c# application
« on: January 19, 2017, 08:42:31 AM »
I have Allen- Bradley 1200 PLC, and I am using SerialDF1forSLCMicroCom driver.

I would like to be able to set polling time of PLC through user interface, I am not sure if that is possible ?

The way how I am doing is :

                        plc.PollRateOverride = Convert.ToInt32(txtPollingInterval.Text);
                        plcPoll.Interval = TimeSpan.FromMilliseconds(Convert.ToDouble(plc.PollRateOverride));
                        plcPoll.IsEnabled = true;
                        plcPoll.Tick += plcPoll_Tick;
                        plcPoll.Start();

inside plcPoll_Tick mostly I am reading some registers from plc and displaying on the screen. For me looks like, whatever value I enter as a plc.PollRateOverride, polling time is 500mS ?

Thanks

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Unable to set polling interval of PLC through c# application
« Reply #1 on: January 19, 2017, 08:56:24 AM »
The PollRateOverride regulates the update interval of subscriptions. It looks like you are using a timer to manually poll for data.

thug_

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Unable to set polling interval of PLC through c# application
« Reply #2 on: January 19, 2017, 09:27:38 AM »
The PollRateOverride regulates the update interval of subscriptions. It looks like you are using a timer to manually poll for data.

Ok, but how would be best way to change polling interval of PLC, if that is possible ?

Thanks

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Unable to set polling interval of PLC through c# application
« Reply #3 on: January 19, 2017, 09:33:25 AM »
For instance, add a BasicLabel to the form and set PLCAdressValue to T4:0.ACC

In the PLC, make T4:0 run continuously

Set PollRateOverride to 0, the. Run the application.

Now set PollRateOverride to 1000 and run the application

You should see a significant difference in the refresh rate of the value.

thug_

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Unable to set polling interval of PLC through c# application
« Reply #4 on: January 19, 2017, 09:41:51 AM »
For instance, add a BasicLabel to the form and set PLCAdressValue to T4:0.ACC

In the PLC, make T4:0 run continuously

Set PollRateOverride to 0, the. Run the application.

Now set PollRateOverride to 1000 and run the application

You should see a significant difference in the refresh rate of the value.

It has to be T4:0.ACC ? Is that mean that PollRateOverride will be 1 second in the case I set it to 1000, and 0 or 100 when I set it to 0 ?

Thanks Archie

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Unable to set polling interval of PLC through c# application
« Reply #5 on: January 19, 2017, 09:49:49 AM »
It can be any timer you want as long as it is free running so you can see the changing values.

The PollRateOverride is in milliseconds. A value of 0 will make it update as fast as the communications allow.

thug_

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Unable to set polling interval of PLC through c# application
« Reply #6 on: January 19, 2017, 10:04:33 AM »
Yeah now I understand what you want to tell me... And it is true it is working.

But in my application unfortunately I am getting same refresh rate and that is 500mS. And I am not sure what I am doing wrong..

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Unable to set polling interval of PLC through c# application
« Reply #7 on: January 19, 2017, 10:13:49 AM »
In your posted code, you had a plcpoll timer instance. What is that doing?

thug_

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Unable to set polling interval of PLC through c# application
« Reply #8 on: January 19, 2017, 11:29:31 AM »
Idea is to give user permission to set time interval, in which he wants to get specific values from PLC. The way how I did, is I create that timer, that event fires up when user start the program, in that Tick event, application reading specific values from PLC, and update textboxes. So I want to make that update time changeable, right now whatever I enter it's updating every 500 ms.

Sorry I don't know if the way from beginning was good.

 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Unable to set polling interval of PLC through c# application
« Reply #9 on: January 19, 2017, 11:53:49 AM »
So you are using your own timing mechanism to update values and not the subscriptions. The subscriptions will be much more efficient and you would only have to change the PollRateOverride.

In your case, you probably need to stop the timer, change the interval , then start the timer again.

thug_

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Unable to set polling interval of PLC through c# application
« Reply #10 on: January 19, 2017, 11:56:42 AM »
Yes, right now works like that, can you write simple example or point to me where I can find more info about using subscription instead of this timer.


Thanks

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Unable to set polling interval of PLC through c# application
« Reply #11 on: January 19, 2017, 12:03:19 PM »
Tell me more about your application. Are you just displaying data on the screen? Is it for operator input? What controls are you using?

thug_

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Unable to set polling interval of PLC through c# application
« Reply #12 on: January 19, 2017, 12:15:06 PM »
Application should optimize trigger from 4 cameras. So I am giving parameters like trigger time, time interval, limits. Behind is running plc application which is recording date such as maximum inspection time, how many times inspection time went over given trigger time - and if it is over given limits in specific time interval, it is increasing/ decreasing trigger rate by the given value. So I would like to be able to set update time from plc.

It is WPF application which is using AdvancedHMI driver, SerialDF1forSLCMicroCom.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Unable to set polling interval of PLC through c# application
« Reply #13 on: January 19, 2017, 06:53:27 PM »
I'm not sure how well this will work with WPF, but here is an example of how to use Subscribe via code:

Code: [Select]
    Private SubscriptionID1 As Integer
    Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
        SubscriptionID1 = EthernetIPforCLXCom1.Subscribe("MyTag", 1, 500, AddressOf Subscription_DataReceived)
    End Sub

    Private Sub Subscription_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs)
        Label1.Text = e.Values(0)
    End Sub

    Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        EthernetIPforCLXCom1.UnSubscribe(SubscriptionID1)
    End Sub

thug_

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Unable to set polling interval of PLC through c# application
« Reply #14 on: January 20, 2017, 04:12:53 AM »
I'm not sure how well this will work with WPF, but here is an example of how to use Subscribe via code:

Code: [Select]
    Private SubscriptionID1 As Integer
    Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
        SubscriptionID1 = EthernetIPforCLXCom1.Subscribe("MyTag", 1, 500, AddressOf Subscription_DataReceived)
    End Sub

    Private Sub Subscription_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs)
        Label1.Text = e.Values(0)
    End Sub

    Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        EthernetIPforCLXCom1.UnSubscribe(SubscriptionID1)
    End Sub
I would like to test it with C# code the code which I am trying to implement is

public int subscriptionID1;
public SerialDF1forSLCMicroCom plc = new SerialDF1forSLCMicroCom();

private void btnStartTriggers_Click(object sender, RoutedEventArgs e)
{
subscriptionID1 = plc.Subscribe ("N7:4", 1, 500, ???);
plc.SubscritionDataRecived += plc_SubscritpionDataRecieved;
}

 void plc_SubscriptionDataReceived(object sender, MfgControl.AdvancedHMI.Drivers.Common.SubscriptionEventArgs e)
        {
            lblDataSubcribe.Content = e.Values(0);
        }

What I should put as a AddressOf Subscription_DataReceived ?

Thanks Archie