PVSS and c#

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
34 posts • Page 3 of 4
vogler
Posts:122
Joined: Thu Oct 28, 2010 8:32 am

Re: PVSS and c#

Post by vogler »

sorry, in this lib there is not yet a "dpConnect" :-(
what you can do is to implement a C#/XMLRPC for dpWaitForValues (see OA online help)... not really a connect, and you can loose values... and it is also still not yet in this lib (i think).
WinForms - create a forms project and and add the assemblies/libs... should be possibly.
i really would like to help you and implement some demo, but i am not sure if i will find (private) time here, maybe afternoon at the hotel...
or you can call my boss to give an offer to you for consulting hours...

mwerksma
Posts:19
Joined: Fri Jul 01, 2011 1:21 pm

Re: PVSS and c#

Post by mwerksma »

Andy,

Thank you for your answer, there is no hurry and not (yet) needed for a project so consulting hours will not be possible.
In januari a Siemens collegue will help me with the code he created, should work like I want to but I am not sure we will have time for it.
As you say it is mostly done in private time...

Have a nice day,

Marcel

vogler
Posts:122
Joined: Thu Oct 28, 2010 8:32 am

Re: PVSS and c#

Post by vogler »

Hi,

I created a very basic WinForms-App with a fake dpConnect => dpWaitForValue...
Import the ascii-export file "example.dpl" and start a ctrl-manager "xmlrpc_server.ctl".
Start debug\\WindowsFormsApplication1 (on windows or on linux & mac with mono!)
Set the dps Example_0001.int or Example_0002.int from para.
With the third text box and the button next to it you can set the value of "Example_0001.int" from winforms.

quick & dirty!! ;-)
take care,
Andy

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using Roc.WCCOA;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        WCCOABase conn;
        WCCOATagList list;

        public Form1()
        {
            InitializeComponent();

            conn = new WCCOABase("localhost", 8080, "RPC2", new NetworkCredential("root", ""), 10000);
            list = new WCCOATagList(conn);

            // add datapoints to "watch"-list
            list.Add("Example_0001.int");
            list.Add("Example_0002.int");

            // add a callback function (delegate)
            list.AddDataChangedAction(TagListAction);

            // start a thread and wait endless for change of values  
            Task t = Task.Factory.StartNew(() => { 
                while (true) list.WaitDataMulti(); // timeout/wait is set to 5 seconds
            });

        }

        //--------------------------------------------------------------------------------------------------------------------
        public void TagListAction(WCCOATagList TagList, bool FirstUpdate)
        {
            Console.WriteLine("TagListAction => " + FirstUpdate + " " + TagList.TagListChanged.Count);

            // for each changed datapoint value
            foreach (WCCOATag t in TagList.TagListChanged)
            {
                this.BeginInvoke(new Action(() =>
                {
                    switch (t.DpName)
                    {
                        case "Example_0001.int": textBox1.Text = t.Value.Value.ToString(); break;
                        case "Example_0002.int": textBox2.Text = t.Value.Value.ToString(); break;
                    }
                }));
            }           
        }

        private void button1Click(object sender, EventArgs e)
        {
            // set value of textbox to first datapoint
            conn.setValue(list.TagList[0].DpName, textBox3.Text);
        }
    }
}
https://www.winccoa.com/fileadmin/image ... s/Test.zip

vogler
Posts:122
Joined: Thu Oct 28, 2010 8:32 am

Re: PVSS and c#

Post by vogler »

It really runs on the Mac ... just copied the .net exe :-)
http://youtu.be/mia-YEfEJII

clicht
Posts:24
Joined: Tue Aug 03, 2010 8:11 am

Re: PVSS and c#

Post by clicht »

Attached you can find a simple XML-RPC server in CTRL and a correspondig C# Console Application with a XML-RPC-Client.
With this solution a subscription to a set of DPEs is possible. The solution implements the long polling pattern.

The client code is very simple:

