main() { int SERVER_ROLE = 4; dyn_string names; string skw_name=""; long t_current=0, t_dp=0, dif=0; time t1, t2; while(1){ names = dpNames("Settings.Connection.SKW.*"); for(int i=1;i<=dynlen(names);i++){ skw_name = names[i]; strreplace(skw_name, "System1:Settings.Connection.SKW.", ""); t1 =getCurrentTime(); dpGet(skw_name + ".conn_state:_original.._stime", t2); t_current = period(t1); t_dp = period(t2); dif = t_current - t_dp; // if(dif > 150) if(dif > 20) { startThread("connect_wells_agp1", skw_name, SERVER_ROLE); } } } } void connect_wells_agp1(string skw_name, int SERVER_ROLE) { string hexWell; int open, write,close; blob datablob = "", IP_sum = "00000000", reg_server; // zaebok string SCADA_IP = "", SKW_IP = ""; dyn_string IP; dpGet("System1:Settings.Connection.SKW." + skw_name + ":_original.._value", SKW_IP); open=tcpOpen(SKW_IP, 502); dpGet("System1:Settings.Connection.SCADA.SERVER1:_original.._value", SCADA_IP); IP=strsplit(SCADA_IP, "."); blobSetValue(IP_sum ,0 ,(int)IP[1] ,1 ,1); blobSetValue(IP_sum ,1 ,(int)IP[2] ,1 ,1); blobSetValue(IP_sum ,2 ,(int)IP[3] ,1 ,1); blobSetValue(IP_sum ,3 ,(int)IP[4] ,1 ,1); switch(SERVER_ROLE){ case 4: { hexWell = strltrim(skw_name, "W"); if((int)hexWell==119) { reg_server = "08AC"; } } } datablob="0101000000190110000800100010000000000000"; write = tcpWrite(open, datablob); time Vremya; Vremya = getCurrentTime(); DebugN("connect to ", skw_name, SKW_IP, write, Vremya); close = tcpClose(open); //DebugN("connect to ", skw_name, SKW_IP, Vremya); dpSet(skw_name + ".conn_state:_original.._value", FALSE); }