Example #1
0
 def read_special_function_2_pulse_frequency_counter_with_debounce(
         self, timer):
     """
     Reads module's settings and constructs a human readable string containing the settings read.
     :param timer: timer to be read, integer.
     :return: string
     """
     response = self.read_registers({0: 1100, 1: 1200}[timer], 12)
     pulse_count = utils.int16_to_int32(response[4:6])
     frequency = utils.int16_to_int32(response[6:8])
     return {
         "Function":
         "2 = Pulse/Frequency Counter w/ Debounce".format(
             response, pulse_count, frequency),
         "Arm/Disarm":
         "{0[1]}".format(response, pulse_count, frequency),
         "Function Status":
         "{0[2]}".format(response, pulse_count, frequency),
         "Alarm Status":
         "{0[3]}".format(response, pulse_count, frequency),
         "Pulse Count":
         "{1}".format(response, pulse_count, frequency),
         "Frequency":
         "{2}".format(response, pulse_count, frequency),
         "Internal Trigger":
         "{0[8]}".format(response, pulse_count, frequency),
         "Debounce Output Enable":
         "{0[9]}".format(response, pulse_count, frequency),
         "Low Time (x 100us)":
         "{0[10]}".format(response, pulse_count, frequency),
         "High Time (x 100us)":
         "{0[11]}".format(response, pulse_count, frequency)
     }
Example #2
0
 def read_special_function_1_pulse_frequency_counter(self, timer):
     """
     Reads module's settings and constructs a human readable string containing the settings read.
     :param timer: timer to be read, integer.
     :return: string
     """
     response = self.read_registers({0: 1100, 1: 1200}[timer], 13)
     pulse_count = utils.int16_to_int32(response[4:6])
     frequency = utils.int16_to_int32(response[6:8])
     return {
         "Function":
         "1 = Pulse/Frequency Counter".format(response, pulse_count,
                                              frequency),
         "Arm/Disarm":
         "{0[1]}".format(response, pulse_count, frequency),
         "Function Status":
         "{0[2]}".format(response, pulse_count, frequency),
         "Alarm_Status":
         "{0[3]}".format(response, pulse_count, frequency),
         "Pulse_Count":
         "{1}".format(response, pulse_count, frequency),
         "Frequency":
         "{2}".format(response, pulse_count, frequency),
         "RPM":
         "{0[8]}".format(response, pulse_count, frequency),
         "Pulses Per Revolution":
         "{0[9]}".format(response, pulse_count, frequency),
         "Internal Trigger":
         "{0[10]}".format(response, pulse_count, frequency),
         "External Enable":
         "{0[11]}".format(response, pulse_count, frequency),
         "External Enable Status":
         "{0[12]}".format(response, pulse_count, frequency)
     }
Example #3
0
 def read_special_function_6_pwm_generator(self, timer):
     """
     Reads module's settings and constructs a human readable string containing the settings read.
     :param timer: timer to be read, integer.
     :return: string
     """
     response = self.read_registers({0: 1100, 1: 1200}[timer], 12)
     period = utils.int16_to_int32(response[6:8])
     output_1_low_time = utils.int16_to_int32(response[8:10])
     output_2_low_time = utils.int16_to_int32(response[10:12])
     return "Function         : 6 = PWM Generator\n" \
            "Arm/Disarm       : {0[1]}\n" \
            "Timebase         : {0[3]}\n" \
            "Output 2 Enable  : {0[4]}\n" \
            "Period           : {1}\n" \
            "Output 1 Low Time: {2}\n" \
            "Output 2 Low Time: {3}\n".format(response, period, output_1_low_time, output_2_low_time)
