AdvancedHMI Software

General Category => Support Questions => Topic started by: pe.vallee on June 30, 2015, 09:48:39 AM

Title: PLC to C#
Post by: pe.vallee on June 30, 2015, 09:48:39 AM
HI !

I'm new here, I searched through the forum for anwsers and find few, so I've decided to ask my question here :P
I'm using an Omron CJ2 under OmronEthernetFINS, I try to retrieve Boolean data from it with C#.
Then I discover AdvancedHMI which allow some behaviors that I would like to do...

I just don't no if it is possible,  if yes ..  how ??

Thanks a lot :)
Title: Re: PLC to C#
Post by: Archie on June 30, 2015, 10:46:52 AM
See this:

http://advancedhmi.com/forum/index.php?topic=774.0
Title: Re: PLC to C#
Post by: pe.vallee on June 30, 2015, 10:51:01 AM
Thanks :)
Title: Re: PLC to C#
Post by: pe.vallee on June 30, 2015, 11:49:24 AM
I don't understand which of the AdvancedHMIControls Component should I use in a form ?

All I want to do is : "in a form.cs,  be able to show the value of my CJ2 PLC input (I took a mushroom button and set an input to true or false)"

My PLC  is connect at the IP adress 192.168.0.149, under the ID 10.10.3.40 there's the mushroom button plugged in at the adress  CIO0000.00

I supposed that I should insert the driver omronEthernetFINSCom and give him the IP adresse  192.168.0.149 in the properties panel....for the rest I'm stuck, may someone help me please :)
Title: Re: PLC to C#
Post by: Archie on June 30, 2015, 12:05:03 PM
- Add an OmronEthernetFINSCom to the form
- Set IPAddress to the address of your PLC
- Add a BasicIndictor to your form
- Set PLCAddressValue to 0.0
- Run the app
Title: Re: PLC to C#
Post by: pe.vallee on June 30, 2015, 12:20:23 PM
thanks for the help,  it doesn't work at all :(

in the properties table of the basicIndicator I haven't the tab PLCAddressValue :(

I'll continue my researches :(
Title: Re: PLC to C#
Post by: Archie on June 30, 2015, 12:23:12 PM
My mistake.... PLCAddressSelectColor2


I'm also not sure what you mean by "under the ID 10.10.3.40". Is that another IP address?
Title: Re: PLC to C#
Post by: pe.vallee on June 30, 2015, 01:05:45 PM
i'm not sure too, since I use KEPServerEX as my OPC Server, I think it's an ID that the server give to this PLC, understanding the Server may have many other PLC
Title: Re: PLC to C#
Post by: Archie on June 30, 2015, 01:30:20 PM
If you are using OmronEthernetFINSCom, then an OPC server has no relevance. You only need to know the IP Address of the PLC. The drivers do not use OPC (except OpcDaCom)
Title: Re: PLC to C#
Post by: pe.vallee on July 01, 2015, 08:56:03 AM
Can an OPC Server blocks device that want to communicate with PLC which are plugged in ??

I'm trying to communicate with a PLC to get its datas and then write data in it.   

Probably its my addresses which aren't good, but with


where did I go wrong ?
Title: Re: PLC to C#
Post by: Archie on July 01, 2015, 09:05:20 AM
The OPC server could be affecting it. I found with Omron that when I am online with CX-Programmer at the same time as running the HMI, the communication will get very bad.

As a simple test just add a BasicLabel and set the PLCAddressValue to D0

If you open a Command Prompt window, can you ping the IP address of the controller?
Title: Re: PLC to C#
Post by: pe.vallee on July 01, 2015, 09:10:47 AM
yup I can :\
Title: Re: PLC to C#
Post by: Archie on July 01, 2015, 09:28:13 AM
Did you try the BasicLabel? If there is an error, it should tell what it is. If it is working, it will change to value.

One other other is to try to change the ProtocolType on the driver.

