OLA python client issue

220 views
Skip to first unread message

Nathan Whitford

unread,
Sep 26, 2015, 7:36:53 PM9/26/15
to open-lighting
Hi, 

I've created a simple application that reads a video file with OPENCV and then outputs 75 pixels of RGB values out to OLA. The app is all in python, which I'm quite new to.  It works, but twice now the python app has crashed, when it triggers an OLADNotRunningException.  I've modelled my code on the multiframe example that is included on the OLA website, but I don't trigger it with an event, and I don't call the wrapper.run() function. I just call the following in my main loop after I've processed each frames data:

    wrapper.Client().SendDmx(11, data1, DmxSent)

Eventually, I get the following error:

  File "pyapps/pySwell.py", line 413, in <module>

    fbi.tide()

  File "pyapps/pySwell.py", line 344, in tide

    SendDMXFrames(pixels)

  File "pyapps/pySwell.py", line 97, in SendDMXFrames

    wrapper.Client().SendDmx(11, data1, DmxSent)

  File "/usr/lib/python2.7/dist-packages/ola/OlaClient.py", line 634, in SendDmx

    raise OLADNotRunningException()

ola.OlaClient.OLADNotRunningException


If I look at the error it looks like OLAD is not running, but it is running, so I checked the syslog and see the following:

And in the syslog I get this info:

Sep 26 11:25:01 raspberrypi olad: common/io/Descriptor.cpp:361: Failed to send on 42: Resource temporarily unavailable

Sep 26 11:25:01 raspberrypi olad: common/rpc/RpcChannel.cpp:308: Failed to send full RPC message, closing channel

Sep 26 11:25:01 raspberrypi olad: olad/Universe.cpp:294: Source client 0x168d188 has been removed from uni 11


Could I be sending data too fast? I should only be sending it at around 20-30 frames, as I've added time.sleep commands to calibrate the video to playback at the recorded framerate. Is there a limit to how fast OLA can receive? 


Can someone explain the wrapper.run() function?  


Thanks,


Nathan



Simon Newton

unread,
Sep 26, 2015, 7:41:12 PM9/26/15
to open-lighting
On Sat, Sep 26, 2015 at 4:35 PM, Nathan Whitford
<nat...@urbanvisuals.com> wrote:
> Hi,
>
> I've created a simple application that reads a video file with OPENCV and
> then outputs 75 pixels of RGB values out to OLA. The app is all in python,
> which I'm quite new to. It works, but twice now the python app has crashed,
> when it triggers an OLADNotRunningException. I've modelled my code on the
> multiframe example that is included on the OLA website, but I don't trigger
> it with an event, and I don't call the wrapper.run() function.

That's your problem.

The OLA server sends an acknowledgment back to your client. Since
you're not calling run(), this data will stack up on the file
descriptor and eventually the server will close the channel, like you
see from the logs below.
See https://docs.openlighting.org/ola/doc/latest/event_driven.html.


Simon

>
>
> Thanks,
>
>
> Nathan
>
>
>
> --
> The Open Lighting Project: open-l...@googlegroups.com, #openlighting
> (irc.freenode.org)
> To unsubscribe from this group, send email to
> open-lightin...@googlegroups.com
> For more options, visit https://groups.google.com/groups/opt_out?hl=en

Nathan Whitford

unread,
Sep 26, 2015, 8:21:16 PM9/26/15
to open-lighting
Hi Simon, 

Thanks for the quick reply. Does wrapper.Run have to be the last thing I run?  I'm trying to wrap my head around the event based stuff, but it looks like anything I put after the wrapper.run doesn't get executed even in the multiple frames example.  Shouldn't I be able to continue running code, but then query for the event within that code?

I don't really want to run all my code within a 100ms loop. Can I use the wrapper object to create multiple events, and have them run at independent times. For example, on loop can run and analyze the video frames, writing the relevant data to the DMX array object, and also writing video to the framebuffer, while the second event can be pushing sending the array object to OLA?

At the very simplest, would I conceivably be able to pull everything from my "while True" main loop, and put that in a named function, and then call that with a wrapper event?

Thanks,

Simon Newton

unread,
Sep 26, 2015, 8:27:03 PM9/26/15
to open-lighting
On Sat, Sep 26, 2015 at 5:21 PM, Nathan Whitford
<nat...@urbanvisuals.com> wrote:
> Hi Simon,
>
> Thanks for the quick reply. Does wrapper.Run have to be the last thing I
> run? I'm trying to wrap my head around the event based stuff, but it looks
> like anything I put after the wrapper.run doesn't get executed even in the
> multiple frames example. Shouldn't I be able to continue running code, but
> then query for the event within that code?

Correct. wrapper.Run() is the last thing you call - well besides any
clean up code as the application terminates. You give up control to
the event loop.


>
> I don't really want to run all my code within a 100ms loop. Can I use the
> wrapper object to create multiple events, and have them run at independent
> times.

Yes, that's what it's there for.

> For example, on loop can run and analyze the video frames, writing
> the relevant data to the DMX array object, and also writing video to the
> framebuffer, while the second event can be pushing sending the array object
> to OLA?
>
> At the very simplest, would I conceivably be able to pull everything from my
> "while True" main loop, and put that in a named function, and then call that
> with a wrapper event?

You could, but have a think about when you want events to occur. For
instance you probably only care when a new video frame arrives. If
there is a way to trigger an event based on that it'll more efficient
than polling in a loop.

You also need to be careful not to block in an event handler since
that'll starve other event handlers.

Simon

Nathan Whitford

unread,
Sep 26, 2015, 8:39:47 PM9/26/15
to open-lighting
Hi Simon, 

Thanks again! I'm new to python, so thanks for the patience. 

One more question: Any cleanup code or anything else after the wrapper.Run statement would only get called if somewhere in one of the event loops, wrapper.stop() was called? 

Thanks,

Nathan

Simon Newton

unread,
Sep 26, 2015, 8:40:28 PM9/26/15
to open-lighting
On Sat, Sep 26, 2015 at 5:39 PM, Nathan Whitford
<nat...@urbanvisuals.com> wrote:
> Hi Simon,
>
> Thanks again! I'm new to python, so thanks for the patience.
>
> One more question: Any cleanup code or anything else after the wrapper.Run
> statement would only get called if somewhere in one of the event loops,
> wrapper.stop() was called?

Correct.

Simon

Nathan Whitford

unread,
Sep 27, 2015, 12:10:12 AM9/27/15
to open-lighting
Hi Simon, 

I tried the sample, wrapper code, but it wouldn't work for me with pygame. I found link to the pygame example on the bottom of the "event driven" page you sent to me, and I've modified my code to suit that, and it seems to work well, but I just want to be sure that I'm not going to run into the same buffer issue. 

Is the code at the bottom of the main loop (copied below) what would take care of clearing the acknowledgment buffer? It looks like it's checking on every loop if there's readable data, and accepting the data but otherwise ignoring the data. I'm not familiar with the select library, and I'm not sure what's happening there.

      # check if there is something to do 
      readable, writable, exceptional = select.select([sock], [], [], 0) 
      if readable: 
        # tell it ola_client 
        ola_client.SocketReady() 

Thanks!

Nathan

Simon Newton

unread,
Sep 27, 2015, 12:41:41 AM9/27/15
to open-lighting
That should work.

Simon


On Sat, Sep 26, 2015 at 9:10 PM, Nathan Whitford
Reply all
Reply to author
Forward
0 new messages