'Set up Variables
Let>WDIR=SCRIPT_DIR
'Let>WDIR=C:\test
Let>ErrMsg=Error Unknown
Let>log=%WDIR%\ACGD.log
Let>ACini=%WDIR%\ACGD.ini
Let>LCDini=%WDIR%\ACtank.txt
Del>%log%
GetDate>date
GetTime>time
WriteLn>%log%,result,%date% %Time% ***log file started***
IfFileExists>%ACini%
GetTime>time
WriteLn>%log%,result,%date% %Time% ini file found.
goto>Start
Else
Let>ErrMsg=ini file does not exist
Goto>ErrorOut
Endif
Label>Start
Let>k=0
Let>N=1
ReadIniFile>%ACini%,CONFIG,AC,AC
ReadIniFile>%ACini%,CONFIG,NAME,ID
ReadIniFile>%ACini%,CONFIG,PASS,PS
ReadIniFile>%ACini%,CONFIG,ALARM,AL
ReadIniFile>%ACini%,CONFIG,PX1000,PXN
'Telnet to Aquacontroller
Label>TelnetAC
TelnetConnect>%AC%,8766,hTN
If>HTN=0
If>N=2
GetTime>time
WriteLn>%log%,result,%date% %Time% Unable to attach to AC at IP %AC%
goto>ErrorOut
Else
Let>N=N+1
Wait>5
Goto>TelnetAC
Endif
endif
GetTime>time
WriteLn>%log%,result,%date% %Time% Logging into AC at IP %AC%
TelnetWaitFor>hTN,login:,5,r
TelnetSend>hTN,%ID%%CR%
TelnetWaitFor>hTN,password:,5,r
TelnetSend>hTN,%PS%%CR%
TelnetWaitFor>hTN,AquaController>,5,r
If>r=TIMEOUT
Let>ErrMsg=Username or password not accepted. Aborting.
goto>ErrorOut
Endif
GetTime>time
WriteLn>%log%,result,%date% %time% Successfully logged into AquaController.
GetTime>time
WriteLn>%log%,result,%date% %time% Polling AquaController.
TelnetSend>hTN,c%CR%
TelnetWaitFor>hTN,AquaController>,5,r
GetTime>time
WriteLn>%log%,result,%date% %time% Successfully Polled AquaController.
TelnetClose>hTN
GetTime>time
WriteLn>%log%,result,%date% %time% Successfully terminated connection to Aquacontroller.
//END TELNET TO ac3
Label>CheckIt
//CHECK FILE FOR DATA
GetTime>time
WriteLn>%log%,result,%date% %time% Checking AC data for consistancy.
Length>r,ln
if>ln<50
Let>ErrMsg=Data Failed Consitancy check
Goto>ErrorOut
endif
//END CHECK
//START GET STATS
Let>lx=7
GetTime>time
WriteLn>%log%,result,%date% %time% Parsing data
Separate>r,CR,Lines
Let>ln=Lines_%lx%
Separate>ln, ,vl
Let>T=vl_1
Let>H=vl_2
Let>O=vl_3
Length>vl_5,ln
if>ln<2
Let>C=--.-
else
Let>C=vl_5
endif
//END GET STATS
//GET PX1000 DATA
If>PXN>0
goto>FPX1000
else
goto>FALRM
endif
Label>FPX1000
Let>PXNUM=1
Label>FindV
Let>lx=lx+2
Separate>r,CR,Lines
Let>ln=Lines_%lx%
Separate>ln, ,vl
Let>vllast=vl_Count-1
Let>vln=1
Label>BreakOut1
Length>vl_%vln%,ln
if>ln<2
If>vln=1
GetTime>time
WriteLn>%log%,result,%date% %time% PX1000 value set wrong, please lower.
goto>FALRM
EndIf
Let>S=---
EditIniFile>%LCDIni%,PX1000,PX%PXNUM%_%vln%,%S%
else
Let>S=vl_%vln%
EditIniFile>%LCDIni%,PX1000,PX%PXNUM%_%vln%,%S%
endif
If>vln=vllast
If>PXNUM=PXN
goto>FALRM
else
Let>PXNUM=PXNUM+1
goto>FindV
Endif
Else
Let>vln=vln+1
goto>BreakOut1
EndIf
//END GET PX1000 DATA
//FIND ALARM VALUE
Label>FALRM
Position>%AL%,%r%,1,x
Let>X=X+7
MidStr>%r%,%X%,2,S
If>S=ON
Let>S=ALARM
EndIf
If>S=OF
Let>S=NORMAL
EndIf
//END FIND ALARM VALUE
GetTime>time
WriteLn>%log%,result,%date% %time% Finished Parsing data. Writing results.
//WRITE RESULTS
EditIniFile>%LCDIni%,READINGS,STAT,%S%
EditIniFile>%LCDIni%,READINGS,TEMP,%T%
EditIniFile>%LCDIni%,READINGS,PH,%H%
EditIniFile>%LCDIni%,READINGS,ORP,%O%
EditIniFile>%LCDIni%,READINGS,COND,%C%
//END WRITE RESULTS
Goto>Fin
Label>ErrorOut
WriteLn>%log%,result,%date% %Time% %ErrMsg%.
//WRITE RESULTS
EditIniFile>%LCDIni%,READINGS,STAT,OFFLINE
EditIniFile>%LCDIni%,READINGS,TEMP,-.--
EditIniFile>%LCDIni%,READINGS,PH,-.-
EditIniFile>%LCDIni%,READINGS,ORP,-.-
//END WRITE RESULTS
Label>Fin
GetTime>time
WriteLn>%log%,result,%date% %time% ***Log file closed***