Site Index - Feedback - Impressum |
| |||||||||
|
|
( Archiv ) | ( Neues Thema ) |
29.04.2005 |
Monitor for APC Back-UPS CS (USB) v 0.01b (10:04:08) | ^ |
/* Monitor for APC Back-UPS CS (USB) v 0.01b */
/* */ /* 29.04.2005 (c) Larin Yury */ /* set intervals */ Interval = 5 ShutDownInterval = 300 /* set minimal battery capacity */ ShutDownBC = 15 /* set ShutDown command */ ShtDwn = 'shutdown o' /* set device driver name */ ddName = 'UPSMON' /* set valid product name */ ProductName = 'Back-UPS' /* ----------------------------------------- */ say 'Monitor for APC Back-UPS CS (USB) v 0.01b' say if RxFuncQuery('SysLoadFuncs') then do call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' call SysLoadFuncs end /* ensure that the device driver statement exists in config.sys */ if stream(ddName,'command','query exists') \= '\DEV\' || ddName then do say 'Missing DEVICE=X:\OS2\BOOT\USBECD.SYS' nParm 'statement in CONFIG.SYS.' exit end oiBuffer = substr(x2c(80 06 00 01 00 00 12 00),1,26,x2c(00)) rc = charout(ddName,oiBuffer) rc = stream(ddName,'description') if rc \= 'READY:' then do parse value rc with sState ':' mNumber say SysGetMessage(mNumber,,ddName) exit end say 'Found on device driver' ddName':' say 'Manufacturer -- 'disp(23) Product = disp(24) say 'Product -- 'Product say 'Serial Number -- 'disp(25) say if substr(Product,1,8) \= ProductName then do say 'Unknown product name. Exiting.' exit end cnt = 1 do forever PS = UPSPowerStatus() select when PS = 1 then do if cnt \= 0 then say date() time() '-- AC utility power source good' cnt = 0 end when PS = 0 then do if cnt = 0 then say date() time() '-- AC utility power source fails!!!' BC = UPSBatteryStatus() say time() 'Battery capacity 'BC'%' cnt = cnt + Interval if (cnt >= ShutDownInterval)|(BC < ShutDownBC) then do ShtDwn exit end end when PS = 255 then say 'Device driver' ddName 'currently in use. Please try later.' otherwise say 'Unknown data from UPS = 'PS end call SysSleep Interval end /* ----------------------------------------- */ UPSPowerStatus: rc=stream(ddName,'command','open') if rc = 'READY:' then do oiBuffer = substr(x2c(a1 01 13 03 00 00 07 00),1,15,x2c(00)) rc=charout(ddName,oiBuffer) rc=stream(ddName,'description') if rc \= 'READY:' then say 'Error!' rc=stream(ddName,'command','close') return c2d(substr(oiBuffer,10,1)) end return 255 UPSBatteryStatus: rc=stream(ddName,'command','open') if rc = 'READY:' then do oiBuffer = substr(x2c(a1 01 0c 03 00 00 07 00),1,15,x2c(00)) rc=charout(ddName,oiBuffer) rc=stream(ddName,'description') if rc \= 'READY:' then say 'Error!' rc=stream(ddName,'command','close') return c2d(substr(oiBuffer,10,1)) end return 255 disp: parse arg Index ixString = substr(oiBuffer,Index,1) if c2d(ixString) = 0 then return 'No String!' siBuffer = substr(x2c(80 06 00 03 00 00 01 00),1,9,x2c(00)) siBuffer = overlay(ixString,siBuffer,3) rc=charout(ddName,siBuffer) rc=stream(ddName,'description') if rc \= 'READY:' then return 'String Error!' szBuffer = substr(siBuffer,9,1) if c2d(szBuffer) = 0 then return 'No String!' siBuffer = overlay(szBuffer,siBuffer,7,c2d(szBuffer)+2,x2c(00)) rc=charout(ddName,siBuffer) rc=stream(ddName,'description') if rc \= 'READY:' then return 'String Error!' szString=c2d(substr(siBuffer,9,1)) + 8 usString = '' /* clear */ do xPos = 11 to szString by 2 usString = usString || substr(siBuffer,xPos,1) end return usString [ Leser: 58 ] |
|
Mit * markierte Felder müssen ausgefüllt werden ! |
( Zeige alle Einträge ) | ( Zur Startübersicht ) |
|
| 58 | 29.04.2005 | 10:04 |
|