Jianw
2025-05-13 3b39fe3810c3ee2ec9ec97236c1769c5c85e062c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--[[
    编码: WMS-100-01
    名称: HostToAgv-TaskCallBack
    作者:HAN    
    入口函数: TaskStatusCallback
              这段代码基本不需要改,各项目都是差不多的。
        
    功能说明:
            这个是一个 给 外部系统调用的 可编程接口,是AGV调度把车辆的状态发给 WMS 系统的接口
            发送过来的数据是一个Json包,格式如下:
            {"State":"%d","No":"%s","Ext1":"%s","Ext2":"%s","Ext3":"%s","ForkliftNo":"%d","ErrCode":"%d","ExtData":"%d"}
            State -- 车辆动作 具体见每个项目的车辆动作码定义
            No    -- Task 编码
            ForkliftNo -- 车辆编码
            
            处理以下这几件事情:
            1)解析外部输入的车辆状态信息 {"State":"%d","No":"%s","Ext1":"%s","Ext2":"%s","Ext3":"%s","ForkliftNo":"%d","ErrCode":"%d","ExtData":"%d"}
            2)根据 ForkliftNo 获取车辆所属工厂标识
            3)判断动作码在动作里是否存在,已经存在返回
            3)把动作码写入 MQ_EQAction  队列
 
    变更记录:
        V1.1
           + mq_eq_action.task_code = agv_action.No
        V3.0
           HAN 2023-6-16 
        V3.1 HAN 2023-7-2
            WMS_CreateDataObj 改成 m3.CreateDataObj
        V4.1 HAN 2023-8-9  wms相关接口调整 
        V6.0 HAN 2023/9/6  -- lua.Error/lua.Debug 函数变化 
--]]
wms_eq = require( "wms_equipment" )
  
function TaskStatusCallback ( strLuaDEID ) 
    local nRet, strRetInfo, strDataJson, strErr
 
    -- step1 获取接口中的Data
    nRet, agv_action = m3.GetSysDataJson( strLuaDEID )
    if ( nRet ~=0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "TaskStatusCallback 无法获取数据包!") end  
 
    -- 获取车辆编码
    local strForkliftNo = agv_action.ForkliftNo
    if ( strForkliftNo == '' ) then lua.Error( strLuaDEID, debug.getinfo(1), "ForkliftNo为空!") end  
 
    -- step2 获取车辆基本信息
    local eq 
    nRet, eq = wms_eq.Equipment_GetInfo( strLuaDEID, strForkliftNo )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), eq ) end
    -- 如果车辆没定义工厂标识返回错误
    if ( eq.factory == '') then
        strErr = "设备编号='"..strForkliftNo.."' 没定义工厂标识!"
        lua.Error( strLuaDEID, debug.getinfo(1), strErr )
    end
 
    -- step3 判断当前车辆的动作码是否已经在队列中(MQ_EQAction)
    local mq_eq_action = m3.AllocObject(strLuaDEID,"MQ_EQAction")
    mq_eq_action.task_code = agv_action.No
    mq_eq_action.eq_code = strForkliftNo
    mq_eq_action.action_code = agv_action.State
    nRet, strRetInfo = wms_eq.MQ_EQAction_Exist( strLuaDEID, mq_eq_action )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), strRetInfo )  end
    -- 如果该车辆编码的动作已经在队列,返回,不做处理
    if ( strRetInfo == "yes" ) then return end
 
    -- step4 把车辆动作写入队列
    mq_eq_action.factory = eq.factory
    mq_eq_action.eq_type = eq.type
    mq_eq_action.eq_type_name = eq.name
    mq_eq_action.data = lua.table2str(agv_action)
    nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, mq_eq_action )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), strRetInfo ) end
end