Wednesday 30 March 2016

My Simple OPC Client

As request from our friends, here we create a simple VB application/project to communicate with OPC Server.

Previously, we create My OPC Client project, the latest is version 5, with some advanced feature. But some friends need more simple application, so we create this project. The purpose of the application is to connect to OPC Server, Read data and Write data. So here is MySimpleOPCClient..




For testing, we use Matrikon OPC Explorer, you can download from here.
Please download MySimpleOPCClient project source code from here.


The steps:
1. Run Matrikon OPC Explorer
2. Create group, and add some items to monitor, ie "Bucket Brigade.Int1"
4. Run MySimpleOPCClient
5. Write "Matrikon.OPC.Simulation.1" on OPC Server Name textbox
6. Click Connect button
7. On OPC Item textbox, write "Bucket Brigade.Int1"
8. Click on Add Item button
9. The value of item is automatically loaded to the Read Value textbox
10. Try to write new value on Write Value textbox, then click on Write button




Note: 
Before opening the project, please make sure you have OPCDAAuto.dll installed/registered on your system. Please follow these steps to register the DLL:
> download DLL from here
> copy file to /System32 folder
> open CMD (command prompt)
> write this command: "regsvr32 OPCDAAuto.dll"

We create this project with MS Visual Studio Express 2010, and we targeted to .NET Framework 4. If you get some problem, please let us know.

See you next time.. Thank you...

35 komentar:

  1. Wow! Thanks a lot!
    So simple and functionally ;)

    ReplyDelete
  2. hello,can you help me Mister hadi hidayat,i went to send data from c# to labview so i will use ni opc server from national instrument and in c# i need to build opc client how can communicacat with ni opc server,please i need a help

    ReplyDelete
  3. i need a code of opc client in c# witch i can send data to ni opc server im sorry im not native speaker

    ReplyDelete
    Replies
    1. Hi,
      you can convert the source code here from VB to C using this tool:
      http://www.developerfusion.com/tools/convert/vb-to-csharp/

      Thanks.

      Delete
  4. Hi

    I can't install the OPCDAAuto.dll
    I'm always getting "The specified module can not be found"
    I must say that I'm using a 64-bit WIN7 operating system
    Can you help me out?

    ReplyDelete
    Replies
    1. Hi..

      try:
      > copy OPCDAAuto.dll to folder C:\windows\syswow64
      > open Command Prompt with "Run as Administrator"
      > type: "cd \windows\syswow64"
      > type: "regsvr32 OPCDAAuto.dll"

      Thanks.

      Delete
    2. Thanks! Now going to try to communicate with Simatic NET OPC Server.

      Delete
  5. Hello Hadi,
    Your blogs are wonderful and very much supportive for me.
    I need documentation of the dlls (OPCDAAuto.dll and Interop.OPCAutomation.dll) you used in the project.
    Thanks.
    Regards,
    Fahad

    ReplyDelete
    Replies
    1. Hello,
      Thanks for your appreciation.
      Please visit OPC Foundation website here:
      https://opcfoundation.org/developer-tools/developer-kits-classic/core-components

      or you can ask to OPC Foundation support by email.

      Delete
  6. Hi Hadi, thank you for the codes, they are very useful and precious.

    ReplyDelete
    Replies
    1. Hi Mateus... You are welcome.

      Delete
    2. Thanks, I'm a benginner in VB.net, do you know if is possible to convert your code to a console aplication?

      I'm trying but if this not possible I will stop to try it.

      Delete
    3. Hi..
      Sorry, I dont know about that. But I think, it's better for you to try.. so you will know the answer..
      Good luck!

      Delete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. Hello Hadi and thank you for your work. I have tested your applicaiton My OPCClientC on window 7 64 bit SP1 and it doesn't work. When click on List OPC servers, there is an unhandeled exception HRESULT E_FAIL has been returned from a call to a COM component.
    I have previously successfully registered OPCDAAuto.dll in syswow64 folder.

    ReplyDelete
    Replies
    1. maybe you can open the VB project, then you can do debugging, find out where is the error occurs.
      Thanks.

      Delete
  10. Hello Hadi, Does your software also work with the OPC UA standard? Ho installato il Prosys OPC UA Simulation Server e purtroppo col tuo sofware non riesco a connettermi ... riesci ad aiutarmi? Maurizio Romerio (ITALIA, Arona -NO)

    ReplyDelete
  11. Hello Hadi, Does your software also work with the OPC UA standard? I installed the Prosys OPC UA Simulation Server and unfortunately with your software I can't connect ... can you help me? Maurizio Romerio (ITALIA, Arona -NO) studium@progettoleonardo.it

    ReplyDelete
    Replies
    1. my OPC project not yet support OPC UA.
      thanks..

      Delete
  12. hello hadi, your code works perfectly with the opc im trying to connect, thank you for sharing it with the world... however i would like to ask for your help, im trying to read more than one item form an opc server but cant manage to create a working code to do so, could you share with me an example or some documentation for me to understand the codes, ... best regars!

    ReplyDelete
    Replies
    1. please try https://hadiscada.blogspot.com/2013/07/my-opc-client.html

      Delete
  13. ini dll nya udh full kah om??
    maksudnya tanpa ada batas waktu nya??

    ReplyDelete
  14. Hi , can you say this client use which port to connect to opc, i try connect to opc in another pc . But get ACCESS DENIED ERROR.

    ReplyDelete
    Replies
    1. Hi..
      it use default OPC port (502)..
      to access OPC Server in another PC, you must set/config DCOM first.
      Thanks.

      Delete
  15. Hi Hadi,

    Please could you help. How do you browse the OPC server for all tags?

    ReplyDelete
    Replies
    1. you can use MyOPCClient project, here: https://hadiscada.blogspot.com/2013/07/my-opc-client.html

      Delete
  16. Hi Hadi,
    Hope u r doing well.
    U did great work by writing above code for learners.

    Well, I want to ask you that I need to add more items in same group to read more value from PLC, so how can i do this ?
    Should I add below lines

    AddHandler MyOPCGroup.DataChange, AddressOf
    MyOPCGroup_Datachange1

    AddHandler MyOPCGroup.AsyncReadComplete, AddressOf MyOPCGroup_AsyncReadComplete1

    Private Sub MyOPCGroup_Datachange1(ByVal TransactionID As Integer, ByVal NumItems As Integer, ByRef ClientHandles As System.Array, ByRef ItemValues1 As System.Array, ByRef Qualities As System.Array, ByRef TimeStamps As System.Array)

    TextBoxReadOUT.Text = ItemValues1(1)

    End Sub
    OR
    Kindly tell about code which I should write to get more values.

    Thanks
    HK

    ReplyDelete
    Replies
    1. i think you can see in My OPC Client article.

      Delete
  17. HI this is really good, exactly what I'm looking for. Unfortunately I get an error caught by the try when clicking on Connect. It doesn't matter what I enter into the server name box, I get the same error regardless. The error message is 'Invalid Class String' (Exception from HRESULT 0x800401F3 (CO_E_CLASSSTRING)
    Any help would be greatly appreciated , thanks a lot.

    ReplyDelete
    Replies
    1. i think you have problem with OPCDAAuto.dll, please check is it already successfully registered in your PC.

      Delete
  18. project file is not accessible. please see link

    ReplyDelete
    Replies
    1. Sorry. I already update the link, please try again. Thanks.

      Delete

 
Copyright © . HadiSCADA - Posts · Comments
Theme Template by BTDesigner · Powered by Blogger