AdvancedHMI Software
General Category => Open Discussion => Topic started by: muratguenduez 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,
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");
}
}
-
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.
-
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
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");
}
}
-
Where are you event handlers for the DataSubscriber? How do you know it is not working?