If none of that works, you may have to install WireShark to do a packet capture and post it,
Title: PLC to C#
Post by: pe.vallee on July 01, 2015, 10:36:18 AM
I've install WireShark,(never use it before) set filters to Omron (since it is an Omron PLC  that I used).
I can see that the PLC (192.168.0.149) is talking (never stop !!)  with the input ID (10.10.3.40).
But when I manually toggle the button ('cause it's a button which is plugged in the PLC for my test).

I cannot see any difference of message from when the Boolean is set to True or False
Is there any way to see the message throught a network sniffer ?



Title: Re: PLC to C#
Post by: Archie on July 01, 2015, 10:43:55 AM
Those requests are coming very fast. Set the PollRateOverride of the OmronEthernetFINSCom driver to 1000

That should slow the reads to every 1 second.

If you save the capture and post it, I can see if you are getting any errors.
Title: Re: PLC to C#
Post by: Archie on July 01, 2015, 10:48:32 AM
That capture is not reads coming from AdvancedHMI. I ran a quick test using address 0.0 and the memory area code is different. The AdvancedHMI driver doesn't have support for a read area code of 0xb0
Title: Re: PLC to C#
Post by: pe.vallee on July 01, 2015, 11:14:06 AM
Yet I started the DEBUG Visual Studio. I do not understand why I can see in WireShark
Title: Re: PLC to C#
Post by: Archie on July 01, 2015, 11:17:39 AM
Do you still have the OPC driver running or CX-Programmer? What ever is communicating is reading every 10ms which is not giving AdvancedHMI a chance to get any communications in.
Title: Re: PLC to C#
Post by: pe.vallee on July 01, 2015, 11:18:19 AM
I shut the OPC Server down .. I don't know what is talking... :\
Title: Re: PLC to C#
Post by: Archie on July 01, 2015, 11:19:18 AM
If you run WireShark without AdvancedHMI running, do you still see all of the Omron packets?
Title: Re: PLC to C#
Post by: pe.vallee on July 01, 2015, 11:31:42 AM
yes, even if both, the server and the AdvancedHMI are off, there's still packets. I resolved the question.... I used a switch between my CPU and my PLC, the switch give my PC an internet access..

the Omron packets are between the switch and the PLC..  when I disconnect the plc from the switch and plug it in my PC, the packets stop,

but even if I bypass the switch, I cannot sniff any AdvancecHMI packets from WireShark...

Title: Re: PLC to C#
Post by: Archie on July 01, 2015, 11:34:54 AM
I'm kind of confused with your 2 IP addresses. They are on 2 completely different subnets, therefore must pass through a router somewhere. Was the switch you bypassed by any chance a router?

Are you now directly connected with an ethernet cable from your PC to your PLC?
Title: Re: PLC to C#
Post by: pe.vallee on July 01, 2015, 11:38:46 AM
this is the switch I used : http://ca.dlink.com/products/connect/8-port-gigabit-desktop-switch/ (http://ca.dlink.com/products/connect/8-port-gigabit-desktop-switch/)

if I bypass it to connect VIA an Ethernet cable my pc to my plc I will no longer connected to the internet but I'll have a direct link to my plc
Title: Re: PLC to C#
Post by: Archie on July 01, 2015, 11:54:04 AM
You need to get your PC and PLC on the same subnet. For example the PC IP address of 192.168.0.5 and the PLC 192.168.0.10

The 10.xx.xx.xx is another private network but on a different subnet.
Title: Re: PLC to C#
Post by: pe.vallee on July 01, 2015, 01:45:34 PM
IT WORKS!!!   AT LAST !!

The IP address 192.168.0.149 is the address of my Network Card  the IP address 10.10.3.40  is the address of my PLC the switch give to it ..    don't know why I haven't thought of it before !!
Title: Re: PLC to C#
Post by: pe.vallee on July 01, 2015, 01:47:42 PM
Many thanks for your help and for your time !!

I'll to work with the Advanced HMI :)

Best Regards !!!
Title: Re: PLC to C#
Post by: pe.vallee on July 02, 2015, 08:15:56 AM
One last question about that... :P

If, instead of a Form I want to use a console application.

