AdvancedHMI Software

General Category => Open Discussion => Topic started by: thug_ on January 19, 2017, 08:42:31 AM

Title: Unable to set polling interval of PLC through c# application
Post by: thug_ 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
Title: Re: Unable to set polling interval of PLC through c# application
Post by: Archie 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.
Title: Re: Unable to set polling interval of PLC through c# application
Post by: thug_ 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
Title: Re: Unable to set polling interval of PLC through c# application
Post by: Archie 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.
Title: Re: Unable to set polling interval of PLC through c# application
Post by: thug_ 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
Title: Re: Unable to set polling interval of PLC through c# application
Post by: Archie 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.
Title: Re: Unable to set polling interval of PLC through c# application
Post by: thug_ 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..
Title: Re: Unable to set polling interval of PLC through c# application
Post by: Archie on January 19, 2017, 10:13:49 AM
In your posted code, you had a plcpoll timer instance. What is that doing?
Title: Re: Unable to set polling interval of PLC through c# application
Post by: thug_ 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.

 
Title: Re: Unable to set polling interval of PLC through c# application
Post by: Archie 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.
Title: Re: Unable to set polling interval of PLC through c# application
Post by: thug_ 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
Title: Re: Unable to set polling interval of PLC through c# application
Post by: Archie 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?
Title: Re: Unable to set polling interval of PLC through c# application
Post by: thug_ 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.
Title: Re: Unable to set polling interval of PLC through c# application
Post by: Archie 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
Title: Re: Unable to set polling interval of PLC through c# application
Post by: thug_ 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
Title: Re: Unable to set polling interval of PLC through c# application
Post by: Archie on January 20, 2017, 04:20:40 AM
Code: [Select]
       private int SubscriptionID1;
        private void Button2_Click_1(object sender, EventArgs e)
        {
            SubscriptionID1 = ethernetIPforCLXCom1.Subscribe("MyTag", 1, 500, Subscription_DataReceived);
        }

        private void Subscription_DataReceived(object sender,MfgControl .AdvancedHMI . Drivers.Common.PlcComEventArgs e)
        {
            Label1.Text = e.Values[0];
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            ethernetIPforCLXCom1.UnSubscribe(SubscriptionID1);
        }
Title: Re: Unable to set polling interval of PLC through c# application
Post by: thug_ on January 20, 2017, 05:11:12 AM
Code: [Select]
       private int SubscriptionID1;
        private void Button2_Click_1(object sender, EventArgs e)
        {
            SubscriptionID1 = ethernetIPforCLXCom1.Subscribe("MyTag", 1, 500, Subscription_DataReceived);
        }

        private void Subscription_DataReceived(object sender,MfgControl .AdvancedHMI . Drivers.Common.PlcComEventArgs e)
        {
            Label1.Text = e.Values[0];
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            ethernetIPforCLXCom1.UnSubscribe(SubscriptionID1);
        }
Thanks Archie, it is working, I will need to updated a lot of code now, but at least there is a way to control polling time.

Just quick question about this number of elements, I am right now setting it to 1, that means I suppose it will read one element from plc and that is in this case N7:4 or whatever tag I provide. In the case this number of elements is higher let's say 10, is that mean that it will read elements from N7:0 until and including N7:9 ?

Cheers
Title: Re: Unable to set polling interval of PLC through c# application
Post by: Archie on January 20, 2017, 08:39:59 AM
Just quick question about this number of elements, I am right now setting it to 1, that means I suppose it will read one element from plc and that is in this case N7:4 or whatever tag I provide. In the case this number of elements is higher let's say 10, is that mean that it will read elements from N7:0 until and including N7:9 ?
Just off the top of my head, I do not know if that particular driver supports that. Some of the drivers do support it, but I cannot remember if that one does. In the original design, it wasn't needed because subscriptions were only used by the built in controls which only used one element. Later on as more complex controls were added, this was implemented in the most popular drivers.