Code: Select all

  class Program
  {
    static void Main(string[] args)
    {
      OaXmlRpcApi api = new OaXmlRpcApi("localhost", 4770);
      api.SubscribeDpes(new string[] { "ExampleDP_Arg1.:_online.._stime", "ExampleDP_Arg1.:_online.._value" }, api_subscriptionCB);
      while (true)
      {
        Thread.Sleep(1 * 1000);
      }
    }

    private static void api_subscriptionCB(string[] dpes, object[] values)
    {
      string s = DateTime.Now.ToString();
      for (int i = 0; i < dpes.Length; i++)
      {
        s += ", " + dpes[i] + ", " + values[i].ToString();
      }
      Console.WriteLine(s);
    }
  }
At the moment the timeouts for long polling in the server are hardcoded.
This means the client get soonest after 1 second and no later than 20 seconds a response.
If within this period a DPE value changed the callback method is called.

Hope this is what you are looking for.

Christian

https://www.winccoa.com/fileadmin/image ... iption.zip
Attachments
XmlRpcSubscription.zip
(12.2 KiB) Downloaded 171 times

vogler
Posts:122
Joined: Thu Oct 28, 2010 8:32 am

Re: PVSS and c#

Post by vogler »

I now implemented a .Net Proxy for a real dpConnect...

Communication from .Net client to the proxy is done with:

* .net remoting for "commands" (dpConnect, dpQueryConnect)

* tcp (xml over tcp) for sending data / events (control to proxy to n client)

The proxy also acts as a distributor - if clients have the same dp(Query)Connects, the connects in the control are done once, and the proxy will forward it to the clients.

take care,
Andy

Image https://www.winccoa.com/fileadmin/image ... /Proxy.zip
Attachments
Proxy.zip
(427.81 KiB) Downloaded 176 times
Unbenannt.PNG

pluns
Posts:3
Joined: Tue Jun 14, 2011 11:58 am

Re: PVSS and c#

Post by pluns »

He Marcel,

We've basically created the same solution to provide information from PVSS to a website displaying the values of datapoints.

Come have a look when you're in the office.

Regards Peter B)

clicht
Posts:24
Joined: Tue Aug 03, 2010 8:11 am

Re: PVSS and c#

Post by clicht »

I found a possible alternative: WCF

WCF is based on SOAP. SOAP is similar to XML-RPC but more flexible and therefore more complex.

If you search at google you can find lots of solutions which do a communication between C++ (SOAP) and DotNet (WCF). Search for "gSOAP WCF".

For the server part I would prefer "gSOAP" (http://gsoap2.sourceforge.net). It is open source and supports communication over HTTP, TCP and UDP. Via plugin also other ways are possible (e.g. Named Pipes).
Further I read that schema files are supported, which minimizes the effort for serialization.

After download of gSOAP I see that there is an example for WCF included, but I didn't tried it out.

"All" you need to do is: Write a API-Manager which includes gSOAP. Define a interface and write the client with WCF DotNet, which implements the client interface

vogler
Posts:122
Joined: Thu Oct 28, 2010 8:32 am

Re: PVSS and c#

Post by vogler »

alternative for what? :-) dpConnect? .Net Remoting is part of WCF (i used it for communication between .net client and .net proxy), but as far as i know it is still REST, also SOAP is REST, so no "active" connection to send values unsolicited from server to the client (dpConnect) (if the client opens the connection...)

btw. googles protobuf is also a cool protocol....

clicht
Posts:24
Joined: Tue Aug 03, 2010 8:11 am

Re: PVSS and c#

Post by clicht »

It is a alternative for XML-RPC in combination with your .NET Proxy.
Both get one component.
Therefore the performance should be better.

Further there are a lot of examples available in the internet which descibes how the publish-subscribe pattern could be implemented with WCF or SOAP.

In detail:
I think over HTTP only BOSH (also called long polling) is possible. This is similar to the solution with XML-RPC.
But SOAP also supports TCP communication. I think there should be more possible.

With this solution
[ol]
[*]only one port is opened on server side, [*]
[*]only two components are necessary (one for server and one for client),[*]
[*]the protokoll is standard and[*]
[*]is usable on all platforms[*]
[/ol]

34 posts • Page 3 of 4