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_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) # This function returns PWM duty and frequency def get_dio_pwm(self, dio_name): ljm.eReadName(self.labjack_handler, dio_name + "_EF_READ_A_AND_RESET") # Here i wait 10 ms but also tried 100 ms sleep(0.01) high_state_ticks = ljm.eReadName(self.labjack_handler, dio_name + "_EF_READ_A") low_state_ticks = ljm.eReadName(self.labjack_handler, dio_name + "_EF_READ_B") try: period = 1.0/(high_state_ticks + low_state_ticks) except ZeroDivisionError: duty = 100.0 * ljm.eReadName(self.labjack_handler, dio_name) return duty, float("inf") duty = 100.0*high_state_ticks*period freq = 80*10**6*period return duty, freq labjack_handler = ljm.openS("T7", "ANY", "ANY") configure_ef_dio("DIO0") configure_dio_pwm_duty("DIO") # 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 as tuple print get_dio_pwm("DIO0")