资讯详情

利用一个继电器来实现脚踏鼠标按钮

? 01测试数据自动记录


两组万用表集成在实验台上,可以通过网络连接PYTHON语句自动输入万用表读数CSDN的markdown提高试验记录的效率和准确性。

  • 第一组万用表:使用MEGA8单片机中继通过UART连入计算机 (1) FLUKE45;(2) FLUKE45;(3) LINT-T; (4)MASTECK
  • 第二组万用表:使用网络连入计算机 (1) RIGOL DM3068

记录数据的PYTHON命令: meterrec: CMD

▲ 左:指尖鼠标;右:拆卸继电器线圈

为了方便解放双手操作测量万用表的表笔,用指尖鼠标按下触发记录的鼠标左键。鼠标的动作是用铁丝和继电器线圈触摸的。

? 02驱动制作


1.驱动电路

因为电磁铁来自220V由220驱动的小型继电器直接采用控制电路V室内交流整流后的电压驱动。

永磁铁安装在鼠标按动铁丝底部,以增加动作力。

▲ 驱动电路图

2.动作效果

采用脚动踏板开关(K)能驱动指尖鼠标的正常动作。

▲ 按键动作

3.为什么需要220VAC整流滤波?

  1. 尽管直接施220V交流电压到继电器的线圈可以吸引铁(电线),但由于电磁电缆的固定位置有一个大型永磁铁。由于外部强磁场的偏执,吸引力大幅抖动(50Hz),而不是100Hz脉动吸引力。

  2. 使用半波整流,这50也出现了Hz脉动吸引力使继电器作用在小磁铁上的力大幅抖动。

  3. 只有通过全波整理和滤波,产生的力才能相对稳定。

※ 程序代码


下面是METERREC对应的PYTHON命令:

