Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyOhNet - problem with IdArray
21-11-2016, 12:47 AM (This post was last modified: 21-11-2016 01:10 AM by Latka.)
Post: #1
PyOhNet - problem with IdArray
Hi,

There seems to be a problem with the evented IdArray (at least from the Playlist service) (ie the PropertyIdArray() ).

It gets returned as a list of integers instead of as a base64 encoded string, so I can't decode it.

It looks like this:
Code:
[0, 0, 0, 127, 0, 0, 0, 128, 0, 0, 0, 129, 0, 0, 0, 130, 0, 0, 0, 131,
0, 0, 0, 132, 0, 0, 0, 133, 0, 0, 0, 134, 0, 0, 0, 135, 0, 0, 0, 136,
0, 0, 0, 138, 0, 0, 0, 139, 0, 0, 0, 140, 0, 0, 0, 141, 0, 0, 0, 142,
0, 0, 0, 143, 0, 0, 0, 144, 0, 0, 0, 145, 0, 0, 0, 146, 0, 0, 0, 147,
0, 0, 0, 148, 0, 0, 0, 149]

Thanks,
Latka
Find all posts by this user
21-11-2016, 01:54 PM
Post: #2
RE: PyOhNet - problem with IdArray
(21-11-2016 12:47 AM)Latka Wrote:  Hi,

There seems to be a problem with the evented IdArray (at least from the Playlist service) (ie the PropertyIdArray() ).

It gets returned as a list of integers instead of as a base64 encoded string, so I can't decode it.

It looks like this:
Code:
[0, 0, 0, 127, 0, 0, 0, 128, 0, 0, 0, 129, 0, 0, 0, 130, 0, 0, 0, 131,
0, 0, 0, 132, 0, 0, 0, 133, 0, 0, 0, 134, 0, 0, 0, 135, 0, 0, 0, 136,
0, 0, 0, 138, 0, 0, 0, 139, 0, 0, 0, 140, 0, 0, 0, 141, 0, 0, 0, 142,
0, 0, 0, 143, 0, 0, 0, 144, 0, 0, 0, 145, 0, 0, 0, 146, 0, 0, 0, 147,
0, 0, 0, 148, 0, 0, 0, 149]

Thanks,
Latka

This is working as intended.
ohNet internally decodes all base64 encoded strings into byte arrays.
pyOhNet then returns this byte array as an array of integers representing the bytes (to permit printing/display of the data).

The following code segment re-assembles this as a byte array
Code:
def _EncodeIdArray( aIdArray ):
    chrString = ''
    for entry in aIdArray:
        chrString += chr( entry )
    return chrString

This will then give you an IdArray from the byte array
Code:
def _DecodeIdArray( encoded ):
    idArray = []
    for i in range( 0, len( encoded ), 4 ):
        idArray.append( ord( encoded[i] )   * 0x1000000 +
                        ord( encoded[i+1] ) * 0x10000 +
                        ord( encoded[i+2] ) * 0x100 +
                        ord( encoded[i+3] ))
    return idArray
Find all posts by this user
21-11-2016, 11:44 PM
Post: #3
RE: PyOhNet - problem with IdArray
Hi rockfather,

Thanks for your clarification. With your provided functions it now works for me, thanks!

Another thing,
I realize I can do:
res = proxy.SyncReadList (idarray)
print res

as an example of how to get the output from an action invocation.

However I can't get my head around how the asynchronous version works and with the callback.
Would it be possible to get an example of how to do for example the
BeginReadList ( idarray )
End ReadList

Invocation and callback?

Thanks again for your time.
Find all posts by this user
22-11-2016, 09:33 AM
Post: #4
RE: PyOhNet - problem with IdArray
(21-11-2016 11:44 PM)Latka Wrote:  Hi rockfather,

Thanks for your clarification. With your provided functions it now works for me, thanks!

Another thing,
I realize I can do:
res = proxy.SyncReadList (idarray)
print res

as an example of how to get the output from an action invocation.

However I can't get my head around how the asynchronous version works and with the callback.
Would it be possible to get an example of how to do for example the
BeginReadList ( idarray )
End ReadList

Invocation and callback?

Thanks again for your time.

Take a look in the examples in https://github.com/openhome/ohNet/tree/m...OhNet/Test
Find all posts by this user
22-11-2016, 09:44 AM
Post: #5
RE: PyOhNet - problem with IdArray
Hi rockfather,

