[SOLVED] read channel in CHOP execute DAT

hello,

I have a Timer CHOP which i attached a CHOP execute DAT to.
My goal is to read hour and minutes and trigger the recording of video from a camera for 1 minute.

Here is the python code i inserted in onValueChanged() :
if op(‘clock1’)[‘hour’] == 15 and op(‘clock1’)[‘min’] == 20:
op(‘moviefileout1’).par.record = 1
if op(‘clock1’)[‘hour’] == 15 and op(‘clock1’)[‘min’] == 21:
op(‘moviefileout1’).par.record = 0

So this works but i see there is channel, val etc… passed to the onValueChanged() function.
I thought about using the channel information to filter out ‘hour’ and ‘min’ values but i can’t understand how…

anybody to give some advice ?

thanks a lot.

Hey Gallo -

I think the first thing to understand here is that the channel object has several members that you might find useful:

derivative.ca/wiki099/index … nnel_Class

I typically use these to separate out actions for different channels, for example:

    if val == 20:
        print("it's hour 20")

That won’t totally work in your case as those callbacks are sequential, but if you wanted to limit your scope to hour changes something like this could work:

	if op('clock1')['min'] == 20:
		print("start recording")

As a slightly different course of action, what if you used your clock to trigger a timer instead? In this approach every hour a CHOP execute would trigger a timer CHOP. I think that does the same thing, but rather than having to compare hour and minute times to start and stop, you only worry about starting your timer - which is the thing in charge of starting and stopping your video recording.

Hey Matthew,

Thanks for those clarifications.

I was loking for some way to grab the value from a specific channel like :

channel['hour'].getVal()

That makes sense now.

Though i am going to try your trigger CHOP suggestion just for my personal knowledge but i am unsure of your explanation.

thanks

Here’s a look at that with a little more clarification in code:
base_timer_every_minute.tox (1.55 KB)

Rather than every hour this runs every minute.
The clock CHOP is used to trigger the timer when the minute val changes, this then kicks off the timer. In the timer callbacks you’ll see the on start call, and the on done call. These would get used for any of your recording needs.

Using the timer callbacks for this means you can write more generalized code, rather than worrying about getting all of the logic right in the CHOP execute.

It might not be the right approach for what you’re doing, but it’s saved me serious time in the past when I’ve needed an event or clock based trigger to set off recording for a fixed period of time.

Yes ! that is a pretty neat way of doing it. I like it a lot and matches perfectly what i need to achieve.

Thanks a lot for all your advice.

This helped me today!
Couldnt figure out how to access channel inside the function call. Thanks!