from labjack import ljm from time import sleep def configure_ef_dio(dio_name): ljm.eWriteName(labjack_handler, dio_name + "_EF_ENABLE", 0) ljm.eWriteName(labjack_handler, "DIO_EF_CLOCK0_DIVISOR", 0) ljm.eWriteName(labjack_handler, "DIO_EF_CLOCK0_ROLL_VALUE", 0) ljm.eWriteName(labjack_handler, "DIO_EF_CLOCK0_ENABLE", 1) def enable_ef_dio(dio_name): ljm.eWriteName(labjack_handler, dio_name + "_EF_ENABLE", 1) def disable_ef_dio(dio_name): ljm.eWriteName(labjack_handler, dio_name + "_EF_ENABLE", 0) def configure_dio_pwm_freq(dio_name): disable_ef_dio(dio_name) ljm.eWriteName(labjack_handler, dio_name + "_EF_OPTIONS", 0) ljm.eWriteName(labjack_handler, dio_name + "_EF_CONFIG_A", 0) ljm.eWriteName(labjack_handler, dio_name + "_EF_INDEX", 3) enable_ef_dio(dio_name) def get_dio_pwm_freq(dio_name): configure_dio_pwm_freq(dio_name) ljm.eReadName(labjack_handler, dio_name + "_EF_READ_A_AND_RESET") # I have to wait here at least 300 ms sleep(0.3) ljm.eReadName(labjack_handler, dio_name + "_EF_READ_A_F") return ljm.eReadName(labjack_handler, dio_name + "_EF_READ_B_F") def configure_dio_pwm_duty(dio_name): disable_ef_dio(dio_name) ljm.eWriteName(labjack_handler, dio_name + "_EF_OPTIONS", 0) ljm.eWriteName(labjack_handler, dio_name + "_EF_CONFIG_A", 0) ljm.eWriteName(labjack_handler, dio_name + "_EF_INDEX", 5) enable_ef_dio(dio_name) def get_dio_pwm_duty(dio_name): configure_dio_pwm_duty(dio_name) ljm.eReadName(labjack_handler, dio_name + "_EF_READ_A_F_AND_RESET") # I have to wait here at least 300 ms sleep(0.3) high_state_time = ljm.eReadName(labjack_handler, dio_name + "_EF_READ_A_F") low_state_time = ljm.eReadName(labjack_handler, dio_name + "_EF_READ_B_F") try: period = 100.0/(high_state_time + low_state_time) # When registers hold both zero values i assume signal is either 0 or 100 hence i just measure pin state except ZeroDivisionError: disable_ef_dio(dio_name) return 100.0*ljm.eReadName(labjack_handler, dio_name) return high_state_time*period labjack_handler = ljm.openS("T7", "ANY", "ANY") configure_ef_dio("DIO0") # This is only mock function used to replace my real function which adjust PWM signal def set_device_signal(): pass while True: # Here i set my device signal so it adjust PWM output set_device_signal() # Than i want to read duty and frequency on same pin print get_dio_pwm_duty("DIO0") print get_dio_pwm_freq("DIO0")