Example #4
0
 def read_special_function_4_time_between_events(self, timer):
     """
     Reads module's settings and constructs a human readable string containing the settings read.
     :param timer: timer to be read, integer.
     :return: string
     """
     response = self.read_registers({0: 1100, 1: 1200}[timer], 22)
     events_measured = utils.int16_to_int32(response[4:6])
     frequency = utils.int16_to_int32(response[6:8])
     time_between_events_curr = utils.int16_to_int32(response[8:10])
     time_between_events_max = utils.int16_to_int32(response[10:12])
     time_between_events_min = utils.int16_to_int32(response[12:14])
     time_between_events_average = utils.int16_to_int32(response[14:16])
     events_to_measure = utils.int16_to_int32(response[20:22])
     return "Function                    : 4 = Time Between Events\n" \
            "Arm/Disarm                  : {0[1]}\n" \
            "Function Status             : {0[2]}\n" \
            "Alarm Status                : {0[3]}\n" \
            "Events Measured             : {1}\n" \
            "Frequency                   : {2}\n" \
            "Time Between Events, current: {3}\n" \
            "Time Between Events, max    : {4}\n" \
            "Time Between Events, min    : {5}\n" \
            "Time Between Events, average: {6}\n" \
            "Timebase                    : {0[16]}\n" \
            "Event 1 Internal Trigger    : {0[17]}\n" \
            "Event 2 Internal Trigger    : {0[18]}\n" \
            "Average Weight              : {0[19]}\n" \
            "Events to measure           : {7}\n".format(response, events_measured, frequency,
                                                         time_between_events_curr,
                                                         time_between_events_max, time_between_events_min,
                                                         time_between_events_average, events_to_measure)
Example #5
0
 def read_special_function_5_frequency_generator(self, timer):
     """
     Reads module's settings and constructs a human readable string containing the settings read.
     :param timer: timer to be read, integer.
     :return: string
     """
     response = self.read_registers({0: 1100, 1: 1200}[timer], 22)
     frequency = utils.int16_to_int32(response[4:6])
     return "Function                    : 5 = Frequency Generator\n" \
            "Arm/Disarm                  : {0[1]}\n" \
            "Frequency                   : {1}\n".format(response, frequency)
Example #6
0
 def read_special_function_7_one_shot_pulse_generator(self, timer):
     """
     Reads module's settings and constructs a human readable string containing the settings read.
     :param timer: timer to be read, integer.
     :return: string
     """
     response = self.read_registers({0: 1100, 1: 1200}[timer], 16)
     pulse_count = utils.int16_to_int32(response[4:6])
     pulse_count_limit = utils.int16_to_int32(response[6:8])
     pulse_width = utils.int16_to_int32(response[10:12])
     pre_delay = utils.int16_to_int32(response[12:14])
     post_delay = utils.int16_to_int32(response[14:16])
     return "Function             : 7 = One-Shot Pulse Generator\n" \
            "Arm/Disarm           : {0[1]}\n" \
            "Timebase             : {0[3]}\n" \
            "Pulse Count          : {1}\n" \
            "Pulse Count Limit    : {2}\n" \
            "Output Pulse Polarity: {0[8]}\n" \
            "Trigger              : {0[9]}\n" \
            "Pulse Width          : {3}\n" \
            "Pre-delay            : {4}\n" \
            "Post-delay           : {5}\n".format(response, pulse_count, pulse_count_limit, pulse_width,
                                                  pre_delay, post_delay)
Example #7
0
"""
Example of how to use the utilities module in the MAQ20 API when reading and writing directly to registers.
"""
from maq20 import MAQ20
import maq20.utilities as utils

maq20 = MAQ20(ip_address="192.168.128.100", port=502)

com = maq20.get_com()  # get a reference to the COM module in the MAQ20 system

# The name of a module is stored in the first 15 registers
name_raw = com.read_registers(0, 15)
name = utils.response_to_string(
    com.read_registers(address=0, number_of_registers=11))
print('Raw name: {}'.format(name_raw))
print('utils.response_to_string(name_raw) : {}'.format(name))

print('')  # new line
# Writing a number bigger than 16 bits: 2^16-1 = 65535
com.write_registers(address=1368, values=utils.int32_to_int16s(987134))
# Reading a number bigger than 16 bits:
read_back = utils.int16_to_int32(
    com.read_registers(address=1368, number_of_registers=2))
