Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
maxLevel2

...

If there is a preset called [Python: Unload], DevWare will automatically execute it when the corresponding ini file window is closed, or when DevWare exits. This can be used to clean up background threads.

DevWare only executes [Python:] when the ini file is opened in a Presets window. In scripts you have to execute [Python:] explicitly if the file isn't in a window, or in applications outside of DevWare. 
You can load an ini file into a DevWare Presets window with: 
    devware.open_ini_file(inifilepath) 
This will run [Python:].

DevWare automatically creates a variable called __IniFileName. When the execution of an ini file preset begins, DevWare sets the contents of this variable to the full path to the ini file. This is useful for accessing other files in the same directory as the current ini file. Note that when execution of the preset ends, the variable reverts back to its previous value, so the variable is not meaningful if accessed from a background thread that remains running after the preset that launched it is finished. If the ini file path is needed in a thread function, then it must be passed to the thread function as a parameter.

...

When the user invokes [Python: Thread Test] in the Presets dialog, the DevWare UI thread shuts down the camera and display threads, executes [Python: Thread Test] (which only creates a new thread and then finishes), and then resumes the camera and display threads. Simultaneously the new thread begins executing and remains alive after [Python: Thread Test] has finished. The 'test_run' thread increments the COARSE_INTEGRATION_TIME register 60, 120, 180, … 1200 every 1000ms until finished, which takes about 20 seconds. When the function exits the thread self-destructs.

If there is a preset called [Python: Unload], DevWare will automatically execute it when the corresponding ini file window is closed, or when DevWare exits. This can be used to clean up background threads.

Subprocesses

If the use of a Subprocess is necessary instead of a thread, "sys.prefix" can be used to ensure that the same version of Python is being used. 
An example;

import os
import sys
import subprocess

...

getstate(statename)

Returns the value of the specified state variable. Some variables have integer values and some have string values. See the INI file user's guide for more details.

setstate(statename, value)

Assign a new value to a state variable. Some state variables are integer valued and some are string valued. The type of the value parameter must match the type of the named state variable.

getoption(optionname)

Returns the value of an integer-valued option variable. See the COM interface document for more details.

setoption(optionname, value)

Assign a new value to an option variables. Option values are persistent across invocations of DevWare.

getoption_str(optionname)

Like getoption() but for string values.

setoption_str(optionname, value)

Like setoption() but for string values. Option values are persistent across invocations of DevWare.

get_mouse_selection()

Returns the Mouse Selection on the DevWare left-hand Info panel and the currently selected image area. Returns a tuple with five items; the selection type, the x and y coordintates of the start of the area, and the x and y coordinates of the end of the area. Example:
sel, x1, y1, x2, y2 = get_mouse_selection()
Sel can be 'off', 'row', 'colcolumn', 'rectangle', or 'point'. It can also be an index from 0 to 4, relative to the listed names.

For 'row' only y1 is relevant, for 'column' only x1 is relevant, and for 'point' only x1 and y1 are relevant.

set_mouse_selection(sel, x1, y1, x2, y2[, subimage=<value>])

Set a new selection area."

sel" is an index of 0 to 4, representing respectively 'off', 'row', 'column', 'rectangle', and 'point'. See "get_mouse_selection()" for parameter values.

get_active_mouse_sel()Get the index of the current active Mouse Selection. Returns an INT, from 0 to 7.
set_active_mouse_sel(sel)Set the index of the current active Mouse Selection. "sel" is a value from 0 to 7.

image(width, height, type)

Override DevWare's calculation of the current sensor output image size and image type. The type parameter is optional. If you only want to set the image type then pass 0 for width and height. See the INI file user's guide, IMAGE= command for more details. Example:
image(640, 480, 'YCBCR')

load_preset(preset)
load_preset(file, preset)

Execute an INI file preset. If the file parameter is not given, the method will load from the currently executing ini file, or if that can't be determined, the main ini file.

open_ini_file(file)

Create a new Additional Presets dialog showing the given file. If the file parameter is omitted or an empty string then DevWare puts up a standard Open File browse dialog and the user may choose the file.

rebuild_user_toolbars()Re-build the User Toolbars from the ini files (in case the files changed).
update_user_toolbars()Update checked/enabled states of User Toolbars.

upload_firmware(file, burst)

Loads firmware or firmware patches from a file. The burst parameter determines whether to use I2C burst writes. Returns the actual number of bytes loaded.
See the COM interface document for more details.

upload_image_file(file, offset, length)

Loads a test image (or any binary data) to a supported emulator platform. The offset and length parameters are optional. Same as the COM interface function.

command(cmd, param)

The command() method sends a WM_COMMAND message to the DevWare main window. See the COM interface document for more details.

