10 REM Cruising Equipment E-Meter Serial Data Logger 20 REM by Lee A. Hart 5/9/2005 30 REM 35 REM For use with one 3v lithium cell and 50amp 50mv shunt. 36 REM 40 REM Initialize and get setup info. Averages data over 2 sec if 45 REM test duration = 4 minutes, 24 sec if duration = 10 hours, etc. 46 REM 47 ahmax = 6: ahstep = -6: ahmin = ahmax + (10 * ahstep): REM set min/max ah 48 vmin = 2.5: vstep = .2: vmax = vmin + (10 * vstep): REM set min/max volts 49 amin = 0: astep = 4: amax = amin + (10 * astep): REM set min/max amps 50 CLS 55 cflag = 0: REM cflag=1 if charging to 14.4v, =0 if discharging to 10.5v 60 INPUT "Test Description? ", comment$ 70 PRINT : INPUT "Test Duration in hours? ", duration 80 duration = duration * 3600: IF duration < 240 THEN duration = 240 90 average% = 10 100 REM 110 REM If outputting to disk, open file. Data is comma delimited. 120 REM Line 1 is column headings, date, and comment$ string. 130 REM Lines 2-58 are time, averaged volts, amphours, averaged amps. 140 PRINT 145 ON ERROR GOTO 175 150 FILES "*.DAT" 155 INPUT "Output to disk [ENTER for no, or C:\PATH\FILENAME.DAT for yes]? ", filename$ 160 IF LEN(filename$) = 0 GOTO 230 170 OPEN filename$ FOR INPUT AS #2 172 INPUT "That file already exists. Append data to it [y/n]? ", a$ 174 CLOSE #2: IF a$ = "y" OR a$ = "Y" THEN OPEN filename$ FOR APPEND AS #2: GOTO 180 ELSE GOTO 150 175 OPEN filename$ FOR OUTPUT AS #2 180 PRINT #2, ";Time,Volts,AmpHrs,Amps, "; DATE$; ", "; comment$ 190 REM 200 REM If printing, initialize printer for 88 lines per page (8 lpi). 210 REM (If Epson FX-80 or equiv; ESC"0"=8 lpi). 220 REM 230 PRINT : INPUT "Output to printer [ENTER for no, y for yes]? ", print$ 235 IF print$ = "Y" THEN print$ = "y" 240 IF print$ = "y" THEN LPRINT CHR$(27); "0"; DATE$; " "; filename$; " "; comment$: LPRINT 250 REM 260 REM Display (and optionally print) graph headings. 270 CLS 275 LOCATE 25, 40: PRINT "Test in progress: Press any key to abort": LOCATE 1, 1 280 PRINT DATE$; " "; filename$; " "; comment$ 290 GOSUB 1230 300 COLOR 7, 1: PRINT volt$: IF print$ = "y" THEN LPRINT volt$ 310 GOSUB 1330 320 PRINT amphr$: IF print$ = "y" THEN LPRINT amphr$ 330 GOSUB 1430 340 PRINT amp$: IF print$ = "y" THEN LPRINT amp$ 350 REM 360 REM Set up serial port to read E-meter data. 370 REM 380 OPEN "COM2: 9600,n,8,1" FOR INPUT AS #1: LINE INPUT #1, dummy$ 390 REM 400 REM Main loop. Get data from E-meter. 410 REM 420 FOR i = -10 TO duration * .95: REM -10 averages 1st 10 samples for 1st save 430 INPUT #1, time, kwhr, amp, volt, ahr, pahrs, pamps, timerem, bargraph 440 REM 450 REM Compute running averages for volts and amps, or use last value 460 REM for fast changes. Write fast changes to disk if it is enabled. 470 REM 475 amp = amp / 10: ahr = ahr / 10: REM for use with 50amp 50mv shunt 480 wflag = 0 490 IF ABS((volt - volts) / volt) > .05 THEN volts = volt: wflag = 1 ELSE volts = (volts * (127) + volt) / 128 500 IF ABS(amp - amps) > .25 THEN amps = amp: wflag = 1 ELSE amps = (amps * (average% - 1) + amp) / average% 510 amps = FIX(amps * 1000) / 1000 520 IF ABS(ahrs - ahr) > .2 THEN wflag = 1 525 ahrs = ahr 530 REM 540 REM Display current data, and "beep" if it is off the graph. 545 REM Write data to disk if voltage hits upper/lower limits. 550 REM 560 a$ = LEFT$(TIME$, 5) + " v h a | . . . . . . . . . |" 570 MID$(a$, 12 - LEN(LEFT$(STR$(volts + .005), 6))) = LEFT$(STR$(volts + .005), 6) 580 MID$(a$, 19 - LEN(LEFT$(STR$(ahrs), 5))) = LEFT$(STR$(ahrs), 5) 590 MID$(a$, 27 - LEN(LEFT$(STR$(amps), 6))) = LEFT$(STR$(amps), 6) 600 LOCATE CSRLIN, 1: COLOR 7, 1: PRINT LEFT$(a$, 27); 610 IF volt < vmin OR volt > vmax OR ABS(amp) > amax THEN PRINT CHR$(7); 614 IF cflag = 0 AND volt < (vmin + vstep) THEN cflag = 1: wflag = 1 616 IF cflag = 1 AND volt > (vmax - vstep) THEN cflag = 0: wflag = 1 618 IF wflag = 1 AND LEN(filename$) > 0 THEN GOSUB 1140 620 IF LEN(INKEY$) > 0 THEN i = duration 622 REM 624 REM Print and/or save data to disk if 1/80th of duration and they 626 REM are enabled. Display data if 1/20th of duration. 628 REM 630 IF i MOD (duration / 80) > 0 GOTO 860 640 REM 650 REM Initialize a line of graphical data to display or print. 660 REM 29th char in a$ is left limit, 79th is right limit. 670 REM 680 REM Put "h" on graph to represent amphours. 690 REM 700 hpos = 29 + (ahmax - ahrs) * (79 - 29) / (ahmax - ahmin) 710 IF ahrs <= ahmax AND ahrs >= ahmin THEN MID$(a$, hpos, 1) = "h" 720 REM 730 REM Put "v" on graph to represent volts. 740 REM 750 vpos = 29 + (volts - vmin) * (79 - 29) / (vmax - vmin) 760 IF volts >= vmin AND volts <= vmax THEN MID$(a$, vpos, 1) = "v" 770 REM 780 REM Put "a" on graph to represent amps (unsigned). 790 REM 800 apos = 29 + (ABS(amps) - amin) * (79 - 29) / (amax - amin) 810 IF ABS(amps) <= amax THEN MID$(a$, apos, 1) = "a" 820 IF i MOD (duration / 20) = 0 THEN COLOR 7, 0: PRINT RIGHT$(a$, 52); : LOCATE CSRLIN + 1, 1 830 IF print$ = "y" THEN LPRINT a$ 840 IF wflag = 0 AND LEN(filename$) > 0 THEN GOSUB 1140 860 NEXT i 870 REM Finish; close files, restore printer to 80 char/line, 66 lines. 880 REM (If Epson FX-80 or equiv; ESC"P"=10 cpi, ESC"2"=6 lpi, 12=FF). 890 REM 900 CLOSE #1: CLOSE #2 920 IF print$ = "y" THEN LPRINT CHR$(27); "2"; CHR$(12) 999 END 1100 REM 1110 REM Write data to disk file every 1/80th of test duration, or 1120 REM if there is a fast change in volts, amps, or amphours. 1130 REM 1140 PRINT #2, TIME$; ","; 1150 PRINT #2, LEFT$(STR$(volts + .005), 6); ","; 1160 PRINT #2, ahrs; ","; 1170 PRINT #2, LEFT$(STR$(amps), 6): RETURN 1200 REM 1210 REM Make title line to display/print max and min voltage limits 1220 REM 1230 volt$ = " Volts -------------> " 1240 FOR i = 0 TO 10 1250 MID$(volt$, 30 + i * 5 - LEN(STR$(vmin + (vstep * i)))) = STR$(vmin + (vstep * i)) 1260 NEXT 1270 RETURN 1300 REM 1310 REM Make title line to display/print max and min amphour limits 1320 REM 1330 amphr$ = " | AmpHrs ----> " 1340 FOR i = 0 TO 10 1350 MID$(amphr$, 30 + i * 5 - LEN(STR$(ahmax + (ahstep * i)))) = STR$(ahmax + (ahstep * i)) 1360 NEXT 1370 RETURN 1400 REM 1410 REM Make title line to display/print max and min current limits 1420 REM 1430 amp$ = "_Time___v_______v_____Amps_____________________________________________________" 1440 FOR i = 0 TO 10 1450 MID$(amp$, 30 + i * 5 - LEN(STR$(amin + (astep * i)))) = STR$(amin + (astep * i)) 1460 NEXT 1470 RETURN