设备状态
设备状态获取配置
修改配置文件tn_tsdb.ini:
[common]
enable_sync_eqpt_state=1 --同步设备状态,andriod服务不需要开启
[run_lua]
tn_tsdb_sync_eqpt_state_his=8,1 --同步设备状态到历史库
设备状态获取
CommandParent获取设备变量数据
--查询当前关联的所有采集数据
local bRet = false;
local sErrorInfo = '';
local sData = CTNString();
local sError = CTNString();
--获取此设备关联的其它参数
commandParent('plugin.dc_server.dc_get', sEqptID, sData, sError);
local helpTech = CSelectHelp();
helpTech:fromString(sData:get());
if helpTech:size()<= 0 then
return;
end
CommandStr获取设备变量数据
--获取设备工艺参数
sOk = db:commandStr('plugin.dc_server.get_eqpt',m_sEqptId, sOut);
itOut:fromString(sOut:get());
--print(sOut:get());
if sOk<0 then
print('获取实时加工数和设备状态失败!');
m_sCurEqptStatePic = m_sEqptStatePic['unknow'];
return;
End
Sqllite获取设备状态
--服务器端查询工艺数据(设备状态,参数), 采集数据要上报,服务端配置文件插件dc-server要启动
function process()
--查询设备的状态help
local helpEqptState = CSelectHelp();
local cc = CTNString();
commandReal('plugin.dc_server.select_sqlite', 'select eqpt_id,eqpt_cur_state,update_time from dc_real_eqpt_state', cc);
helpEqptState:reset();
helpEqptState:fromString(cc:get());
outIt:setHelp('help',helpEqptState)
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
--读取采集服务中的所有变量数据
if pICE:command('dc_get_all', '', outIt) < 0 then
return print('从采集服务读取数据失败');
end
local helpDc = CSelectHelp();
outIt:getHelp('help', helpDc);
helpDc:dump();
读取指定dec_id下所有变量数据
--读取指定dc_dev_id下所有变量数据
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();
读取指定站点下所有变量数据
--读取指定站点dc_loc_id下所有变量数据
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();
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');--0为读取采集服务内存中的数据,1为直接读取PLC采集设备的数据,数据准确性时效性更好
iRet = pICE:commandStr('dc_get', itIn:toString(), outmsg);
if iRet < 0 then
return print('读取失败');
end
print(outmsg:get())
单变量写入设备
--单变量写入到采集设备
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
按采集变量编号(var_ids)进行查询采集信息(客户端)
local it = CIntent();
it:set('dc_loc_id','1067');
it:set('var_ids','2589,2590');local sOut = CTNString();
db:commandStr('dc_get_redis',it:toString(),sOut);
local help = CSelectHelp();
help:fromString(sOut:get());
按站点编号(dc_loc_id)查询采集变量信息(客户端)
local it = CIntent();
it:set('dc_loc_id','1067');local sOut = CTNString();
db:commandStr('dc_get_by_dc_loc_id_redis',it:toString(),sOut);
local help = CSelectHelp();
help:fromString(sOut:get());
help:dump();
查询该采集站点下采集变量信息(服务端)
local help = CSelectHelp();
serv:dc_get_redis('1067','2589,2590',help);
outIt:setHelp('help',help);
实时查询设备状态(服务端)
local help = CSelectHelp();
tnsys:dc_get_eqpt_state('1224',help);
outIt:setHelp('help',help);
实时查询设备加工数(服务端)
local ivalue = tnsys:dc_get_eqpt_danum('1223');print('i value = ' .. ivalue);
实时查询设备状态(支持多个使用“,”隔开)(服务端)
local help = CSelectHelp();
tnsys:dc_get_eqpt_state('1223,1224',help);
help:dump();