getstate(state)Get the value of a ColorPipe state variable. See the ColorPipe User Guide for details.
setstate(state)Set the value of a ColorPipe state variable. See the ColorPipe User Guide for details.

stop(bool)

Stops or starts the image capture and image display threads in DevWare. Call stop(True) to stop the threads, and stop(False) to resume them. Every call to stop(True) must be matched with a call to stop(False). DevWare stops the threads before executing an ini file preset, so this function will have no effect in that situation. But if your Python code may run in a thread you created, or may be called from a plug-in or from the COM interface then the capture and display threads may be running concurrently with your Python code.

begin_access_regs()

Tells DevWare that register accesses are following. If the device driver can't do simultaneous register access and frame capture then this function will pause the image capture thread. Using this function is not necessary, but calling begin_access_regs() before a sequence of many register accesses saves the overhead of pausing and unpausing the capture thread on each register access. This function is typically not needed in ini file presets because the capture thread is normally already turned off before the ini preset is executed. Every call to this function must be matched with a call to end_access_regs() or else the capture thread will not resume.

end_access_regs()

Resume the image capture thread if it was paused by a call to begin_access_regs().

log(string)

If the Register Log window is enabled, adds a string to the log.

get_warning_choice(id)

Get the automatic response to the DevWare warning dialog given by the id number. The response can be devware.IDOK for OK or Yes, devware.IDNO for No, or -1 to show the warning dialog.

set_warning_choice(id, choice)

Set the automatic response to the DevWare warning dialog.

reset_warnings()

Reset all warning dialogs to be shown (no automatic response).

suppress_warnings()Suppress all warning dialogs.

close()

Equivalent to clicking the close button on the DevWare main window. This is may be preferred to sys.exit(), which may cause an error message pop-up dialog. The function allows a parameter, but ignores it. Note that this function does return, and if executed in the DevWare main UI thread, DevWare doesn't exit until the script is finished.

add_check_box(params)Add scriptable checkbox. See  Command Syntax, below, for params format.
add_spin_box(params)Add scriptable spin box. See  Command Syntax, below, for params format.
add_float_spin_box(params)Add scriptable float spin box. See  Command Syntax, below, for params format.
add_float_slider(params)Add scriptable float slider control. See  Command Syntax, below, for params format.
add_list_box(params)Add list box with enumeration. See  Command Syntax, below, for params format.
add_edit_box(params)Add edit string box. See Command Syntax, below, for params format.
refresh_control(tab, group, label)Refresh the targeted control. Parameters are those supplied in one of the Command Syntax calls.
get_refresh_interval()Get the refresh interval in milliseconds. Returns an INT.
set_refresh_interval(value)Change the refresh interval in milliseconds.
getOpenFileName(params)Get filename from pop-up file dialog. params are strings of title, directory, and filter; do a Web search of "QFileDialog::getOpenFileName" for details.
getSaveFileName(params)Get filename from pop-up file dialog. params are strings of title, directory, and filter; do a Web search of "QFileDialog::getSaveFileName" for details.
showMessageBox(params)

Pop-up a messagebox. params are title, message, and button.
For title and message, provide strings.
For button provide an INI of; 0 for "OK", 1 for "OK", "Cancel", 2 for "Retry", "Ignore", "Abort", 3 for "Yes", "No", "Cancel".
Returns an INT of; 1 = OK, 2 = Cancel, 3 = Abort, 4 = Retry, 5 = Ignore, 6 = Yes, 7 = No

graph_gettype()Get the current Analysis Graph type. 0 = Intensity; 1 = Histogram; 2 = Cumulative Intensity; 3 = Cumulative Histogram; 4 = Noise; 5 = Vectorscope; 6 = Embedded Statistics; 7 = SOC Statistics
graph_settype()Set the Analysis Graph type.
graph_getcolortype(type)Get current Analysis Graph color type; 0 to 2 = RGB, Bayer/YCbCr, HSV, FFT.
graph_setcolortype(type)Set Analysis Graph color type; 0 to 2 = RGB, Bayer/YCbCr, HSV, FFT.
graph_getdata()Get the data from the current Analysis Graph.
histogram_getmode()Get the current histogram mode. 0 = RGB; 1 = Luminance.
histogram_setmode()Set the histogram mode.
histogram_mean()If Analysis Graph is set to Histogram (1 or 3) and the histogram mode is Luminance (1) this returns the current mean of the data.
histogram_median()If Analysis Graph is set to Histogram (1 or 3) and the histogram mode is Luminance (1) this returns the current median of the data.
histogram_max()If Analysis Graph is set to Histogram (1 or 3) and the histogram mode is Luminance (1) this returns the current maximum of the data.
histogram_stddev()If Analysis Graph is set to Histogram (1 or 3) and the histogram mode is Luminance (1) this returns the current standard deviation of the data.

...