AdvancedHMI Software
General Category => Open Discussion => Topic started by: mopo on October 03, 2016, 03:57:08 AM
-
Hey Guys,
Great software! This could make my life so much easier.
I have the test app working great. I was wondering if anyone is able to point me in the right direction for using the library with a console app. The code below never fires an event.
static void Main(string[] args)
{
AdvancedHMIDrivers.EthernetIPforSLCMicroCom SLC = new AdvancedHMIDrivers.EthernetIPforSLCMicroCom();
SLC.IPAddress = "192.168.76.12";
DataSubscriber ds = new DataSubscriber();
ds.BeginInit();
ds.PLCAddressValue = new PLCAddressItem("N9:3");
ds.ComComponent = SLC;
ds.EndInit();
ds.DataChanged += Ds_DataChanged;
ds.SuccessfulSubscription += Ds_SuccessfulSubscription;
while (true)
{
Thread.Sleep(10);
}
}
private static void Ds_SuccessfulSubscription(object sender, EventArgs e)
{
throw new NotImplementedException();
}
private static void Ds_DataChanged(object sender, MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs e)
{
throw new NotImplementedException();
}
}
-
If you are writing everything in code, it's better to directly subscribe to the driver.
SubscriptionID=EthernetIPforSLCMicroCom1.Subscribe("N7:0", 1, 500, AddressOf DataReceived)
Private Sub DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs)
If e.ErrorId = 0 Then
Console.WriteLine(e.Values(0))
End If
End Sub
-
As Archie suggested, use the driver only and possibly create some sort of the mini DataSubscriber, similar to this:
class Program
{
static int SubscriptionID;
static string previousValue;
static void Main(string[] args)
{
EthernetIPforSLCMicroCom SLC = new EthernetIPforSLCMicroCom();
SLC.IPAddress = "192.168.76.12";
SubscriptionID = SLC.Subscribe("N9:3", 1, 500, SLC_SubscriptionDataReceived);
previousValue = SLC.Read("N9:3");
SLC.SubscriptionDataReceived += SLC_SubscriptionDataReceived;
while (true)
{
Thread.Sleep(10);
}
}
private static void SLC_SubscriptionDataReceived(object sender, MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs e)
{
if (e.ErrorId == 0)
{
if (e.Values[0] != previousValue)
{
Console.WriteLine("{0} Data Change, Old Value = {1}, New Value = {2}, {3}", e.PlcAddress, previousValue, e.Values[0], DateTime.Now);
previousValue = e.Values[0];
}
}
}
}
or the mini version of the DataSubscriber2, similar to this:
class Program
{
static int SubscriptionID0;
static int SubscriptionID1;
static string[] previousValue = new string[2] {"", ""};
static void Main(string[] args)
{
EthernetIPforSLCMicroCom SLC = new EthernetIPforSLCMicroCom();
SubscriptionID0 = SLC.Subscribe("B3:0/0", 1, 500, SLC_SubscriptionDataReceived);
previousValue[SubscriptionID0 - 1] = SLC.Read("B3:0/0");
SubscriptionID1 = SLC.Subscribe("N7:0", 1, 500, SLC_SubscriptionDataReceived);
previousValue[SubscriptionID1 - 1] = SLC.Read("N7:0");
SLC.SubscriptionDataReceived += SLC_SubscriptionDataReceived;
while (true)
{
Thread.Sleep(10);
}
}
private static void SLC_SubscriptionDataReceived(object sender, MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs e)
{
if (e.ErrorId == 0)
{
if (e.Values[0] != previousValue[e.SubscriptionID - 1])
{
Console.WriteLine("{0} Data Change, Old Value = {1}, New Value = {2}, {3}", e.PlcAddress, previousValue[e.SubscriptionID - 1], e.Values[0], DateTime.Now);
previousValue[e.SubscriptionID - 1] = e.Values[0];
}
}
}
}
-
Thanks Guys,
That worked great!
I found that the Subscribe event handler didn't fire so I just added a SubscriptionDataReceived handler and that fired.
Happy days!
All I need now is time to write some apps with this cool library!
-
I'm trying to do the same thing (run a test console app). but I;m getting a null reference exception thrown for OmronEthernetFINSCom.synchronizingObject.
Since I don't have a form to use as the synchronizingObject in my test app what can I do to resolve this?
OmronEthernetFINSCom comComponent = new OmronEthernetFINSCom()
{
IPAddress = "192.168.1.80",
ProtocolType = OmronEthernetFINSCom.ProtocolOptions.UDP
};
main.Initialize(comComponent);
public void Initialize(OmronEthernetFINSCom comComponent)
{
this.comComponent = comComponent;
this.comComponent.Subscribe(RUN, 1, 100, DataSubRun_DataReceived);
this.comComponent.Subscribe(FIXTURE_ID, 1, 100, DataSubFixtureID_DataReceived);
}
-
You are probably the first person to try a non-GUI application with the Omron drivers, therefore it has never been tested. But I believe there is an easy fix:
- In Solution Explorer under the AdvancedHMIDrivers project, expand down to the \Omron\FINS folder
- Right click FINSBaseCom.vb and select View Code
- Go to Line 767 which you should see this code:
If Not SubscriptionList(i).MarkForDeletion Then
m_SynchronizingObject.BeginInvoke(SubscriptionList(i).dlgCallback, x)
End If
- Replace that code with this code:
If Not SubscriptionList(i).MarkForDeletion Then
If m_SynchronizingObject IsNot Nothing AndAlso m_SynchronizingObject.InvokeRequired Then
m_SynchronizingObject.BeginInvoke(SubscriptionList(i).dlgCallback, x)
Else
SubscriptionList(i).dlgCallback(Me, f)
End If
End If
-
Awesome! Thanks
Note: I also needed to change Line 544
m_SynchronizingObject.BeginInvoke(SubscriptionList(i).dlgCallback, x)
to
If m_SynchronizingObject IsNot Nothing AndAlso m_SynchronizingObject.InvokeRequired Then
m_SynchronizingObject.BeginInvoke(SubscriptionList(i).dlgCallback, x)
Else
SubscriptionList(i).dlgCallback(Me, f)
End If