這是一個具有最少代碼的簡單電壓輸入示例。
它執(zhí)行v_in_32(),適用于所有具有12位至24位轉(zhuǎn)換器的設(shè)備。
注意:這不使用設(shè)備發(fā)現(xiàn)。在運(yùn)行此示例之前,必須先在InstaCal中找到您的MCC設(shè)備。
"""
File: a_inw_CBcfg.py
Library Call Demonstrated: mcculw.ul.v_in_32()
Purpose: Reads an A/D Input Channel.
Demonstration: Displays the analog input on a user-specified
channel.
Other Library Calls: ul.get_board_name()
ul.get_config_string()
Special Requirements: Device must have an A/D converter.
Analog signal on an input channel.
"""
from __future__ import absolute_import, division, print_function
from builtins import * # @UnusedWildImport
from mcculw import ul
from mcculw.enums import ULRange, InfoType, BoardInfo
def run_example():
my_board_name = "USB-1208 Series"
board_num = 0
board_found = False
try:
# find an MCC device with a user specified name...
for board_num in range(0, 99):
board_name = ul.get_board_name(board_num)
if "1208" in board_name:
board_found = True
break
if not board_found:
# failure...
print("No %s found in system. Please run InstaCal." % my_board_name)
else:
# success...
print("%s found as board number %d." % (board_name, board_num))
# get the serial number of device...
serial_num = ul.get_config_string(InfoType.BOARDINFO, board_num, 0, BoardInfo.DEVSERIALNUM, 10)
print("using serial number: %s\n" % serial_num)
# set some parameters
ai_range = ULRange.BIP10VOLTS
channel = 0
# Get a value from the device
# Use the v_in_32 method for devices with any device with an A/D (12 to 24 bits)
value = ul.v_in_32(board_num, channel, ai_range)
# Display the engineering value
print('Measured Value: {:.4f}'.format(value))
except Exception as e:
print('\n', e)
if __name__ == '__main__':
run_example(