1
Jianw
10 天以前 f6f5e6b632d6649386a380558d84003f3de7ec6c
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
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")
 
local plc_base = {
    _version = "0.1.1"
}
 
--- 从设备中获取通讯项信息
function plc_base.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)
 
    -- 获取设备通讯URL
    local url
    nRet,url = wms_base.Get_sConst2( "设备通讯URL" )
    if ( nRet ~= 0 ) then
        lua.Stop( strLuaDEID, "系统无法获取常量 设备通讯URL")
        return 1,"系统无法获取常量 设备通讯URL"
    end
 
    local strurl = url .. "/api/devctrl/ReadData"
    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,"调用OIDeviceCommS接口ReadData失败! device_code = " .. devicecode .. " comm_code = " .. commcode ..
                "错误码:" .. nRet .. "  " .. strRetInfo
    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,"调用OIDeviceCommS接口ReadData失败! device_code = " .. devicecode .. " comm_code = " .. commcode ..
                "错误码:" .. nRet .. "  " .. strRetInfo
    end
 
    local retinfo = api_ret.result
    return 0,retinfo
end
 
return plc_base