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
|