利用一个继电器来实现脚踏鼠标按钮
实现 一个 利用 按钮 鼠标 继电器
2023-09-11 14:15:22 时间
➤ 01自动记录测试数据
在实验台上集成了两组万用表,通过联网可以通过PYTHON语句自动将万用表的读数自动录入CSDN的markdown的编辑器,提高试验记录的效率和准确性。
- 第一组万用表:使用MEGA8单片机中继通过UART连入计算机
(1) FLUKE45;(2) FLUKE45;(3) LINT-T; (4)MASTECK - 第二组万用表:使用网络连入计算机
(1) RIGOL DM3068
记录数据的PYTHON命令: meterrec: CMD
▲ 左:指尖鼠标;右:拆开的继电器线圈
为了便于解放出双手来操作测量万用表的表笔,用于触发记录的鼠标左键按动则使用一个指尖鼠标来进行。鼠标的动作利用一个铁丝外加一个继电器线圈来触动动作。
➤ 02驱动制作
1.驱动电路
由于电磁铁来自于一个220V驱动的小型继电器,因此控制电路直接采用来自于220V室内交流整流后的电压来驱动。
为了增加动作力量,在鼠标的按动铁丝的底部安装有永磁铁。
▲ 驱动电路图
2.动作效果
采用脚动踏板开关(K)可以驱动指尖鼠标的正常的动作。
▲ 按键动作
3.为什么需要对220VAC进行整流滤波?
-
虽然直接施加220V交流电压到继电器的线圈,可以使其吸引铁质(铁丝),但是由于该电磁铁索固定的位置存在一个大型的永磁铁。由于外部的强磁场的偏执,这使得所产生的吸引力出现了较大的抖动(50Hz),而不是100Hz的脉动吸引力了。
-
使用半波整流,也是出现了这50Hz脉动吸引力,使得继电器作用在小型磁铁上的力出现较大的抖动。
-
只有通过全波整理,并且进行滤波,所产生的作用力才比较平稳。
※ 程序代码
下面是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:]
else:
tablesection = sys.argv[2:]
for s in tablesection:
if s.find('#') >=0:
tableid = 1
tablesection = [s.strip('#') for s in tablesection]
#------------------------------------------------------------
if meterid > 3:
dm3068open()
elif len(datachannel) > 0:
for c in datachannel:
if c > 3:
dm3068open()
break
#------------------------------------------------------------
#============================================================
#------------------------------------------------------------
def tspmsgdecimal(val, dn=-1):
if dn == 0:
tspmsg('%d '%val)
elif dn == 1:
tspmsg('%3.1f '%val)
elif dn == 2:
tspmsg('%4.2f '%val)
elif dn == 3:
tspmsg('%5.3f '%val)
elif dn == 4:
tspmsg('%6.4f '%val)
elif dn == 5:
tspmsg('%7.5f '%val)
elif dn == 6:
tspmsg('%8.6f '%val)
elif dn == 7:
tspmsg('%9.7f '%val)
elif dn == 8:
tspmsg('%10.8f '%val)
else:
tspmsg('%f '%val)
#------------------------------------------------------------
def recordchannel():
# global decimalnum
dn = decimaldim[meterid]
val = 0
val = getchannelval(meterid)
tspmsgdecimal(val, dn)
tspbeep(2000, 200)
#------------------------------------------------------------
ch1data = []
ch2data = []
ch3data = []
ch4data = []
ch5data = []
ch6data = []
ch7data = []
ch8data = []
def recorddata():
global datafilename
global datachannel
# global decimalnum
global decimaldim
global ch1data, ch2data, ch3data, ch4data
global ch5data, ch6data, ch7data, ch8data
tspbeep(1200, 50)
if len(datachannel) == 0:
printf('ERROR: Channel number: 0.')
exit()
if len(datafilename) == 0:
printf("ERROR: Data file length is zero.")
exit()
if len(ch1data) == 0:
tspclr()
if len(datachannel) >= 1:
if waitchannel[0] != 0: waitclick()
ch1data.append(getchannelval(datachannel[0]))
tspmsgdecimal(ch1data[-1], decimaldim[0])
if len(datachannel) >= 2:
if waitchannel[1] != 0: waitclick()
ch2data.append(getchannelval(datachannel[1]))
tspmsgdecimal(ch2data[-1], decimaldim[1])
if len(datachannel) >= 3:
if waitchannel[2] != 0: waitclick()
ch3data.append(getchannelval(datachannel[2]))
tspmsgdecimal(ch3data[-1], decimaldim[2])
if len(datachannel) >= 4:
if waitchannel[3] != 0: waitclick()
ch4data.append(getchannelval(datachannel[3]))
tspmsgdecimal(ch4data[-1], decimaldim[3])
if len(datachannel) >= 5:
if waitchannel[4] != 0: waitclick()
ch5data.append(getchannelval(datachannel[4]))
tspmsgdecimal(ch5data[-1], decimaldim[4])
if len(datachannel) >= 6:
if waitchannel[5] != 0: waitclick()
ch6data.append(getchannelval(datachannel[5]))
tspmsgdecimal(ch6data[-1], decimaldim[5])
if len(datachannel) >= 7:
if waitchannel[6] != 0: waitclick()
ch7data.append(getchannelval(datachannel[6]))
tspmsgdecimal(ch7data[-1], decimaldim[6])
if len(datachannel) >= 8:
if waitchannel[7] != 0: waitclick()
ch8data.append(getchannelval(datachannel[7]))
tspmsgdecimal(ch8data[-1], decimaldim[7])
if len(datachannel) == 1:
tspsave(datafilename, ch1=ch1data)
if len(datachannel) == 2:
tspsave(datafilename, ch1=ch1data, ch2=ch2data)
if len(datachannel) == 3:
tspsave(datafilename, ch1=ch1data, ch2=ch2data, ch3=ch3data)
if len(datachannel) == 4:
tspsave(datafilename, ch1=ch1data, ch2=ch2data, ch3=ch3data, ch4=ch4data)
if len(datachannel) == 5:
tspsave(datafilename, ch1=ch1data, ch2=ch2data, ch3=ch3data, ch4=ch4data, ch5=ch5data)
if len(datachannel) == 6:
tspsave(datafilename, ch1=ch1data, ch2=ch2data, ch3=ch3data, ch4=ch4data, ch5=ch5data, ch6=ch6data)
if len(datachannel) == 7:
tspsave(datafilename, ch1=ch1data, ch2=ch2data, ch3=ch3data, ch4=ch4data, ch5=ch5data, ch6=ch6data, ch7=ch7data)
if len(datachannel) == 8:
tspsave(datafilename, ch1=ch1data, ch2=ch2data, ch3=ch3data, ch4=ch4data, ch5=ch5data, ch6=ch6data, ch7=ch7data, ch8=ch8data)
printf("\a")
#------------------------------------------------------------
time.sleep(.5)
tspbeep(1000, 500)
tspclr()
clipboard.copy('')
#------------------------------------------------------------
if workmode == 1:
printf('Record data %s at %s:'%(datafilename, str(datachannel)))
tspshowcaption('Record data %s at %s:'%(datafilename, str(datachannel)))
tspclickaction(recorddata)
else:
tspclickaction(recordchannel)
#------------------------------------------------------------
tspmsgcopy()
tspbeep(500, 200)
#------------------------------------------------------------
# END OF FILE : METERREC.PY
#============================================================
相关文章
- sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)
- C#字符串数组排序 C#排序算法大全 C#字符串比较方法 一个.NET通用JSON解析/构建类的实现(c#) C#处理Json文件 asp.net使用Jquery+iframe传值问题
- JavaScript实现一个录屏功能
- 设计模式: 自己手动实现一个观察者设计模式
- python脚本实现集群检测和管理
- python基础编程:python如何实现浪漫的烟花秀(附代码)
- C7N Table 组件实现排序功能
- js new一个对象的过程,实现一个简单的new方法
- 从一个NPU失效问题看Linux PM Domain Framework的实现逻辑
- 基于Python+MySQL实现物联网引论课程一个火警报警及应急处理系统【100010366】
- Netty实现的一个异步Socket代码
- 利用ConcurrentHashMap来实现一个ConcurrentHashSet
- iOS网络缓存的系统实现是一个烂尾工程
- JavaScript实现99乘法表的打印
- 一个基于MVVM的TableView组件化实现方案
- Python基础入门-实现计算器多种姿势
- 如何快速实现一个基于Nginx的网站监控场景 – 操作篇
- 浅析如何利用逐帧动画配合补间动画实现一个无限循环的文字及图片轮播效果
- 如何利用UGUI在Unity中实现一个本地排行榜
- .net实现一个简单的通用查询数据、导出Excel的网页
- 基于SpringBoot框架实现的博客发布网站 附带运行指导文档
- 协程的简单实现
- 曹工杂谈:花了两天时间,写了一个netty实现的http客户端,支持同步转异步和连接池(1)--核心逻辑讲解
- PyTorch实现断点继续训练,学习率接着上一个epoch的接着变化