解決方案
在debug模式下,InstrumentStudio 會自動查找打開的裝置驅動程式sessions。出現錯誤
-1074118537是因為 InstrumentStudio 偵測到有運行中的Sequence打開裝置驅動程式session,但Sequence很快就被刪除了。
要解決此錯誤,請在刪除Sequence之前增加一個短暫的等待時間(基於使用者輸入或特定時間範圍的等待)。
這邊提供一個 Python 腳本,它為 PXIe-4137 建立進階Sequence。在
session.delete_advanced_sequence( ) 方法之前調用 input()函式以強制 Python 在刪除進階Sequence之前等待使用者輸入。
import argparse
import hightime
import nidcpower
import sys
def example(resource_name, options, voltage_max, current_max, points_per_output_function, delay_in_seconds):
timeout = hightime.timedelta(seconds=(delay_in_seconds + 1.0))
with nidcpower.Session(resource_name=resource_name, options=options) as session:
# Configure the session.
session.source_mode = nidcpower.SourceMode.SEQUENCE
session.voltage_level_autorange = True
session.current_limit_autorange = True
session.source_delay = hightime.timedelta(seconds=delay_in_seconds)
properties_used = ['output_function', 'voltage_level', 'current_level']
session.create_advanced_sequence(sequence_name='my_sequence', property_names=properties_used,
set_as_active_sequence=True)
voltage_per_step = voltage_max / points_per_output_function
for i in range(points_per_output_function):
session.create_advanced_sequence_step(set_as_active_step=False)
session.output_function = nidcpower.OutputFunction.DC_VOLTAGE
session.voltage_level = voltage_per_step * i
current_per_step = current_max / points_per_output_function
for i in range(points_per_output_function):
session.create_advanced_sequence_step(set_as_active_step=False)
session.output_function = nidcpower.OutputFunction.DC_CURRENT
session.current_level = current_per_step * i
with session.initiate():
session.wait_for_event(nidcpower.Event.SEQUENCE_ENGINE_DONE)
channel_indices = '0-{0}'.format(session.channel_count - 1)
channels = session.get_channel_names(channel_indices)
measurement_group = [session.channels[name].fetch_multiple(points_per_output_function * 2, timeout=timeout) for name
in channels]
input('Wait before deletion')
session.delete_advanced_sequence(sequence_name='my_sequence')
line_format = '{:<15} {:<4} {:<10} {:<10} {:<6}'
print(line_format.format('Channel', 'Num', 'Voltage', 'Current', 'In Compliance'))
for i, measurements in enumerate(measurement_group):
num = 0
channel_name = channels[i].strip()
for measurement in measurements:
print(line_format.format(channel_name, num, measurement.voltage, measurement.current,
str(measurement.in_compliance)))
num += 1