I've create and Driver Object
Code: [Select]
private static AdvancedHMIDrivers.Omron.OmronEthernetFINSCom o_IPAdress = new AdvancedHMIDrivers.Omron.OmronEthernetFINSCom();
and then give him an IP Address
Code: [Select]
   o_IPAdress.IPAddress = s_address;
Then, I got this exception throwed by OmronEthernetFINSCom.vb
Code: [Select]
System.Exception was unhandled
  HResult=-2146233088
  Message=Incomplete Solution
  Source=MfgControl.AdvancedHMI.Drivers
  StackTrace:
       Ã  MfgControl.AdvancedHMI.Drivers.Omron.FinsTcpDataLinkLayer..ctor()
       Ã  MfgControl.AdvancedHMI.Drivers.Omron.FinsTcpDataLinkLayer..ctor(String ipAddress)
       Ã  AdvancedHMIDrivers.Omron.OmronEthernetFINSCom.CreateDLLInstance() dans C:\Users\pe.vallee\Documents\Visual Studio 2013\Projects\PLCToFileThread\AdvancedHMIDrivers\Omron\FINS\OmronEthernetFINSCom.vb:ligne 133
       Ã  AdvancedHMIDrivers.Omron.OmronEthernetFINSCom.set_IPAddress(String value) dans C:\Users\pe.vallee\Documents\Visual Studio 2013\Projects\PLCToFileThread\AdvancedHMIDrivers\Omron\FINS\OmronEthernetFINSCom.vb:ligne 31
       Ã  PLCToFileThread.PLCToFileThread.Main(String[] args) dans c:\Users\pe.vallee\Documents\Visual Studio 2013\Projects\PLCToFileThread\PLCToFileThread\Program.cs:ligne 49
       Ã  System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       Ã  System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       Ã  Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       Ã  System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       Ã  System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       Ã  System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       Ã  System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       Ã  System.Threading.ThreadHelper.ThreadStart()
  InnerException:


What did I do wrong ?
Title: Re: PLC to C#
Post by: Archie on July 02, 2015, 08:26:09 AM
Incomplete Solution means there is something missing from the project. Maybe the controls references or some of the drivers. AdvancedHMI only works as a compete solution with all of its original components and references.
Title: Re: PLC to C#
Post by: pe.vallee on July 02, 2015, 09:29:22 AM
I did what you suggest :
While executing the debug, I can see the value of the label change immediately when I toggle the button plug in the PLC address,
what is the
Code: [Select]
basicLabel1 property or method to call to acces the value of the label from the Console ?!
I tried in an
Code: [Select]
while( true )loop the code
Code: [Select]
Console.WriteLine( "basicLabel1 : " + basicLabel1.value);
( and many other properties and method but I can't see the value printed in the console..
even a basicLabel1.Refresh(); before the Console.WriteLine();   but it doesn't work :(
Title: Re: PLC to C#
Post by: pe.vallee on July 02, 2015, 10:04:52 AM
at last , I finally found my problem ....
in my Main I wrote
Code: [Select]
            basicLabel1.ValueChanged += basicLabel1_ValueChanged;

and in basicLabel1_ValueChanged() I wrote
Code: [Select]
            Console.WriteLine( "basicLabel1 : " + basicLabel1.Value );

finally!!! :P
Title: Re: PLC to C#
Post by: Archie on July 02, 2015, 01:37:19 PM
For a console app, you could read directly through the driver:

Dim MyValue as string = OmronEthernetFINSCom1.Read("D0")
Title: Re: PLC to C#
Post by: pe.vallee on August 10, 2015, 09:27:57 AM
I've got an error message if I had these lines of code :
Code: [Select]


            var _msg = driver.Read( "d0", 1 );            Console.WriteLine( _msg );




An unhandled exception of type 'MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException' occurred in AdvancedHMIDrivers.dll

Additional information: No reponse from PLC. Ensure baud rate is correct.


If I add a BasicLabel and set its address at "0" I can get the value,  but as soon as I add the Console output code, even if I didn't change the baud rate, I got this error.