Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Are there any Samples for C#?
21-12-2012, 04:13 PM
Post: #1
Are there any Samples for C#?
Hi,

I'm new to the Forum, so ... hello Smile

I'll start with my first question.
Are there any Examples for a ControlPoint with OhNet using C#.
Im not really used to C# but for simple applications it's enough Confused

I managed to get devices and i can control devices, but i have some problems subscribing to events. They wont raise.

For example i subscribed to a AvTransportServive of a mediaRenderer with the CpProxyUpnpOrgAVTransport1 like this.

tr = new CpProxyUpnpOrgAVTransport1(dev);
tr.SetPropertyChanged(new System.Action(propChanged));
tr.Subscribe();

I also tried subscription to the connectionManager and the rendering control proxy itself. (I think I'm probably doing something wrong with the System.Action delegate?)

Another question is how to get the AVTransportUri which holds the url for the container on the media server (the one which links to the queue on the mediaserver which may hold a "playlist" queue)

I hope someone can give me some feedback!
Thank You!
Find all posts by this user
21-12-2012, 04:49 PM
Post: #2
RE: Are there any Samples for C#?
(21-12-2012 04:13 PM)ChriD Wrote:  Hi,

I'm new to the Forum, so ... hello Smile

Hi ChriD, welcome to the forum.

(21-12-2012 04:13 PM)ChriD Wrote:  I'll start with my first question.
Are there any Examples for a ControlPoint with OhNet using C#.
Im not really used to C# but for simple applications it's enough Confused

I managed to get devices and i can control devices, but i have some problems subscribing to events. They wont raise.

For example i subscribed to a AvTransportServive of a mediaRenderer with the CpProxyUpnpOrgAVTransport1 like this.

tr = new CpProxyUpnpOrgAVTransport1(dev);
tr.SetPropertyChanged(new System.Action(propChanged));
tr.Subscribe();

I also tried subscription to the connectionManager and the rendering control proxy itself. (I think I'm probably doing something wrong with the System.Action delegate?)

The best C# sample will be one of our test programs. You can find the source at ohNet/OpenHome/Net/Bindings/Cs/ControlPoint/Test/TestProxy.cs. This test finds all devices on the network that implement the ConnectionManager service then times how many actions it can invoke on each device in 1 second, followed by how many subscriptions it can make. (Don't worry, neither the action invocation or (un)subscribing are destructive! Your devices are left in exactly the same state as before.)

You should be able to subscribe using

tr = new CpProxyUpnpOrgAVTransport1(dev);
tr.SetPropertyChanged(propChanged);
tr.Subscribe();


Subscribing is an asynchronous operation so your propChanged function won't be called immediately after control returns from Subscribe(). It should be called pretty quickly afterwards however (certainly in a number of milliseconds rather than seconds).

If this still doesn't work, I'd suggest ruling out problems caused by attempting to connect to a defective device by downloading Intel Device Spy and checking you can subscribe using that. If that works, try to post a small, self-contained example program and I'll see if I can reproduce / diagnose the problem using that.

(21-12-2012 04:13 PM)ChriD Wrote:  Another question is how to get the AVTransportUri which holds the url for the container on the media server (the one which links to the queue on the mediaserver which may hold a "playlist" queue)

The AVTransportUri state variable is not evented so can't be retrieved via subscription. From a quick look at the service xml, it appears to be returned in the CurrentURI output argument for the GetMediaInfo action so you can use either BeginGetMediaInfo or SyncGetMediaInfo. In general, actions prefixed with Begin are asynchronous; this allows for better performing control points but can be harder to program with. Actions prefixed with Sync are (unsurprisingly!) synchronous; they are slower to call but very easy to program with.
Find all posts by this user
21-12-2012, 06:38 PM
Post: #3
RE: Are there any Samples for C#?
Thank you for your quick answer!

I checked with Intel DeviceSpy. If i use my Windows VISTA Laptop. The subscription works flawlessly, but if i use my windows 7 Machine, i can't receive any upnp events. There has to be something wrong on my Windows 7 Machine, i've to check this!

Thank you...
Find all posts by this user
24-12-2012, 08:43 AM
Post: #4
RE: Are there any Samples for C#?
(21-12-2012 06:38 PM)ChriD Wrote:  I checked with Intel DeviceSpy. If i use my Windows VISTA Laptop. The subscription works flawlessly, but if i use my windows 7 Machine, i can't receive any upnp events. There has to be something wrong on my Windows 7 Machine, i've to check this!

Subscription involves your control point running a TCP server which devices connect to. This requires that your Windows Firewall allows incoming TCP connections. It'd be worth checking the firewall rules for your test program (Control Panel -> Windows Firewall -> Allow a program or feature...)
Find all posts by this user


Forum Jump: