国产性一乱一性一伧的解决方法,国产一区影视,日韩欧美国产亚洲,日韩av在线播放不卡,国产69精品久久久久孕妇大杂乱 ,亚洲国产一,97国产精品视频,波多野结无码高清中文
君億道科技聯(lián)系電話:0755-26830682

公司新聞

最全面及時(shí)的公司資訊、企業(yè)動(dòng)態(tài)

Python for Windows USB-CTR04 同時(shí)操作

來源君億道

以下 Python for Windows 示例演示了設(shè)備發(fā)現(xiàn)以及USB-CTR04以與計(jì)數(shù)器通道相同的速率對(duì)數(shù)字端口進(jìn)行采樣的能力。

 

這是使用 ul.daq_in_scan() 而不是 ul.c_in_scan() 的一次性采集,不連續(xù)。使用一次性或有限模式(默認(rèn)),ul.daq_in_scan() 函數(shù)將阻塞,直到數(shù)據(jù)被捕獲到緩沖區(qū)。

 

程序配置了兩個(gè)計(jì)數(shù)器通道,第一個(gè)計(jì)數(shù)器設(shè)置為范圍計(jì)數(shù)。輸出線被啟用并由輸出寄存器控制。第二計(jì)數(shù)器被配置為測量周期。這個(gè)想法是第一個(gè)計(jì)數(shù)器將輸入頻率除以 100,第二個(gè)計(jì)數(shù)器對(duì)其進(jìn)行測量。對(duì)于測試信號(hào),使用 TMR0 線(頻率脈沖輸出)。推薦連接方式為 TMR0-->C0IN C0O-->C1IN

 

要安裝 Python for Windows 支持,請(qǐng)將以下 URL 復(fù)制到瀏覽器中并按照提供的說明進(jìn)行操作。

 

此示例是使用 Python 3.8.5 PyCharm 構(gòu)建的。代碼模塊通過本文末尾的下載鏈接提供。

 image.png

"""

文件:daq_in_scan_usb_1800.py

 

展示的庫調(diào)用:mcculw.ul.daq_in_scan()

 

目的:同步掃描數(shù)字端口和計(jì)數(shù)器

                            在前臺(tái)使用USB-CTR04 64 位支持。

 

演示:從數(shù)字端口和兩個(gè)計(jì)數(shù)器輸入收集數(shù)據(jù)。

 

其他庫調(diào)用:mcculw.ul.ignore_instacal()

                            mcculw.ul.get_daq_device_inventory()

                            mcculw.ul.create_daq_device()

                            mcculw.ul.win_buf_alloc_64()

                            mcculw.ul.c_config_scan()

                            mcculw.ul.pulse_out_start()

                            mcculw.ul.daq_in_scan()

                            mcculw.ul.pulse_out_stop()

                            mcculw.ul.win_buf_free()

                            mcculw.ul.release_daq_device()

 

特殊要求:此示例過濾器適用于 USB-1808 系列。

"""

from __future__ import absolute_import、除法、print_function

from builtins import * # @UnusedWildImport

 

ctypes 導(dǎo)入轉(zhuǎn)換、指針、c_doublec_ulonglongc_ubytec_ushort

 

mcculw 進(jìn)口 ul

mcculw.enums 導(dǎo)入 ScanOptionsChannelTypeULRangeDigitalPortType

mcculw.enums 導(dǎo)入 InterfaceTypeFunctionType

mcculw.enums 導(dǎo)入 CounterModeCounterDebounceModeCounterDebounceTime

mcculw.enums 導(dǎo)入 CounterEdgeDetectionCounterTickSizeCounterRegister

導(dǎo)入 ctypes

 

 

def run_example():

    use_device_detection = True

 

    內(nèi)存句柄 =

 

    嘗試:

        # **********開始設(shè)備發(fā)現(xiàn)************

        board_num = 0

        board_index = 0

        find_device = " USB-CTR04 "

        如果使用設(shè)備檢測:

            board_num = -1

            ul.ignore_instacal()

            dev_list = ul.get_daq_device_inventory(InterfaceType.USB)

            如果 len(dev_list) > 0

                對(duì)于 dev_list 中的設(shè)備:

                    如果 str(device) == find_device:

                        打印(f“找到{find_device}板號(hào)= {board_index}”

                        打印(f“序列號(hào):{device.unique_id}”

                        打印(f“產(chǎn)品類型:{hexdevice.product_id}”

                        board_num = board_index

                        ul.create_daq_device(board_num, device)

                        休息

                    board_index = board_index + 1

                如果 board_num == -1

                    打印(f“設(shè)備{find_device}未找到

            別的:

                print("未檢測到設(shè)備")

 

        # **********設(shè)備發(fā)現(xiàn)結(jié)束************

 

        # 將計(jì)數(shù)器配置為從 x 計(jì)數(shù)到 x+n 并帶有活動(dòng)輸出

        ctr0_mode = CounterMode.TOTALIZE | CounterMode.RANGE_LIMIT_ON | CounterMode.OUTPUT_ON

        如果 board_num > -1

            ul.c_config_scan(board_num,

                             0,

                             ctr0_mode,

                             CounterDebounceTime.DEBOUNCE_NONE,

                             CounterDebounceMode.TRIGGER_AFTER_STABLE

                             CounterEdgeDetection.RISING_EDGE

                             CounterTickSize.TICK20PT83ns,

                             0)

            # 除以 100

            ul.c_load_32(board_num, CounterRegister.MINLIMITREG0, 0)

            ul.c_load_32(board_num, CounterRegister.MAXLIMITREG0, 99)

 

            # 輸出將在零時(shí)切換為高電平,在 49 50% 占空比時(shí)切換為低電平

            ul.c_load_32(board_num, CounterRegister.OUTPUTVAL0REG0, 0)

            ul.c_load_32(board_num, CounterRegister.OUTPUTVAL1REG0, 49)

 

            # 測量計(jì)數(shù)器 0 輸出的周期;將 C0O 連接到 C1IN

            ul.c_config_scan(board_num,

                             1

                             CounterMode.PERIOD,

                             CounterDebounceTime.DEBOUNCE500ns,

                             CounterDebounceMode.TRIGGER_AFTER_STABLE

                             CounterEdgeDetection.RISING_EDGE

                             CounterTickSize.TICK20PT83ns,

                             0)

 

            # tick_size 是分配給單次計(jì)數(shù)的時(shí)間量

            刻度尺寸 = 0.000000020830

 

            # 創(chuàng)建 daq_in_scan 通道配置列表

            chan_list = []

            chan_type_list = []

            增益列表 = []

 

            chan_list.append(0)

            chan_type_list.append(ChannelType.CTRBANK0)

            gain_list.append(ULRange.NOTUSED)

 

            chan_list.append(0)

            chan_type_list.append(ChannelType.CTRBANK1)

            gain_list.append(ULRange.NOTUSED)

 

            chan_list.append(0)

            chan_type_list.append(ChannelType.CTRBANK2)

            gain_list.append(ULRange.NOTUSED)

 

            chan_list.append(0)

            chan_type_list.append(ChannelType.CTRBANK3)

            gain_list.append(ULRange.NOTUSED)

 

            chan_list.append(1)

            chan_type_list.append(ChannelType.CTRBANK0)

            gain_list.append(ULRange.NOTUSED)

 

            chan_list.append(1)

            chan_type_list.append(ChannelType.CTRBANK1)

            gain_list.append(ULRange.NOTUSED)

 

            chan_list.append(1)

            chan_type_list.append(ChannelType.CTRBANK2)

            gain_list.append(ULRange.NOTUSED)

 

            chan_list.append(1)

            chan_type_list.append(ChannelType.CTRBANK3)

            gain_list.append(ULRange.NOTUSED)

 

            # 數(shù)字端口是 8 位,但它是

            # 作為一個(gè) 16 位寄存器處理;使用 PADZERO 作為

            # 其他 48 位的虛擬占位符

 

            chan_list.append(DigitalPortType.AUXPORT)

            chan_type_list.append(ChannelType.DIGITAL8)

            gain_list.append(ULRange.NOTUSED)

 

            chan_list.append(DigitalPortType.AUXPORT)

            chan_type_list.append(ChannelType.PADZERO)

            gain_list.append(ULRange.NOTUSED)

 

            chan_list.append(DigitalPortType.AUXPORT)

            chan_type_list.append(ChannelType.PADZERO)

            gain_list.append(ULRange.NOTUSED)

 

            chan_list.append(DigitalPortType.AUXPORT)

            chan_type_list.append(ChannelType.PADZERO)

            gain_list.append(ULRange.NOTUSED)

 

            timer_num0 = 0

            頻率 = 20000

            占空比 = 0.5

 

            # 啟動(dòng)脈沖定時(shí)器輸出(可選參數(shù)省略)

            # 用作測試信號(hào)

            # TMR0 連接到 C0IN

            # 計(jì)數(shù)器 0 將除以它的范圍限制量

            實(shí)際頻率,實(shí)際占空比,_ = ul.pulse_out_start(

                board_numtimer_num0、頻率、占空比)

 

            num_channels = len(chan_list) # 16 位位置的數(shù)量

            num_64_bit_channels = 3 # 64 位通道數(shù)

            比率 = 2000

            num_rows = 384 # 掃描次數(shù),必須是 num_64_bit_channels 的倍數(shù)

            total_count = num_channels * num_rows # 12 * 96

 

            # 為掃描分配內(nèi)存并將其轉(zhuǎn)換為 ctypes 數(shù)組指針

            # 默認(rèn)寄存器大小為 64

            memhandle = ul.win_buf_alloc_64(total_count)

            # 檢查緩沖區(qū)是否分配成功

            如果不是內(nèi)存句柄:

                raise Exception('錯(cuò)誤:分配內(nèi)存失敗')

            緩沖區(qū) = 演員表(內(nèi)存句柄,指針(c_ulonglong))

 

            嘗試:

                # 開始掃描

                ul.daq_in_scan(board_num,

                               chan_list

                               chan_type_list

                               增益列表,

                               num_channels,

                               速度,

                               0,

                               總數(shù),

                               內(nèi)存句柄,

                               ScanOptions.DEFAULTIO)

 

            除了作為 e 的例外:

                print('daq_in_scan 錯(cuò)誤 >>>', e)

            print('掃描成功完成。')

 

            # 開始更新顯示的值

            狀態(tài),curr_countcurr_index = ul.get_status(

                board_num, FunctionType.DAQIFUNCTION)

            打印(f“狀態(tài){狀態(tài)}計(jì)數(shù){curr_count}索引{curr_index}”

 

            # 停止 TMR0 TMR1

            ul.pulse_out_stop(board_num, timer_num0)

 

 

            打印(指數(shù)\tCOIN\tC1IN\tDI”

 

            # 打印數(shù)據(jù)循環(huán) - 數(shù)字端口只有 8 位所以使用掩碼歸零

            # 高位

            指數(shù) = 0

            掩碼 = 0xFF

            對(duì)于我在范圍內(nèi)(num_rows):

                如果緩沖區(qū)[索引 + 1] > 0

                    # 如果計(jì)數(shù)不為零,則計(jì)算頻率

                    f = 1 / (buffer[index + 1] * tick_size)

                別的:

                    f = 0.01

                打印(f"{i:d}\t{buffer[index]:d}\t{f:5.2f} Hz \t{(buffer[index+2] & mask):d}")

                索引 += num_64_bit_channels

 

    除了作為 e 的例外:

        打印('\n'e

    最后:

        如果內(nèi)存句柄:

            # finally 塊中釋放緩沖區(qū)以防止內(nèi)存泄漏。

            ul.win_buf_free(memhandle)

        如果使用設(shè)備檢測:

            ul.release_daq_device(board_num)

 

 

如果 __name__ == '__main__'

    運(yùn)行示例()


主營:電流探頭,電壓探頭,羅氏線圈,電流傳感器,高壓探頭,電流互感器,功率電子測量產(chǎn)品
粵ICP備14003389號(hào)深圳君億道科技有限公司 © http://www.fengshengzhitongche.com
主站蜘蛛池模板: 于田县| 郎溪县| 鹤壁市| 龙陵县| 连州市| 康平县| 安岳县| 鸡西市| 莒南县| 合山市| 华蓥市| 石门县| 美姑县| 襄城县| 宝山区| 岳普湖县| 甘谷县| 东平县| 万全县| 梧州市| 饶阳县| 东海县| 蒙山县| 轮台县| 海宁市| 隆安县| 靖远县| 庐江县| 神农架林区| 威海市| 鹤峰县| 固阳县| 建昌县| 托克逊县| 永靖县| 怀化市| 定州市| 贵州省| 张家口市| 中山市| 扎囊县| 衢州市| 大关县| 张掖市| 舒兰市| 静安区| 高阳县| 孟村| 英吉沙县| 乐亭县| 西宁市| 仁怀市| 宜丰县| 明水县| 罗甸县| 会东县| 潮安县| 抚顺市| 泾阳县| 天柱县| 邹平县| 准格尔旗| 正安县| 乌什县| 凤城市| 鄂托克旗| 济源市| 理塘县| 高台县| 驻马店市| 钟祥市| 福州市| 榆社县| 连南| 宜良县| 洛宁县| 松原市| 洛扎县| 金寨县| 确山县| 壶关县| 滨海县|