--[[
|
编码:
|
名称: PLCStatusChange
|
作者: xsy
|
入口函数: PLCStatusChange
|
功能说明:
|
变更历史:
|
--]] m3 = require("oi_base_mobox")
|
lua = require("oi_base_func")
|
json = require("json")
|
mobox = require("OILua_JavelinExt")
|
wms_base = require("wms_base")
|
wms_cntr = require("wms_container")
|
ams_plc = require("amsplc_base")
|
|
-- --- 主动获取线体通讯项信
|
-- local function ReadS7PLCCommsData(strLuaDEID, devicecode, commcode)
|
|
-- -- 写数据到PLC
|
-- local function WriteS7PLCCommsData(strLuaDEID, devicecode, commcode, comm_value)
|
|
-- -- 托盘号查作业信息 (1072、1085、1099 入库称重点时用)
|
|
-- -- 根据任务号返回当前任务
|
-- local function ReturnTaskEnd(strLuaDEID, task_no, cntr_code)
|
|
-- -- 读出线体任务号 转换为我们的任务号
|
-- local function ReadPlcTaskNo(strLuaDEID, taskno1, taskno2)
|
|
-- 主函数
|
function PLCStatusChange(strLuaDEID)
|
local nRet, strRetInfo
|
local input_datajson
|
m3.PrintLuaDEInfo(strLuaDEID)
|
|
-- 设备编码, 线体编号, 信号,订阅名称
|
local device_code, unit_code, value, task_info, condition_flag, isexit
|
-- 获取接口中的Data
|
nRet, input_datajson = m3.GetSysDataJson(strLuaDEID)
|
if (nRet ~= 0) then
|
lua.Stop(strLuaDEID, "PLCStateChange无法获取数据包!" .. input_datajson)
|
return 1
|
end
|
-- 打印获取的设备信息
|
-- lua.DebugEx(strLuaDEID, "data_objs-->", input_datajson)
|
device_code = lua.Get_StrAttrValue(input_datajson.device_code) -- 设备编码
|
unit_code = lua.Get_StrAttrValue(input_datajson.unit_code) -- 线体编号
|
value = input_datajson.value[1]
|
|
-- lua.DebugEx(strLuaDEID, "unit_code", unit_code)
|
-- lua.DebugEx(strLuaDEID, "value", value)
|
if (value ~= 3) then
|
return 0
|
end
|
|
-- 扫码位
|
if (unit_code == "1072" or unit_code == "1085" or unit_code == "1099") then
|
-- 读取托盘码
|
local cntr_info = ams_plc.ReadS7PLCCommsData(strLuaDEID, "S7_LINE_01", {unit_code .. "-S_CNTR_NO"})
|
-- lua.DebugEx(strLuaDEID, "cntr_info", cntr_info)
|
cntr_code = cntr_info[1].value
|
--lua.DebugEx(strLuaDEID, "cntr_code", cntr_code)
|
-- 查询作业号
|
local op_info = ams_plc.QueryOpbyTray(strLuaDEID, cntr_code, "")
|
|
-- lua.DebugEx(strLuaDEID, "作业信息", op_info)
|
local op_code = op_info.code
|
|
-- local strCondition = "S_EQ_CODE = '" .. unit_code .. "' AND S_OP_CODE = '" .. op_code .. "' "
|
local strCondition = "S_EQ_CODE = '" .. unit_code .. "' AND S_OP_CODE = '" .. op_code .. "'" -- AND N_B_STATE != 1
|
nRet, isexit = mobox.existThisData(strLuaDEID, "MQ_EQAction", strCondition)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "调用方法existThisData出错" .. isexit)
|
return
|
end
|
|
if (isexit == 'yes') then
|
--lua.DebugEx(strLuaDEID, "设备队列中已存在,直接返回", isexit)
|
return 0
|
end
|
-- 判断当前车辆的动作码是否已经在队列中, 如果已经存在则不做处理
|
local mq_eq_action = m3.AllocObject(strLuaDEID, "MQ_EQAction")
|
mq_eq_action.op_code = op_code
|
mq_eq_action.eq_code = unit_code
|
mq_eq_action.action_code = 1
|
mq_eq_action.cntr_code = cntr_code
|
-- 把车辆动作写入队列
|
mq_eq_action.factory = "0001"
|
mq_eq_action.eq_type = 4
|
mq_eq_action.eq_type_name = "输送线"
|
|
-- lua.DebugEx(strLuaDEID, "创建设备动作队列前", mq_eq_action)
|
nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, mq_eq_action)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo)
|
end
|
|
--lua.DebugEx(strLuaDEID, "扫码位处理成功", "成功")
|
end
|
|
-- 分支点
|
if (unit_code == "1019" or unit_code == "1026") then
|
local is_task_running
|
local front_line_code -- 前叉线体编号
|
local back_line_code -- 后叉线体编号
|
local current_task_no_key -- :当前任务号通讯项
|
local front_fork_task_key -- :前叉任务号通讯项 (用于校验终点)
|
local front_fork_mode_key -- :前叉工作模式通讯项 (用于判断有载状态)
|
local back_fork_mode_key -- :后叉工作模式通讯项 (用于判断有载状态)
|
local next_branch_code -- :下个分支点编号
|
|
-- 前叉后叉 线体编号
|
if (unit_code == "1019") then
|
front_line_code = "1035" -- 前叉编号
|
back_line_code = "1033" -- 后叉编号
|
current_task_no_key = "1019-S_TASK_NO"
|
front_fork_task_key = "1035-S_TASK_NO"
|
front_fork_mode_key = "1035-WORK_MODE"
|
back_fork_mode_key = "1033-WORK_MODE"
|
next_branch_code = "1026"
|
elseif (unit_code == "1026") then
|
front_line_code = "1047"
|
back_line_code = "1045"
|
current_task_no_key = "1026-S_TASK_NO"
|
front_fork_task_key = "1047-S_TASK_NO"
|
front_fork_mode_key = "1047-WORK_MODE"
|
back_fork_mode_key = "1045-WORK_MODE"
|
next_branch_code = "1019"
|
end
|
|
-- 读当前任务号校验终点
|
local current_task_no = ams_plc.ReadS7PLCCommsData(strLuaDEID, device_code, {current_task_no_key})
|
|
if current_task_no then
|
-- 如果是数组类型(如[612,10]),需要根据业务需求处理:
|
-- 方案1:取第一个元素
|
local task_number = current_task_no[1].value[1]
|
local task_number2 = current_task_no[1].value[2]
|
if (task_number == 0 or task_number2 == 0) then
|
lua.DebugEx(strLuaDEID, "任务号为空已退出", "")
|
return
|
end
|
-- lua.DebugEx(strLuaDEID, "读到的任务号", current_task_no)
|
-- 将读到的任务号转换为我们的任务号
|
local us_task_no = ams_plc.ReadPlcTaskNo(strLuaDEID, task_number, task_number2)
|
|
-- 通过任务号当前任务的终点
|
local mst = ams_plc.ReturnTaskEnd(strLuaDEID, us_task_no, "")
|
-- lua.DebugEx(strLuaDEID, "通过任务号查到的终点", mst.end_loc_code)
|
|
-- 终点为当前线体时
|
if (mst.end_loc_code == unit_code) then
|
-- 判断当前车辆的动作码是否已经在队列中, 如果已经存在则不做处理
|
|
-- local strCondition = "S_EQ_CODE = '" .. unit_code .. "' AND S_TASK_CODE = '" .. us_task_no .. "'"
|
local strCondition = "S_EQ_CODE = '" .. unit_code .. "' AND N_B_STATE != 1"
|
nRet, isexit = mobox.existThisData(strLuaDEID, "MQ_EQAction", strCondition)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "调用方法existThisData出错" .. isexit)
|
return
|
end
|
|
if (isexit == 'yes') then
|
lua.DebugEx(strLuaDEID, "设备队列中已存在,直接返回", isexit)
|
return 0
|
end
|
|
local mq_eq_action = m3.AllocObject(strLuaDEID, "MQ_EQAction")
|
mq_eq_action.eq_code = unit_code
|
mq_eq_action.action_code = 2
|
mq_eq_action.task_code = us_task_no
|
-- 把车辆动作写入队列
|
mq_eq_action.factory = "0001"
|
mq_eq_action.eq_type = 4
|
mq_eq_action.eq_type_name = "输送线"
|
|
lua.DebugEx(strLuaDEID, "创建设备动作队列前", mq_eq_action)
|
nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, mq_eq_action)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo)
|
end
|
else
|
ams_plc.WriteS7PLCCommsData(strLuaDEID, "S7_LINE_01", "1019-TARGRT_ADDRESS",
|
{tonumber(mst.end_loc_code)})
|
end
|
end
|
end
|
|
-- 接驳位
|
if (unit_code == "1035" or unit_code == "1033" or unit_code == "1047" or unit_code == "1045") then
|
|
-- 获取当前位置的任务号
|
local current_task_no = ams_plc.ReadS7PLCCommsData(strLuaDEID, "S7_LINE_01", {unit_code .. "-S_TASK_NO"}); -- 当前任务号
|
if current_task_no then
|
-- 如果是数组类型(如[612,10]),需要根据业务需求处理:
|
-- 方案1:取第一个元素
|
local task_number = current_task_no[1].value[1]
|
local task_number2 = current_task_no[1].value[2]
|
if (task_number == 0 or task_number2 == 0) then
|
lua.DebugEx(strLuaDEID, "读到的任务号为0,不执行", task_number)
|
return
|
end
|
|
-- lua.DebugEx(strLuaDEID, "读到的任务号", current_task_no)
|
-- 将读到的任务号转换为我们的任务号
|
local us_task_no = ams_plc.ReadPlcTaskNo(strLuaDEID, task_number, task_number2)
|
-- 通过任务号当前任务的终点
|
local mst = ams_plc.ReturnTaskEnd(strLuaDEID, us_task_no, "")
|
-- lua.DebugEx(strLuaDEID, "通过任务号得到的终点", mst.end_loc_code)
|
-- 查询当前作业信息
|
local isPush = ams_plc.GetddjTaskInfo(strLuaDEID, mst.op_code)
|
if (isPush ~= 'yes') then
|
-- 终点为当前线体时
|
if (mst.end_loc_code == unit_code) then
|
-- local strCondition = "S_EQ_CODE = '" .. unit_code .. "' AND S_TASK_CODE = '" .. us_task_no .. "'"
|
local strCondition = "S_EQ_CODE = '" .. unit_code .. "' AND N_B_STATE != 1"
|
nRet, isexit = mobox.existThisData(strLuaDEID, "MQ_EQAction", strCondition)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "调用方法existThisData出错" .. isexit)
|
return
|
end
|
if (isexit == 'yes') then
|
lua.DebugEx(strLuaDEID, "设备队列中已存在,直接返回", isexit)
|
return 0
|
end
|
|
local mq_eq_action = m3.AllocObject(strLuaDEID, "MQ_EQAction")
|
mq_eq_action.eq_code = unit_code
|
mq_eq_action.action_code = 3
|
mq_eq_action.task_code = us_task_no
|
mq_eq_action.op_code = mst.op_code
|
-- 把车辆动作写入队列
|
mq_eq_action.factory = "0001"
|
mq_eq_action.eq_type = 4
|
mq_eq_action.eq_type_name = "输送线"
|
|
-- lua.DebugEx(strLuaDEID, "创建设备动作队列前", mq_eq_action)
|
nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, mq_eq_action)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo)
|
end
|
end
|
else
|
lua.DebugEx(strLuaDEID,
|
"当前作业" .. mst.op_code .. "的堆垛机任务已推送,不再创建动作队列", "return")
|
end
|
end
|
end
|
end
|