PVSS and c#

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

Re: PVSS and c#

Post by vogler »

Hi Marcel, currently i am in the office Siemens Nederland... if you want we can talk about your issue... i will be back on monday.

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

Re: PVSS and c#

Post by mwerksma »

Hello Andreas,

I work in Zoetermeer and I am very busy with our current project so I don't have time to come to Den Haag, sorry.
I am curious how to create the events in C# so we can create small applications out of PVSS but do use the database.

A while ago I have sent this question to the ETM helpdesk but there they could not fix my problem/question.

If you have time could you contact me please, thank you for your quick response.

Marcel

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

Re: PVSS and c#

Post by clicht »

Hi

Take a look into the xmlrpcHandlerCommon.ctl in the /script/libs directory.
I think there is a functionality implemented, which allows similar to a subscription. This library could be simple integrated in the XML-RPC server. Just call methodHandlerCommon() function.

Remark: A real subscription is not possible over xml-rpc, because it uses http and there connections have a short timeout.

As I remember this functionality uses the "long polling" pattern in combination with a buffer.

Unfortunately there is no client implementation in C# available.

On client side you must start a thread which do cyclic a request of the buffer. If you increase the connection timeout (or is this a setting of the server, I can't remember) than the message overhead is very low.
If something is in the buffer the client get informed and can fire a event or call a delegate.

In this library also a set of other useful functions is implemented.

Hope this helps.
Christian

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

Re: PVSS and c#

Post by mwerksma »

Christian,

Thank you for your quick response.

I already use the xmlrpcHandlerCommon.ctl and there I see the functions below:


case "pvss.db.startSubscriptionValues":
//int pvss.db.startSubscriptionValues(dyn_string dpes, mapping settings)
methodResult = xmlrpc_pvss_db_startSubscriptionValues(sMethod, asValues);
break;
case "pvss.db.stopSubscriptionValues":
//int pvss.db.stopSubscriptionValues(dyn_int subId)
methodResult = xmlrpc_pvss_db_stopSubscriptionValues(sMethod, asValues);
break;
case "pvss.db.startQuerySubscriptionAlerts":
//int pvss.db.startQuerySubscriptionAlerts(mapping filter, mapping settings)
methodResult = xmlrpc_pvss_db_startQuerySubscriptionAlerts(sMethod, asValues, language);
break;


Cab you tell me how I should use these functions in combination with eachother?
In the comment of the function xmlrpc_pvss_db_startSubscriptionValues this text below is written.

///
/// calculates a subscriptionId and executes a dpQueryConnectSingle
/// (re-)starts the killConnectionThread for the subscription
///

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

Re: PVSS and c#

Post by clicht »

The server uses dpQueryConnectSingle instead of dpConnect.

I think (not sure) you must call on client side (pseudo code):

clientId = pvss.db.getClientSubscriptionId();
subId = pvss.db.startSubscriptionValues(dpes, settings, clientId);

Start Thread and run following in the thread:
while (true)
{
result = pvss.db.getSubscriptionBuffer( new int[] {subId});
if (result contains something)
{
//fire event or call callback
}
//delay 1 second

}

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

Re: PVSS and c#

Post by mwerksma »

Wow,

That was what I was looking for, thank you I will try the code.

Marcel

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

Re: PVSS and c#

Post by mwerksma »

Hello Cristian,

Below is my C#code but I get an error that the parameters are wrong, do you have any idea what I am doing wrong?
In the comment you can see where the error appears and what the error message is.
It is a simple project with a form, a button and a label for error messages

Thank you for your time,

Marcel


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using CookComputing.XmlRpc;

namespace RPCTest
{
public partial class Form1 : Form
{

[XmlRpcUrl("http://localhost/RPC2")]
public interface IStringValues : IXmlRpcProxy
{
//Declare PVSS functions
[XmlRpcMethod("pvss.db.getClientSubscriptionId")]
Object GetClientSubscriptionId();
[XmlRpcMethod("pvss.db.startSubscriptionValues")]
Object StartSubscriptionValues(string ObjectName, Object[] Settings);

}

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Object ClientSubscriptionId = GetClientSubscriptionId_DotNet();
//Subscription ID is 1 @ firtst then 2 and so on, must be ok I think
object[] Settings = new[] { "", "", ClientSubscriptionId.ToString() };
Object dpConnectResult = StartSubscriptionValues_DotNet("test", Settings);
}

public Object GetClientSubscriptionId_DotNet()
{
Object res = null;
try
{
IStringValues s = XmlRpcProxyGen.Create();
res = s.GetClientSubscriptionId();
}
catch (XmlRpcFaultException fex)
{
lblError.Text = fex.FaultString;
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
return res;
}

public Object StartSubscriptionValues_DotNet(string ObjectName, Object[] Settings)
{
Object res = null;
try
{
IStringValues s = XmlRpcProxyGen.Create();
res = s.StartSubscriptionValues(ObjectName, Settings);
}
catch (XmlRpcFaultException fex)
{
//Here I get the error:

// PVSS00ui (1), 2012.12.13 20:22:07.817, SYS, SEVERE, 51, Parameter incorrect, Error parsing xml-rpc stream, Method: pvss.db.startSubscriptionValues,

lblError.Text = fex.FaultString;
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
return res;
}

}
}

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

Re: PVSS and c#

Post by clicht »

Hi

Take a look at the Server-Log-File. There should be further information.
Maybe the object[] settings is the problem.
Therefor is nothing implemented on the server and should be empty.
I think this would work if you transfer an empty KeyValuePair or hashtable. If this is not working define a empty class or struct.

Further I think you defined the methods wrong:
[XmlRpcMethod("pvss.db.getClientSubscriptionId")]
uint GetClientSubscriptionId();
[XmlRpcMethod("pvss.db.startSubscriptionValues")]
uint StartSubscriptionValues(string[] ObjectName, KeyValuePair Settings, uint clientId);

Remark: If you implement the XML-RPC server right the fault/error return values are transferd to XML-RPC errors and result into a exception on client side. This means you could define the XML-RPC methods typesave with the real types.
The "mixed" return values are workarounds on serverside, because exceptions was not available as the library was written.

A good example for a correct XML-RPC server is available in the AddOn "Etool" of the WinCC OA installation.
There is also a workaround for a bug in the XML-RPC server implemented:
sTmp = content;
if (getType(sTmp) == STRING_VAR)
{
strreplace(sTmp, " />", "/>");
strreplace(sTmp, "", "");
}


Christian

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

Re: PVSS and c#

Post by vogler »

Hi,

have seen christian already gave you all needed information :-)

if you are interested, some time ago i created a basic C# library - i played with C# + XMLRPC + WinCC OA to create iPhone and Android mobile applications with MonoTouch (www.xamarin.com - pretty cool product)

I have now uploaded the source to sourceforge:
http://sourceforge.net/projects/roc-xmlrpc/
http://sourceforge.net/projects/roc-winccoa-lib/

I also played with dpConnect: http://www.youtube.com/watch?v=_QKoItKdkks
I think i created a tcp connection to have a state-full connection and sent the XMLRPC over that tcp connection...

Or your client can also act as a XMLRPC server and OA can send xmlrpc-calls to the C# XMLRPC-Server - but of course then you will have problems if you have NAT or a firewall between client and server.

Andy

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

Re: PVSS and c#

Post by mwerksma »

Hi Andy,

Indeed I got feedback from Christian and also of a collegue of mine but I do nut fully understand
the code and how to use it. Now I have donwloade both your projects and put them in a solution
and I am now able to rebuild without errors but I haven't figured out how to omplement this code
in a C# Windows Form project.

Do you have sample code of a Windows form project?
What I want to create is a simple test form where values can be shown and altered with the use of events.
I understand that is possible with this code but how?

Thank you for your time,

Marcel

34 posts • Page 2 of 4