ULAO02.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:mcculw 作者: mccdaq 项目源码 文件源码
def send_data(self):
        # Build the data array
        num_chans = min(self.ao_props.num_chans, 4)
        num_points = num_chans
        ao_range = self.ao_props.available_ranges[0]

        memhandle = ul.win_buf_alloc(num_points)

        # Check if the buffer was successfully allocated
        if not memhandle:
            messagebox.showerror("Error", "Failed to allocate memory")
            self.start_button["state"] = tk.NORMAL
            return

        try:
            data_array = self.memhandle_as_ctypes_array(memhandle)

            full_scale_count = (2 ** self.ao_props.resolution) - 1
            value_step = full_scale_count / (num_chans + 1)
            for point_num in range(0, num_points):
                raw_value = int(value_step * (point_num + 1))
                data_array[point_num] = raw_value

                self.raw_data_labels[point_num]["text"] = str(raw_value)
                # ul.to_eng_units cannot be used here, as it uses the analog
                # input resolution. Instead, do the conversion on our own.
                volts = self.ao_to_eng_units(
                    raw_value, ao_range, self.ao_props.resolution)
                self.volts_labels[point_num]["text"] = (
                    '{:.3f}'.format(volts))

            ul.a_out_scan(
                self.board_num, 0, num_chans - 1, num_points, 100, ao_range,
                memhandle, 0)
        except ULError as e:
            self.show_ul_error(e)
        finally:
            ul.win_buf_free(memhandle)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号