Author Topic: Dynamic creation for DataSubscriber2? need help!  (Read 1431 times)

muratguenduez

  • Newbie
  • *
  • Posts: 22
    • View Profile
Dynamic creation for DataSubscriber2? need help!
« on: September 14, 2018, 08:33:13 AM »
hail all,
i have tried basic addition dynamicly for DataSubscriber2 but i coudnt get any values.

i added a ModbusTCPCom  modbusTCPCom1 from toolbox as drag and drop,

then i added dynamicly a DataSubscriber2 ds, ModbusTCPCom mbDelta and  PLCAddressItem item0 = new PLCAddressItem { PLCAddress = "U44597", Name = "L1" };
when the ds.Comcomponent =  modbusTCPCom1; is ok i read my first object L1 by ds.GetValuesByName("L1");

but ds.Comcomponent = mbDelta; is not working.
i tried to copy all setup for modbusTCPCom1 from designer.cs even more  =) i miss something here. anyway code is below,


Code: [Select]
public partial class Form1 : Form
    {
        PLCAddressItem item0 = new PLCAddressItem { PLCAddress = "U44597", Name = "L1" };
        ModbusTCPCom mbDelta = new ModbusTCPCom();     
        DataSubscriber2 ds = new DataSubscriber2();

        public Form1()
        {

            InitializeComponent();

            mbDelta.BeginInit();
            ds.BeginInit();

            mbDelta.DisableSubscriptions = false;
            mbDelta.IniFileName = "";
            mbDelta.IniFileSection = null;
            mbDelta.IPAddress = "192.168.1.5";
            mbDelta.MaxReadGroupSize = 20;
            mbDelta.PollRateOverride = 500;
            mbDelta.SwapBytes = true;
            mbDelta.SwapWords = true;
            mbDelta.TcpipPort = ((ushort)(502));
            mbDelta.TimeOut = 20000;
            mbDelta.UnitId = ((byte)(1));


           
            ds.ComComponent = mbDelta;
            ds.PLCAddressValueItems.Add(item0);
            ds.PollRate = 0;           
            ds.SynchronizingObject = this;           
            ds.Value = null;
            ds.EndInit();
            mbDelta.EndInit();

           
            timer1.Start();
        }

private void timer1_Tick(object sender, EventArgs e)
        {
           
            richTextBox1.Text = ds.GetValueByName("L1");
           
        }
}
« Last Edit: September 14, 2018, 08:36:58 AM by muratguenduez »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Dynamic creation for DataSubscriber2? need help!
« Reply #1 on: September 14, 2018, 08:50:22 AM »
Creating a DataSubscriber in code really doesn't make a lot of sense because it is easier to directly subscribe to the driver. The main reason the DataSubscriber was created was to wrap the complexities of driver subscriptions into a drag and drop component.

muratguenduez

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Dynamic creation for DataSubscriber2? need help!
« Reply #2 on: September 14, 2018, 09:40:33 AM »
well,
what is wrong in my code ?

actually it should be easy i think. something wrong with my modbusTCPCom setup.

dinamic ds is working on drag-dropped modbusTCPCom but why dynamic ds is not working on dynamic modbusTCPCom ?

this was my first code before the copied all setup from designer.cs

Code: [Select]
public partial class Form1 : Form
    {     
        PLCAddressItem item0 = new PLCAddressItem { PLCAddress = "U44597", Name = "L1" };
        ModbusTCPCom mbDelta = new ModbusTCPCom { IPAddress = "192.168.1.5"};       
        DataSubscriber2 ds = new DataSubscriber2();

        public Form1()
        {
            InitializeComponent();
            timer1.Start();
        }

       
        private void Form1_Load(object sender, EventArgs e)
        {
            ds.BeginInit();
            ds.ComComponent = mbDelta;// !!!!!!!!!!!! changing to mbDelta to modbusTCPCom1(drag-dropped) is working. !!!!!!!!!!!!!!!!!!!!!!!!!!
            ds.PLCAddressValueItems.Add(item0);
            ds.EndInit();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
           
            richTextBox1.Text = ds.GetValueByName("L1");
           
        }
}

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Dynamic creation for DataSubscriber2? need help!
« Reply #3 on: September 14, 2018, 04:21:17 PM »
Where are you event handlers for the DataSubscriber? How do you know it is not working?