print('Wrote 32 bit number 987134 and we read: {}'.format(read_back))
Example #8
0
 def read_special_function_3_waveform_measurement(self, timer):
     """
     Reads module's settings and constructs a human readable string containing the settings read.
     :param timer: timer to be read, integer.
     :return: string
     """
     response = self.read_registers({0: 1100, 1: 1200}[timer], 35)
     events_measured = utils.int16_to_int32(response[4:6])
     frequency = utils.int16_to_int32(response[6:8])
     period = utils.int16_to_int32(response[10:12])
     low_time = utils.int16_to_int32(response[12:14])
     high_time = utils.int16_to_int32(response[14:16])
     avg_low_time = utils.int16_to_int32(response[16:18])
     avg_high_time = utils.int16_to_int32(response[18:20])
     max_low_time = utils.int16_to_int32(response[20:22])
     min_low_time = utils.int16_to_int32(response[22:24])
     max_high_time = utils.int16_to_int32(response[24:26])
     min_high_time = utils.int16_to_int32(response[26:28])
     events_to_measure = utils.int16_to_int32(response[32:34])
     return "Function         : 3 = Waveform Measurement\n" \
            "Arm/Disarm       : {0[1]}\n" \
            "Function Status  : {0[2]}\n" \
            "Alarm Status     : {0[3]}\n" \
            "Events Measured  : {1}\n" \
            "Frequency        : {2}\n" \
            "Duty Cycle       : {0[8]}\n" \
            "Period           : {3}\n" \
            "Low Time         : {4}\n" \
            "High Time        : {5}\n" \
            "Avg Low Time     : {6}\n" \
            "Avg High Time    : {7}\n" \
            "Max Low Time     : {8}\n" \
            "Min Low Time     : {9}\n" \
            "Max High Time    : {10}\n" \
            "Min High Time    : {11}\n" \
            "Timebase         : {0[30]}\n" \
            "Internal Trigger : {0[31]}\n" \
            "Events To Measure: {12}\n" \
            "Average Weight   : {0[34]}\n".format(response, events_measured, frequency, period, low_time,
                                                  high_time, avg_low_time, avg_high_time, max_low_time,
                                                  min_low_time, max_high_time, min_high_time, events_to_measure)
Example #9
0
    def load_ranges_information(self):
        """
        Loads a module's ranges information into RAM.
        Ranges are stored in a list of dictionaries that has the keys:
        "Engineering-FS"
        "Engineering+FS"
        "EngineeringUnits"
        "CountValue-FS"
        "CountValue+FS"
        """
        # self._load_number_of_ranges()  # Ask module how many ranges it has

        if self._number_of_ranges > 0:
            try:
                self._ranges_information = []
                for range_num in range(self._number_of_ranges):
                    range_info = self.read_range(range_num)  # type: list
                    self._ranges_information.append({
                        "Engineering-FS":
                        range_info[0] * 10**range_info[4],
                        "Engineering+FS":
                        range_info[2] * 10**range_info[4],
                        "EngineeringUnits":
                        str(chr(range_info[5])) + str(chr(range_info[6])),
                        "CountValue-FS":
                        utils.int16_to_int32(range_info[7:9]),
                        "CountValue+FS":
                        utils.int16_to_int32(range_info[9:11]),
                    })
                    check = self._ranges_information[-1]
                    passed = self._check_range_validity(check)
                    if not passed:
                        if range_num == 1:
                            # May be Old Module
                            """
                            Old modules Contain the range information right next to the previous one instead of
                            skipping to 1710+(i*20), where i is the range number.
                            """
                            del self._ranges_information[-1]
                            for a_range in range(1, self._number_of_ranges):
                                range_info = self.read_registers(
                                    1710 + (a_range * 11), 11)
                                self._ranges_information.append({
                                    "Engineering-FS":
                                    range_info[0] * 10**range_info[4],
                                    "Engineering+FS":
                                    range_info[2] * 10**range_info[4],
                                    "EngineeringUnits":
                                    str(chr(range_info[5])) +
                                    str(chr(range_info[6])),
                                    "CountValue-FS":
                                    utils.int16_to_int32(range_info[7:9]),
                                    "CountValue+FS":
                                    utils.int16_to_int32(range_info[9:11]),
                                })
                                check = self._ranges_information[-1]
                                passed = self._check_range_validity(check)
                                if not passed:
                                    break
                        if not passed:
                            raise TypeError("Invalid Range Value")
                        break
            except Exception as e:
                pass
        else:
            self._number_of_ranges = None
            self._ranges_information = None  # type: list(dict)
            self._channel_active_ranges = None  # type: list