--[[
|
编码: WCS-01-02
|
名称:
|
作者:lss
|
日期:2025-06-24
|
|
函数: EmptyTaskRun
|
功能:
|
|
更改记录:
|
|
--]]
|
|
json = require("json")
|
mobox = require("OILua_JavelinExt")
|
m3 = require("oi_base_mobox")
|
|
|
-- 从内存中获取设备信息
|
local function ReadS7PLCCommsData(strLuaDEID, devicecode, commcode)
|
local nRet, strRetInfo, api_ret
|
-- 开始调用
|
local canshu = {
|
device_code = devicecode,
|
comm_code = commcode
|
}
|
|
local strKey = "OpenInfo"
|
local strSecret = "OpenInfoSecret"
|
local strHeader = ''
|
-- 获取Header
|
nRet, strHeader = mobox.genReqVerify(strKey, strSecret)
|
strHeader = string.gsub(strHeader, "ReqTime", "\nReqTime")
|
strHeader = string.gsub(strHeader, "ReqVerify", "\nReqVerify")
|
lua.DebugEx(strLuaDEID, "strHeader:", strHeader)
|
|
local strBody = lua.table2str(canshu)
|
local strurl = "http://192.168.1.205:5121/api/devctrl/GetCommData"
|
lua.DebugEx(strLuaDEID, "接口调用前参数:", strBody)
|
|
nRet, strRetInfo = mobox.sendHttpRequest(strurl, strHeader, strBody)
|
lua.DebugEx(strLuaDEID, "接口调用后返回信息:", strRetInfo)
|
if (nRet ~= 0 or strRetInfo == '') then
|
lua.Stop(strLuaDEID,
|
"调用OIDeviceCommS接口ReadData失败! device_code = " .. devicecode .. " comm_code = " .. commcode ..
|
"错误码:" .. nRet .. " " .. strRetInfo)
|
return 1
|
end
|
local api_ret = json.decode(strRetInfo)
|
if (api_ret.err_code ~= 0) then
|
lua.Stop(strLuaDEID,
|
"调用OIDeviceCommS接口ReadData失败! device_code = " .. devicecode .. " comm_code = " .. commcode ..
|
"错误码:" .. api_ret.err_code .. " " .. api_ret.err_msg)
|
return 1
|
end
|
|
local retinfo = api_ret.result
|
return retinfo
|
end
|
|
-- 读出线体任务号 转换为我们的任务号
|
local function ReadPlcTaskNo(strLuaDEID, taskno1, taskno2)
|
lua.Debug(strLuaDEID, debug.getinfo(1), "ReadPlcTaskNo:", "IN")
|
if (taskno1 == 0 or taskno2 == 0) then
|
return '0'
|
end
|
local no1 = tostring(taskno1) -- 确保输入是字符串
|
if #no1 < 4 then
|
no1 = string.rep("0", 4 - #no1) .. no1
|
end
|
|
local no2 = tostring(taskno2) -- 确保输入是字符串
|
if #no2 < 4 then
|
no2 = string.rep("0", 4 - #no2) .. no2
|
end
|
local shortYear = os.date("%y")
|
return "TA" .. shortYear .. no1 .. "-" .. no2
|
end
|
|
--主函数
|
function EmptyTaskRun(strLuaDEID)
|
--获取全部
|
local nRet, WcsTasks
|
local strCondition = "N_B_STATE = '1' and S_TYPE ='呼叫空调'"
|
nRet, WcsTasks = m3.QueryDataObject(strLuaDEID, "Task", strCondition)
|
if (nRet ~= 0) then
|
lua.Stop(strLuaDEID, "获取已推送的空托任务失败" .. WcsTasks)
|
return 1
|
end
|
lua.DebugEx(strLuaDEID, 'WCS作业启动:', WcsTasks)
|
|
--遍历作业 根据作业类型创建任务
|
if (WcsTasks ~= '') then
|
for i = 1, #WcsTasks do
|
local WmsTask
|
nRet, WmsTask = m3.ObjAttrStrToLuaObj("Task", lua.table2str(WcsTasks[i].attrs))
|
--读取任务终点线体,判断托盘有没有到位
|
local DeviceResult = ReadS7PLCCommsData(strLuaDEID, "S7_LINE_01",
|
{ WcsTasks.end_loc_code .. "-WORK_MODE", WcsTasks.end_loc_code .. "-S_TASK_NO" })
|
local WORK_MODE = DeviceResult[1].value[1] --工作模式
|
local TaskNo = ReadPlcTaskNo(strLuaDEID, DeviceResult[8].value[1], DeviceResult[8].value[2]) -- todo 任务号
|
if (WORK_MODE == 3) then
|
if TaskNo == WcsTasks.code then
|
--设置任务完成
|
local updateTask, task
|
local strCondition = "S_CODE = '" .. WcsTasks.code .. "' "
|
nRet, updateTask = mobox.updateDataAttrByCondition(strLuaDEID, "Task", strCondition,
|
"S_B_STATE = '完成',N_B_STATE = 3")
|
if (nRet ~= 0) then
|
lua.stop(strLuaDEID, debug.getinfo(1), " SetTaskComplete 设置任务信息失败! " .. updateTask)
|
return 1
|
end
|
--判断当前任务作业下是否任务全部完成,如果全部完成,完成作业
|
local TaskSelect = "S_OP_CODE = '" .. WcsTasks.op_code .. "' and N_TYPE in (0,1)"
|
nRet, task = m3.GetDataObjByCondition(strLuaDEID, "Task", TaskSelect)
|
if (nRet == 2) then
|
lua.Stop(strLuaDEID,
|
"获取后叉任务信息有误! " .. task .. " SQL条件: " .. TaskSelect)
|
return 1
|
end
|
if (nRet == 1) then
|
--相同作业下不存在执行中的任务,设置作业完成
|
local strCondition = "S_CODE = '" .. WcsTasks.op_code .. "' "
|
nRet, updateTask = mobox.updateDataAttrByCondition(strLuaDEID, "Operation", strCondition,
|
"S_B_STATE = '完成',N_B_STATE = 3")
|
if (nRet ~= 0) then
|
lua.stop(strLuaDEID, debug.getinfo(1), " SetTaskComplete 设置作业信息失败! " .. updateTask)
|
return 1
|
end
|
return 0
|
end
|
return 0
|
end
|
end
|
end
|
end
|
|
return 0
|
end
|