# This script checks that the MagicDAQ API and MagicDAQ Driver were installed properly
# It is NOT NECESSARY to have the MagicDAQ connected to the computer

print('*** MagicDAQ Install Check***')
print('')

try:

    # Import MagicDAQDevice object
    from magicdaq.api_class import MagicDAQDevice

    # Create daq_one object
    daq_one = MagicDAQDevice()
    print('GOOD: MagicDAQ API is installed properly.')

    # Get MagicDAQ Driver Version
    driver_version = daq_one.get_driver_version()

    if driver_version == 1.0:
        print('GOOD: MagicDAQ Driver is installed properly.')
        print('You are ready to use MagicDAQ!')
    else:
        print('ERROR: MagicDAQ Driver version not expected value: '+str(driver_version))
        print('Try installing MagicDAQ using pip again.')
        print('https://magicdaq.github.io/magicdaq_docs/#/Install_MagicDAQ')
        print('Feel free to email MagicDAQ Support at: [email protected]')

except Exception as exception_text:
    print('Original exception: ')
    print(exception_text)
    print('')
Esempio n. 2
0
# Use the USB cable to plug MagicDAQ into your computer

# Import standard time module
import time

# Import MagicDAQDevice object
from magicdaq.api_class import MagicDAQDevice

# Create daq_one object
daq_one = MagicDAQDevice()

# Connect to the MagicDAQ
daq_one.open_daq_device()

# Configure analog input stream for pins AI1 and AI2. Sampling frequency of 200 Hz.
# Remember, analog input streaming only supports single ended measurement (measuring between AI1 and AGND for example).
daq_one.configure_analog_input_stream([1, 2], 200)

print('Streaming AI1 and AI2 at 200Hz.')

# Start the analog input stream
daq_one.start_analog_input_stream()

# Use a loop to read the incoming data
# This kind of structure could be used to provide data to a continuously updated display
read_cycle_count = 0
while read_cycle_count < 3:

    print('')
    print('Pausing for 1 sec to acquire streamed data')
    time.sleep(1)
##############################################################

import sys
import time

# Import MagicDAQ
print('*** MagicDAQ Install Check ***')
print('')

try:

    # Import MagicDAQDevice object
    from magicdaq.api_class import MagicDAQDevice

    # Create daq_one object
    daq_one = MagicDAQDevice()
    print('GOOD: MagicDAQ API is installed properly.')

    # Get MagicDAQ Driver Version
    driver_version = daq_one.get_driver_version()

    if driver_version == 1.0:
        print('GOOD: MagicDAQ Driver is installed properly.')
        print('You are ready to use MagicDAQ!')
    else:
        print('ERROR: MagicDAQ Driver version not expected value: ' +
              str(driver_version))
        print('Try installing MagicDAQ using pip again.')
        print('https://magicdaq.github.io/magicdaq_docs/#/Install_MagicDAQ')
        print('Feel free to email MagicDAQ Support at: [email protected]')
# Use the USB cable to plug MagicDAQ into your computer

# Import standard time module
import time

# Import MagicDAQDevice object
from magicdaq.api_class import MagicDAQDevice

# Create daq_one object
daq_one = MagicDAQDevice()

# Connect to the MagicDAQ
daq_one.open_daq_device()

# Start the Pulse Counter
# Pulses will be counted on the falling edge
daq_one.enable_pulse_counter()

print('Pausing for 15 sec to allow time to read pulses.')
print('Briefly join together pins CTRO and DGND repeatedly to simulate pulses.')
time.sleep(15)

# Read number of pulses
print('Number of pulses counted: '+str(daq_one.read_pulse_counter()))

print('Now clearing the pulse counter')
daq_one.clear_pulse_counter()
print('Pulse count after clearing: '+str(daq_one.read_pulse_counter()))

# We are done using the MagicDAQ, so close it
daq_one.close_daq_device()
Esempio n. 5
0
# Use the USB cable to plug MagicDAQ into your computer

# Import MagicDAQDevice object
from magicdaq.api_class import MagicDAQDevice

# Create daq_one object
daq_one = MagicDAQDevice()

# Connect to the MagicDAQ
daq_one.open_daq_device()

# Single ended analog input voltage measurement on pin AI0
# This voltage will be approximately 0.5V if nothing is connected to the DAQ (pin is 'floating')
pin_0_voltage = daq_one.read_analog_input(0)
print('Single ended analog input voltage measurement on pin AI0: ' +
      str(pin_0_voltage))

# Differential voltage measurement between pin AI1 and AI2
# This voltage should be roughly 0V if nothing is connected to the DAQ (pins are 'floating')
pin_1_pin_2_diff_voltage = daq_one.read_diff_analog_input(1, 2)
print('Differential voltage measurement between pin AI1 and pin AI2: ' +
      str(pin_1_pin_2_diff_voltage))

