function main()
local sSiteID = '999';
local sEqptID = '888';
local sVarFunc = 'barcode';
local sql = "select dc_loc_id,dc_loc_ip,dc_loc_port from dc_loc where dc_loc_id='%s'";
local help = CSelectHelp();
if db:select(string.format(sql, sSiteID), '', help) < 0 then
return print('查询站点采集服务连接信息失败'..db:error());
elseif help:size() <= 0 then
return print('站点ID信息不存在');
elseif string.len(help:vs(0, 'dc_loc_ip')) <= 0 then
return print('未配置采集服务连接信息');
end
local iPort = tonumber(help:vs(0, 'dc_loc_port'));
if iPort == nil then
iPort = 9002;
end
local pICE = LuaICE();
pICE:setServer(help:vs(0, 'dc_loc_ip'), iPort);
if pICE:isLogin() == false then
if pICE:login() == false then
return print('采集服务连接失败');
end
end
sql = [[select b.dc_dev_id,b.var_id,b.var_name from dc_dev a,dc_dev_var b where b.var_busi_func_code='%s'
and b.eqpt_id='%s' and a.dc_loc_id='%s' and a.dc_dev_id=b.dc_dev_id]];
local helpVar = CSelectHelp();
if db:select(string.format(sql, sVarFunc, sEqptID, sSiteID), '', helpVar) < 0 then
return print('查询采集信息失败');
elseif help:size() <= 0 then
return print('确认相关采集变量信息');
end
local outIt = CIntent();
local itIn = CIntent();
if pICE:command('dc_get_all', '', outIt) < 0 then
return print('从采集服务读取数据失败');
end
local helpDc = CSelectHelp();
outIt:getHelp('help', helpDc);
helpDc:dump();
itIn:clear();
outIt:clear();
itIn:set('dc_dev_id', helpVar:vs(0, 'dc_dev_id'));
if pICE:command('dc_get_dev', itIn:toString(), outIt) < 0 then
return print('从采集服务读取数据失败');
end
local helpDc = CSelectHelp();
outIt:getHelp('help', helpDc);
helpDc:dump();
itIn:clear();
outIt:clear();
itIn:set('dc_loc_id', sSiteID);
if pICE:command('dc_get_site', itIn:toString(), outIt) < 0 then
return print('从采集服务读取数据失败');
end
local helpDc = CSelectHelp();
outIt:getHelp('help', helpDc);
helpDc:dump();
itIn:clear();
outIt:clear();
itIn:set('var_name', helpVar:vs(0, 'var_name'));
itIn:set('value', '678');
itIn:set('dc_dev_id', helpVar:vs(0, 'dc_dev_id'));
iRet = pICE:command('dc_write', itIn:toString(), outIt);
if iRet < 0 then
return print('写入失败');
end
itIn:clear();
local outmsg = CTNString();
itIn:set('var_name', helpVar:vs(0, 'var_name'));
itIn:set('dc_dev_id', helpVar:vs(0, 'dc_dev_id'));
itIn:set('real_read', '0');
iRet = pICE:commandStr('dc_get', itIn:toString(), outmsg);
if iRet < 0 then
return print('读取失败');
end
print(outmsg:get())
return true;
end
if main() ~= true then
end