Python Script Sleep and Refreshing EZ-IO Binary States

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
automaton
Posts: 103
Joined: Fri May 23, 2008 8:35 am

Python Script Sleep and Refreshing EZ-IO Binary States

Post by automaton »

I haven't been able to find the answers to the following by searching the docs and forums.

I have an embedded Python script that refreshes an EZ-io module status, then reads the updated status, then acts based on the status like this:

Code: Select all

# Refresh the EZ-IO status
indigo.iodevice.statusRequest(EZ-IO-Device)
# 
# Need to have a delay here to wait for the status request to complete
indigo.script.sleep(2)
#
# Get Status of EZ-IO Binary Input here and take appropriate action
My two questions:
1. Am I using indigo.script.sleep(2) properly here? Does this just cause this script to sleep, or does it sleep indigo or all scripts?
2. Is there a command which will only refresh the binary input status (vs. both binary and analog status) of the EZ-IO module (you can do this directly in Indigo, but I couldn't figure out if this was possible using a script command. Refreshing just the binary status is quicker.

If anyone can help, it would be much appreciated.
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Python Script Sleep and Refreshing EZ-IO Binary States

Post by matt (support) »

The sleep call will block the script for 2 seconds. If it is an embedded script then you don't want to block for very long, since only one embedded script can execute at a time. If the IndigoServer detects a script is taking too long to run, then it will kill it so other embedded scripts have a chance to run. But 2 seconds should be fine.

There is no python script command to only request the binary states, but you can do it by creating an Action Group that only requests the binary states then execute the Action Group from the script (instead of calling .statusRequest()).
Image
automaton
Posts: 103
Joined: Fri May 23, 2008 8:35 am

Re: Python Script Sleep and Refreshing EZ-IO Binary States

Post by automaton »

Thanks Matt. I suppose the best practice is to make most scripts external to avoid conflicts and running out of execution time. By the way, is there a preferred or recommended location to create a folder to store external scripts?
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Python Script Sleep and Refreshing EZ-IO Binary States

Post by matt (support) »

It depends. There is overhead in starting up the process that executes the script. For every external python script file a new process has to be started (and then it has to perform a handshake with the IndigoServer to get started). For embedded scripts they share this process context. So the first one take a second or so to start, but then after that other embedded scripts can startup very quickly (but serially, so one blocking or sleeping will hold up the sequence).

So in general I recommend embedded scripts if they will finish executing in a couple of seconds. And I recommend external script if they need to take longer than that, or if they might have to block/wait on external services/applications.

You can put the scripts anywhere, but I would recommend:

/Library/Application Support/Perceptive Automation/Indigo 6/Scripts/
Image
Locked

Return to “Extending Indigo with Plugins and Python”