#!/usr/local/bin/python # -*- coding: gbk -*- #============================================================ # METERREC.PY -- by Dr. ZhuoQing 2020-07-06 # # Note: #============================================================  from headm import * import os from tsmodule.tsstm32       import * from tsmodule.tsvisa        import *  #------------------------------------------------------------ csdn_title = '写文章-CSDN博客'  #============================================================  #------------------------------------------------------------ def val2decimalstring(val, dn=-1):     if dn == 0:         return '%d '%val     elif dn == 1:         return '%3.1f '%val     elif dn == 2
       
        : 
        return 
        '%4.2f '
        %val 
        elif dn 
        == 
        3
        : 
        return 
        '%5.3f '
        %val 
        elif dn 
        == 
        4
        : 
        return 
        '%6.4f '
        %val 
        elif dn 
        == 
        5
        : 
        return 
        '%7.5f '
        %val 
        elif dn 
        == 
        6
        : 
        return 
        '%8.6f '
        %val 
        elif dn 
        == 
        7
        : 
        return 
        '%9.7f '
        %val 
        elif dn 
        == 
        8
        : 
        return 
        '%10.8f '
        %val 
        else
        : 
        return 
        '%f '
        %val 
        #------------------------------------------------------------ 
        def 
        getchannelval
        (ch
        )
        : 
        if ch 
        == 
        9
        : 
        input 
        = tspinputline
        (string
        =
        ''
        , hint
        =
        'Input Value'
        , title
        =
        'Input'
        )
        .strip
        (
        ' '
        ) 
        if 
        len
        (
        input
        ) 
        > 
        0
        : 
        return 
        float
        (
        input
        ) 
        else
        : 
        return 
        0 
        if ch 
        < 
        4
        : 
        for i 
        in 
        range
        (
        20
        )
        : meter 
        = meterval
        (
        ) 
        if 
        len
        (meter
        ) 
        >= 
        4
        : val 
        = meter
        [ch
        ] 
        break 
        else
        : val 
        = 
        0 
        elif ch 
        == 
        4
        : val 
        = dm3068vdc
        (
        ) 
        elif ch 
        == 
        5
        : val 
        = dm3068vac
        (
        ) 
        elif ch 
        == 
        6
        : val 
        = dm3068res
        (
        ) 
        elif ch 
        == 
        7
        : val 
        = dm3068freq
        (
        ) 
        else
        : val 
        = dm3068vdc
        (
        ) 
        return val 
        #------------------------------------------------------------ 
        def 
        waitclick
        (
        )
        : tspbeep
        (
        1800
        , 
        350
        ) 
        while 
        True
        : key 
        = tspread
        (
        ) 
        if key
        [
        2
        ] 
        != 
        0 
        or key
        [
        3
        ] 
        != 
        0
        : 
        break time
        .sleep
        (
        .5
        ) 
        while 
        True
        : key 
        = tspread
        (
        ) 
        if key
        [
        2
        ] 
        == 
        0 
        or key
        [
        3
        ] 
        == 
        0
        : 
        break time
        .sleep
        (
        .5
        ) 
        #------------------------------------------------------------ 
        def 
        tspclickaction
        (func1
        =
        None
        , func2
        =
        None
        )
        : 
        global workmode 
        global tablesection
        , tableid 
        global ch1data
        , ch2data
        , ch3data
        , ch4data 
        global ch5data
        , ch6data
        , ch7data
        , ch8data 
        #-------------------------------------------------------- 
        def 
        f1
        (
        )
        : tspmsg
        (
        'msg \a'
        ) 
        def 
        f2
        (
        )
        : printf
        (
        '\a'
        ) 
        if func1 
        == 
        None
        : func1 
        = f1 
        if func2 
        == 
        None
        : func2 
        = f2 
        #-------------------------------------------------------- codeflag 
        = 
        0 
        if 
        len
        (tablesection
        ) 
        > 
        0
        : printf
        (
        ' '
        .join
        (tablesection
        )
        ) linenum 
        = 
        0 
        #-------------------------------------------------------- 
        while 
        True
        : 
        if codeflag 
        == 
        0
        : time
        .sleep
        (
        .5
        ) 
        else
        : time
        .sleep
        (
        .5
        ) key 
        = tspread
        (
        ) 
        if key
        [
        7
        ] 
        != 
        0 
        and codeflag 
        == 
        0
        : 
        if key
        [
        2
        ] 
        != 
        0
        : tspmsgcopy
        (
        ) tspclr
        (
        ) tspbeep
        (
        1200
        , 
        100
        ) codeflag 
        = 
        1 
        if 
        len
        (tablesection
        ) 
        > 
        0
        : tspexecutepythoncmd
        (
        'cdpt'
        ) 
        if 
        len
        (tablesection
        ) 
        > 
        0
        : printf
        (
        ' '
        .join
        (tablesection
        )
        ) 
        continue 
        if key
        [
        3
        ] 
        != 
        0
        : 
        return 
        if key
        [
        2
        ] 
        != 
        0 
        and codeflag 
        == 
        0
        : codeflag 
        = 
        1 
        continue 
        if key
        [
        3
        ] 
        != 
        0 
        and codeflag 
        == 
        0
        : codeflag 
        = 
        2 
        continue 
        if codeflag 
        != 
        0
        : 
        if key
        [
        2
        ] 
        == 
        0 
        and key
        [
        3
        ] 
        == 
        0
        : 
        if codeflag 
        == 
        1
        : func1
        (
        ) linenum 
        = linenum 
        + 
        1 
        if 
        len
        (tablesection
        ) 
        > 
        0
        : 
        if linenum 
        >= 
        len
        (tablesection
        ) 
        - tableid
        : func2
        (
        ) linenum 
        = 
        0 
        elif codeflag 
        == 
        2
        : 
        if 
        len
        (tablesection
        ) 
        == 
        0
        : func2
        (
        ) 
        if workmode 
        == 
        1
        : ch1data 
        = 
        [
        ] ch2data 
        = 
        [
        ] ch3data 
        = 
        [
        ] ch4data 
        = 
        [
        ] ch5data 
        = 
        [
        ] ch6data 
        = 
        [
        ] ch7data 
        = 
        [
        ] ch8data 
        = 
        [
        ] tspclr
        (
        ) printf
        (
        'Record data %s at %s:'
        %
        (datafilename
        , 
        str
        (datachannel
        )
        )
        ) 
        else
        : tspclr
        (
        ) tspbeep
        (
        1200
        , 
        200
        ) 
        if 
        len
        (tablesection
        ) 
        > 
        0
        : printf
        (
        ' '
        .join
        (tablesection
        )
        ) linenum 
        = 
        0 codeflag 
        = 
        0 
        continue 
        if key
        [
        2
        ] 
        != 
        0 
        and key
        [
        3
        ] 
        != 
        0
        : 
        if codeflag 
        == 
        1
        : printf
        (
        "\r\n"
        ) tspmsgcopy
        (
        ) tspbeep
        (
        1200
        , 
        100
        ) codeflag 
        = 
        3 
        if 
        len
        (tablesection
        ) 
        > 
        0
        : tspexecutepythoncmd
        (
        'cdpt'
        ) time
        .sleep
        (
        1.5
        ) tspclr
        (
        ) 
        if 
        len
        (tablesection
        ) 
        > 
        0
        : printf
        (
        ' '
        .join
        (tablesection
        )
        ) tspbeep
        (
        1500
        , 
        100
        ) 
        continue 
        elif codeflag 
        == 
        2
        : 
        return 
        #------------------------------------------------------------ windowtitle 
        = tspgetwindowtitle
        (
        ) findflag 
        = 
        0 meterfile 
        = r
        'D:\zhuoqing\window\cb\MyResearch\Test\TestAD5344\M8BL_BAS\M8BL_BAS.exe' 
        for wt 
        in windowtitle
        : 
        if wt
        .find
        (
        'MEGA8 DOWLOAD PROGERAM'
        ) 
        >= 
        0
        : findflag 
        = 
        1 
        break 
        if findflag 
        == 
        0
        : os
        .system
        (meterfile
        ) time
        .sleep
        (
        .5
        ) tspbeep
        (
        1200
        , 
        200
        ) 
        #============================================================ 
        #------------------------------------------------------------ workmode 
        = 
        0 
        # 0 Record the table data 
        # 1 Record data file meterid 
        = 
        0 
        #decimalnum = -1 # Decimal number no limited decimaldim 
        = 
        [
        -
        1
        ] 
        * 
        32 datafilename 
        = 
        '' datachannel 
        = 
        [
        ] waitchannel 
        = 
        [
        ] tablesection 
        = 
        [
        ] 
        # tableid 
        = 
        0 
        # 
        #------------------------------------------------------------ 
        if 
        len
        (sys
        .argv
        ) 
        > 
        1
        : 
        #-------------------------------------------------------- 
        if sys
        .argv
        [
        1
        ]
        [
        0
        ] 
        == 
        '#'
        : chstr 
        = sys
        .argv
        [
        1
        ]
        [
        1
        :
        ] dnum 
        = 
        -
        1 
        if chstr
        .find
        (
        '.'
        ) 
        > 
        0
        : csc 
        = chstr
        .split
        (
        '.'
        ) 
        if csc
        [
        0
        ]
        .isdigit
        (
        ) 
        and csc
        [
        1
        ]
        .isdigit
        (
        )
        : ch 
        = 
        int
        (csc
        [
        0
        ]
        ) dnum 
        = 
        int
        (csc
        [
        1
        ]
        ) chval 
        = getchannelval
        (ch
        ) insertstr 
        = val2decimalstring
        (chval
        , dnum
        ) clipboard
        .copy
        (insertstr
        ) tspsendwindowkey
        (csdn_title
        , 
        'v'
        , control
        =
        1
        , noreturn
        =
        1
        ) clipboard
        .copy
        (
        ''
        ) tspfocuswindow
        (csdn_title
        ) exit
        (
        ) 
        elif chstr
        .isdigit
        (
        )
        : ch 
        = 
        int
        (chstr
        ) dnum 
        = 
        -
        1 chval 
        = getchannelval
        (ch
        ) insertstr 
        = val2decimalstring
        (chval
        , dnum
        ) clipboard
        .copy
        (insertstr
        ) tspsendwindowkey
        (csdn_title
        , 
        'v'
        , control
        =
        1
        , noreturn
        =
        1
        ) clipboard
        .copy
        (
        ''
        ) tspfocuswindow
        (csdn_title
        ) exit
        (
        ) 
        elif chstr 
        == 
        'dt'
        : insertstr 
        = time
        .strftime
        (
        '%Y-%m-%d %H:%M:%S'
        ) clipboard
        .copy
        (insertstr
        ) tspsendwindowkey
        (csdn_title
        , 
        'v'
        , control
        =
        1
        , noreturn
        =
        1
        ) clipboard
        .copy
        (
        ''
        ) tspfocuswindow
        (csdn_title
        ) exit
        (
        ) 
        elif chstr 
        == 
        'date' 
        or chstr 
        == 
        'd'
        : insertstr 
        = time
        .strftime
        (
        '%Y-%m-%d'
        ) clipboard
        .copy
        (insertstr
        ) tspsendwindowkey
        (csdn_title
        , 
        'v'
        , control
        =
        1
        , noreturn
        =
        1
        ) clipboard
        .copy
        (
        ''
        ) tspfocuswindow
        (csdn_title
        ) exit
        (
        ) 
        elif chstr 
        == 
        'time' 
        or chstr 
        == 
        't'
        : insertstr 
        = time
        .strftime
        (
        '%H:%M:%S'
        ) clipboard
        .copy
        (insertstr
        ) tspsendwindowkey
        (csdn_title
        , 
        'v'
        , control
        =
        1
        , noreturn
        =
        1
        ) clipboard
        .copy
        (
        ''
        ) tspfocuswindow
        (csdn_title
        ) exit
        (
        ) 
        #-------------------------------------------------------- 
        if sys
        .argv
        [
        1
        ]
        .isdigit
        (
        ) 
        == 
        False 
        and\ sys
        .argv
        [
        1
        ]
        .find
        (
        '.'
        ) 
        < 
        0
        : datafilename 
        = sys
        .argv
        [
        1
        ] 
        for s 
        in sys
        .argv
        [
        2
        :
        ]
        : 
        if s
        .isdigit
        (
        ) 
        == 
        False 
        and\ s
        .find
        (
        '.'
        ) 
        < 
        0
        : printf
        (
        "meterrec datafile ch1 ch2 ..."
        ) exit
        (
        ) 
        if s
        .isdigit
        (
        ) 
        == 
        True
        : 
        if 
        not 
        int
        (s
        ) 
        in datachannel
        : datachannel
        .append
        (
        int
        (s
        )
        ) waitchannel
        .append
        (
        0
        ) 
        else
        : waitchannel
        [datachannel
        .index
        (
        int
        (s
        )
        )
        ] 
        = 
        1 
        else
        : sc 
        = s
        .split
        (
        '.'
        ) 
        if 
        not 
        int
        (sc
        [
        0
        ]
        ) 
        in datachannel
        : decimaldim
        [
        len
        (datachannel
        )
        ] 
        = 
        int
        (sc
        [
        1
        ]
        ) datachannel
        .append
        (
        int
        (sc
        [
        0
        ]
        )
        ) waitchannel
        .append
        (
        0
        ) 
        else
        : waitchannel
        [datachannel
        .index
        (sc
        [
        0
        ]
        )
        ] 
        = 
        1 
        if 
        len
        (datachannel
        ) 
        == 
        0
        : printf
        (
        "meterrec datafile ch1 ch2 ..."
        ) exit
        (
        ) workmode 
        = 
        1 
        # 
        else
        : 
        if sys
        .argv
        [
        1
        ]
        .isdigit
        (
        )
        : meterid 
        = 
        int
        (sys
        .argv
        [
        1
        ]
        ) 
        elif sys
        .argv
        [
        1
        ]
        .find
        (
        '.'
        ) 
        >= 
        0
        : sc 
        = sys
        .argv
        [
        1
        ]
        .split
        (
        '.'
        ) meterid 
        = 
        int
        (sc
        [
        0
        ]
        ) decimaldim 
        = 
        [
        int
        (sc
        [
        1
        ]
        )
        ] 
        * 
        32 
        if 
        len
        (sys
        .argv
        ) 
        > 
        2
        : 
        if sys
        .argv
        [
        2
        ]
        .isdigit
        (
        )
        : 
        # decimalnum = int(sys.argv[2]) dn 
        = 
        int
        (sys
        .argv
        [
        2
        ]
        ) decimaldim 
        = 
        [dn
        ] 
        * 
        32 tablesection 
        = sys
        .argv
        [
        3
        :

标签: d2s交流继电器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台