# We are done using the MagicDAQ, so close it
daq_one.close_daq_device()
Esempio n. 6
0
# Connect one or more MagicDAQs to your system using the USB cables.
# Feel free to use a USB hub to connect multiple DAQs to your computer.

# Import the standard time module
import time

# Import MagicDAQDevice object
from magicdaq.api_class import MagicDAQDevice

# Create daq_one object
daq_one = MagicDAQDevice()

# Get the serial numbers of all DAQs that are connected to your computer.
daqs_serial_number_list = daq_one.list_all_daqs()
print('List of DAQ Serial Numbers: ' + str(daqs_serial_number_list))
print('There are ' + str(len(daqs_serial_number_list)) +
      ' DAQs in total connected to your computer.')
print('')

# If there is at least 1 DAQ, connect to it and read its serial number
if len(daqs_serial_number_list) >= 1:

    # NOTE:
    # For systems that always use the same DAQ units, you can hard code the serial numbers
    # For example:
    # daq_one.open_daq_device(daq_serial_number = '931cd19e')

    daq_one.open_daq_device(daq_serial_num=daqs_serial_number_list[0])
    # Read the DAQ's serial number
    print('daq_one serial number: ', daq_one.get_serial_number())
# Use the USB cable to plug MagicDAQ into your computer

# Import standard time module
import time

# Import MagicDAQDevice object
from magicdaq.api_class import MagicDAQDevice

# Create daq_one object
daq_one = MagicDAQDevice()

# Connect to the MagicDAQ
daq_one.open_daq_device()

# Set constant 2.5V output on pin AO0
daq_one.set_analog_output(0, 2.5)
print(
    'Pausing for 10 sec to allow time to measure pin AO0 (should be constant 2.5V)'
)
time.sleep(10)

# Configure a 500 Hz frequency, 3.3V amplitude continuous Sine Wave on pin AO0
daq_one.configure_analog_output_sine_wave(0, 500, amplitude=3.3)

# Configure a 500 Hz frequency, 50% duty cycle, 5V amplitude, continuous PWM Wave on pin AO1
daq_one.configure_analog_output_pwm_wave(1, 500, 50)

# Start both AO0 and AO1 waves
daq_one.start_analog_output_wave(0)
daq_one.start_analog_output_wave(1)
# Use the USB cable to plug MagicDAQ into your computer

# Import MagicDAQDevice object
from magicdaq.api_class import MagicDAQDevice

# Create daq_one object
daq_one = MagicDAQDevice()

# Connect to the MagicDAQ
daq_one.open_daq_device()

# Do useful things with the DAQ
# For example, you can read a digital pin's state
print('This is Digital Pin P0.0 State: ' + str(daq_one.read_digital_input(0)))

# We are done using the MagicDAQ, so close it
daq_one.close_daq_device()
Esempio n. 9
0
# Docs: https://magicdaq.github.io/magicdaq_docs/#/PyCharmCodeCompletion

##############################################################
#*** Imports ***
##############################################################

import time
import csv

# Import MagicDAQ
from magicdaq.api_class import MagicDAQDevice

#*** Connect to DAQ Device ***

# Create daq_one object
daq_one = MagicDAQDevice()
# Connect to the MagicDAQ
daq_one.open_daq_device()

##############################################################
#*** IMPORTANT: Set Acquisition Type ***
##############################################################

# This script demonstrates two different ways of acquiring data:
# Slowly (using read_analog_input() ) and quickly (using streaming methods)

# If set to True, slow data acquisition demonstrated (read_analog_input() )
# If set to False, fast data acquisition demonstrated (uses streaming methods )
DATA_ACQUIRED_SLOWLY = True

##############################################################
Esempio n. 10
0
# Use the USB cable to plug MagicDAQ into your computer

# Import standard time module
import time

# Import MagicDAQDevice object
from magicdaq.api_class import MagicDAQDevice

# Create daq_one object
daq_one = MagicDAQDevice()

# Connect to the MagicDAQ
daq_one.open_daq_device()

# Configure a 50 KHz frequency, 75% duty cycle, 3.3V amplitude, continuous PWM Wave on the counter pin (CTR0)
daq_one.configure_counter_pwm(50000, 75)

# Start the counter PWM wave
daq_one.start_counter_pwm()

print(
    'Pausing for 10 sec to allow time to observe with oscilloscope waveform on pin CTR0'
)
time.sleep(10)

# Now stopping the counter PWM wave
daq_one.stop_counter_pwm()

# We are done using the MagicDAQ, so close it
daq_one.close_daq_device()