Author Topic: EthernetIPforCLX driver: SubscriptionID reset  (Read 1043 times)

trung.bui

  • Newbie
  • *
  • Posts: 6
    • View Profile
EthernetIPforCLX driver: SubscriptionID reset
« on: February 21, 2019, 02:11:17 AM »
Hi bro,
I'm writing a console application using Subscription to trigger another Subscription but notice that after Unsubscribe the ID still count up. Is this normal or that subscription haven't unsubscribed and released?
Thank for your help!!
Code: [Select]
private static EthernetIPforCLX EthernetIPforCLXCom1;

        private static int SubscriptionID0;
        private static int SubscriptionID1;

        static void Main(string[] args)
        {
            EthernetIPforCLXCom1 = new EthernetIPforCLX();

            EthernetIPforCLXCom1.IPAddress = "192.168.137.134";
            EthernetIPforCLXCom1.ProcessorSlot = 0;
            EthernetIPforCLXCom1.PollRateOverride = 0;

            SubscriptionID0 = EthernetIPforCLXCom1.Subscribe("_Event_buffer_PLC_ptr", 1, EthernetIPforCLXCom1_SubscriptionDataReceived);
            EthernetIPforCLXCom1.SubscriptionDataReceived += EthernetIPforCLXCom1_SubscriptionDataReceived;
            EthernetIPforCLXCom1.SubscriptionDataReceived += EthernetIPforCLXCom1_SubscriptionDataReceived1;

            while (true)
            {
                Thread.Sleep(10);
            }
        }

        private static void EthernetIPforCLXCom1_SubscriptionDataReceived(object sender, PlcComEventArgs e)
        {
            //throw new NotImplementedException();

            SubscriptionID1 = EthernetIPforCLXCom1.Subscribe("_Event_data_buffer_array[0,0]", 1, EthernetIPforCLXCom1_SubscriptionDataReceived1);
           
        }

        private static void EthernetIPforCLXCom1_SubscriptionDataReceived1(object sender, PlcComEventArgs e)
        {
            //throw new NotImplementedException();
            //do st

            EthernetIPforCLXCom1.UnSubscribe(SubscriptionID1);
            Console.WriteLine(SubscriptionID1);
        }

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLX driver: SubscriptionID reset
« Reply #1 on: February 21, 2019, 07:04:54 AM »
Every subscription is assigned a unique ID number and the numbers are not re-used. It is up to you to save the ID and unsubscribe from the ID when the data is no longer needed.

Why are you using a subscription in your first callback instead of a read?
Code: [Select]
private static void EthernetIPforCLXCom1_SubscriptionDataReceived(object sender, PlcComEventArgs e)
        {
            //throw new NotImplementedException();

            Value = EthernetIPforCLXCom1.Reade("_Event_data_buffer_array[0,0]");
           
        }

trung.bui

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: EthernetIPforCLX driver: SubscriptionID reset
« Reply #2 on: February 21, 2019, 09:28:16 AM »
Thank you for reply,
"_Event_buffer_PLC_ptr" is the pointer to indicate the start index to read in the array. It will change (increase) randomly and i will base on that value to read some of continuous values in the array. When "_Event_buffer_PLC_ptr" change i will read (_Event_buffer_PLC_ptr - Previous_Event_buffer_PLC_ptr) array data (some time data will be > 508 bytes)

Wonder is there any better way to read?
What happens when SubscsribeID exceed int.MaxValue?

« Last Edit: February 21, 2019, 09:32:35 AM by trung.bui »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLX driver: SubscriptionID reset
« Reply #3 on: February 21, 2019, 09:42:03 AM »
Once the subscriptionID exceeds the integer limit, it will probably throw an exception. Subscriptions were not intended for only a single read. With your program and the PollRateOverride set to 0, you will probably be creating a new subscription every 5ms then removing it only after a single read. Subscriptions are intended for continuous updating of a value. The Read Method is the way to read only a single time.

Your current method is creating a lot of overhead to create a subscription, then unsubscribe after only 1 value is read.

trung.bui

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: EthernetIPforCLX driver: SubscriptionID reset
« Reply #4 on: February 21, 2019, 10:08:59 AM »
Understood, last question:
So can i use
myArray = Read(array[0,0],1000)?
to read 1000 elements?
Data type is int
or need to split to read
Because i heard about 508 bytes limit?

Thank you!
« Last Edit: February 21, 2019, 10:26:49 AM by trung.bui »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLX driver: SubscriptionID reset
« Reply #5 on: February 21, 2019, 10:27:04 AM »
The 508 byte limit is a CIP limit, but from a user perspective the driver hides this. It will be handled in the background.

Yes you can use Read for arrays.