前言
今天和一个同事在聊天,聊到一个客户希望在台达的触摸屏上实现以下功能:
在设定时间内,没有操作人员没有操作触摸屏,让触摸屏自动的跳转到指定的页面。
最开始我想到的是利用触摸屏自带的屏保的功能,不过,实验后发现,如果只是指定某一个页面为屏保的话,页面的数据是不会进行更新的。这显然不符合工业的操作习惯和需求。
正文
采用DOP-100系列开始后全系列都内置了Lua 程序。
直接附上测试界面和程序
测试界面


Lua程序
--台达DOP-100系列触摸无操作定时跳转指定页面
while true do
--获取鼠标坐标X,Y
x = sys.GetInterParam("TP_X")
y = sys.GetInterParam("TP_Y")
--读取$2的值写入z变量
z = mem.inter.Read(2)
--读取$3的值写入u变量
u = mem.inter.Read(3)
--防止没有设置无法跳回原来页面
if (u == 0) then
mem.inter.Write(3, 10)
end
--读取$4的值写入p变量
p = mem.inter.Read(4)
-- one cycle is 100ms
sys.Sleep(100)
--分别把X坐标写入$0,Y坐标写入$1
mem.inter.Write(0, x)
mem.inter.Write(1, y)
--读取$0的值写入x1变量,读取$1的值写入y1变量
x1 = mem.inter.Read(0)
y1 = mem.inter.Read(1)
--判断鼠标是否在当前位置停留
if (x1 == sys.GetInterParam("TP_X")) then
if (y1 == sys.GetInterParam("TP_Y")) then
z1 = z + 1
mem.inter.Write(2, z1)
else
mem.inter.Write(2, 0)
end
else
mem.inter.Write(2, 0)
end
--计时时间到,跳转页面
if (z1 >= u) then
screen.Open(p)
z1 = 0
mem.inter.Write(2, 0)
end
end
结尾
结合上面实例,最终实现客户需要的功能: 在设定时间内,没有操作人员没有操作触摸屏,让触摸屏自动的跳转到指定的页面。
Log:
2021-03-25 发布本文
网友评论