Thanks for your response. I have looked there but failed to see anything but the Sync calls.
Find all posts by this user
22-11-2016, 02:59 PM (This post was last modified: 22-11-2016 03:37 PM by rockfather.)
Post: #6
RE: PyOhNet - problem with IdArray
(22-11-2016 09:44 AM)Latka Wrote:  Hi rockfather,

Thanks for your response. I have looked there but failed to see anything but the Sync calls.

Ooops - I misread your request

The Sync methods use the Async methods internally. These can be observed in the generated proxies. It may be worth looking at these to see what is going on. These need to be saved to disk when generated for you to view them - see the commented out block in _Device.py

Example from Playlist service - you would need to mimic the SyncPlay() and _PlayActionComplete() methods to get asynch operation

Code:
def SyncPlay( self ):
        self.response = None
        self.BeginPlay( self._PlayActionComplete )
        self.semaReady.acquire()    # wait for response
        return self.response

    def BeginPlay( self, aCb ):
        invocation = Control.Invocation( self.service, self.actionPlay, aCb )
        self._InvokeAction( invocation )

    def EndPlay( self, aHandle ):
        response = Control.InvocationResponse( aHandle )
        err = response.Error()
        if err['err'] is not False:
            return( 'Proxy error - %d: %s' % (err['code'],err['desc']) )
        return

    def _PlayActionComplete( self, aHandle ):
        self.response = self.EndPlay( aHandle )
        self.semaReady.release()    # signal response available
Find all posts by this user
22-11-2016, 06:11 PM
Post: #7
RE: PyOhNet - problem with IdArray
Thanks rockfather!
I will have a look at your example code.

Regarding this:
Quote:The Sync methods use the Async methods internally.

Does this mean that the use of Sync functions is as good as the Begin/End equivalents in pyOhNet?

The reason I am asking is because of the way these methods are described in the docs.
In the control point stack pdf from 2011, pages 8-9, one can read the following:

Quote:Each action is represented in a Proxy by three functions. Two of these are begin and end functions for
an asynchronous invocation of the action. This gives you the option of providing your Control Point
application with a faster and more responsive user interface. You can execute actions while others
complete, or cancel long-running actions if required.

Using the synchronous functions makes the Control Point application easier to develop. However,
the disadvantage of synchronous calls is that it risks the application looking like it has frozen while it
waits for the action to complete. Long sequences of actions will take longer as synchronized calls
are serialized rather than run in parallel.
Users will be unable to use other actions until the sequence of calls on the remote device has
completed. A targeted use of synchronous invocations in a few special cases can be useful, but
general use is not recommended.

Thanks again Smile
Find all posts by this user
23-11-2016, 10:58 AM
Post: #8
RE: PyOhNet - problem with IdArray
(22-11-2016 06:11 PM)Latka Wrote:  Thanks rockfather!
I will have a look at your example code.

Regarding this:
Quote:The Sync methods use the Async methods internally.

Does this mean that the use of Sync functions is as good as the Begin/End equivalents in pyOhNet?

The reason I am asking is because of the way these methods are described in the docs.
In the control point stack pdf from 2011, pages 8-9, one can read the following:

Quote:Each action is represented in a Proxy by three functions. Two of these are begin and end functions for
an asynchronous invocation of the action. This gives you the option of providing your Control Point
application with a faster and more responsive user interface. You can execute actions while others
complete, or cancel long-running actions if required.

Using the synchronous functions makes the Control Point application easier to develop. However,
the disadvantage of synchronous calls is that it risks the application looking like it has frozen while it
waits for the action to complete. Long sequences of actions will take longer as synchronized calls
are serialized rather than run in parallel.
Users will be unable to use other actions until the sequence of calls on the remote device has
completed. A targeted use of synchronous invocations in a few special cases can be useful, but
general use is not recommended.

Thanks again Smile


A call to SyncXXX() will block until the call responds (or fails/times out)
A call to BeginXXX() will return immediately

It is up to you which is better in the scenario you are working in. If you cannot proceed until the response to the call is known it is better to use Sync calls, if you can proceed then use the Begin/End calls

The documentation snippet above is a bit misleading - only you know whether you need synchronous or asynchronous behavior - so it should not really suggest one way is preferable to the other.

Note that there are other methods to run asynchronously (for example put the Sync call on its own thread)
Find all posts by this user
23-11-2016, 12:59 PM
Post: #9
RE: PyOhNet - problem with IdArray
Thanks for the answer! Smile
Find all posts by this user


Forum Jump: