Home > Scrapbook > Uni-T UT70B Multimeter MS-DOS Software

Uni-T UT70B Multimeter MS-DOS Software

Interface your UT70B multimeter with your computer running MS-DOS
By 26/10/10 [Last Edited by Joseph 13/04/11]
BOOKMARK
LOGIN
REGISTER
This video is about the QuickBasic software I wrote to read from the UT70B multimeter. Please forgive me for the dull, monotonous tone, and the length. However, to make up for the dire video, I've posted the source code underneath, which you can compile using QuickBasic 4.5. Please note, you can only run the program from under Real-Mode MS-DOS, i.e. not in Windows.



DECLARE SUB ShowHelp ()
DECLARE SUB AddList (Reading$)
DECLARE FUNCTION GetValue (Data1$, NegPos$)
DECLARE FUNCTION GetMode$ (Data2$, Sign$, NegPos$)
DECLARE FUNCTION GetData$ ()
DECLARE SUB DrawScreen (Selection)
DECLARE SUB ConnectCom (Operation)
DIM SHARED ListBuffer(17) AS STRING
DIM SHARED ListTimeBuffer(17) AS STRING
DIM SHARED ListNoBuffer(17) AS INTEGER
CONST ProgramVersion$ = "Alpha1"
CONST BlankBar$ = "                                                                                "
IF COMMAND$ = "/?" THEN ShowHelp
'
' UNI-T UT70B Multimeter Interface Software for DOS
' Version 1.0
' (C)2008 Joseph Newman
' http://www.josephn.net/ut70b?r=sc-alpha
'
' Compile with Microsoft QuickBasic 4.5 or compatible
' Will not run under Windows NT correctly
'
CLS
DrawScreen (1)
LOCATE 4, 1: INPUT "Enter the filename to dump (CSV) values to: ", FileDump$
CLS : DrawScreen (1): DrawScreen (2)
OPEN FileDump$ FOR OUTPUT AS #2
PRINT #2, "Reading No,Reading,Time"
ConnectCom (1)  'Open COM1
LOCATE 4, 1: PRINT "Waiting for Data..."
LOCATE 5, (69 - LEN(FileDump$)): PRINT "Dumping to " + FileDump$
LocVar = 1
DO
        Count = Count + 1
        IF Count = 5000 THEN Count = 0
        IF Count = 1000 THEN LocVar = LocVar + 1
        IF LocVar = 57 THEN LocVar = 1
        IF Count = 2000 THEN LOCATE 2, 1: COLOR 7, 5: PRINT BlankBar$: LOCATE 2, LocVar: PRINT "ALPHA EXPERIMENTAL BUILD!"
        COLOR 7, 0
        DataCollect$ = GetData$
        IF LEN(DataCollect$) THEN
                LOCATE 4, 1: PRINT "                                                 "
                LOCATE 4, 1: PRINT STR$(GetValue(DataCollect$, NegPos$)) + Sign$ + "    " + GetMode(DataCollect$, Sign$, NegPos$)
                AddList (STR$(GetValue(DataCollect$, NegPos$)) + Sign$)
        END IF

LOOP UNTIL INKEY$ = CHR$(27)

ConnectCom (0)  'Close COM1
CLOSE #2

SUB AddList (Reading$)
'Implements a simple scrolling 17 row table of values. Also dumps readings to file handle #2

        IF ListBuffer(17) <> Reading$ THEN
                FOR LoopCounter = 1 TO 17
                        ListBuffer(LoopCounter - 1) = ListBuffer(LoopCounter)
                        ListTimeBuffer(LoopCounter - 1) = ListTimeBuffer(LoopCounter)
                        ListNoBuffer(LoopCounter - 1) = ListNoBuffer(LoopCounter)
                NEXT
                ListBuffer(17) = Reading$
                ListTimeBuffer(17) = TIME$
                ListNoBuffer(17) = ListNoBuffer(16) + 1
                PRINT #2, STR$(ListNoBuffer(17)) + "," + ListBuffer(17) + "," + ListTimeBuffer(17)
                FOR LoopCounter = 1 TO 17
                        LOCATE (LoopCounter + 6), 1: PRINT "                                             "
                        IF ListNoBuffer(LoopCounter) <> 0 THEN LOCATE (LoopCounter + 6), 1: PRINT ListNoBuffer(LoopCounter)
                        LOCATE (LoopCounter + 6), 15: PRINT ListBuffer(LoopCounter)
                        LOCATE (LoopCounter + 6), 30: PRINT ListTimeBuffer(LoopCounter)
                NEXT
        END IF
END SUB

SUB ConnectCom (Operation)
'Sub contains connection and disconnection routines

        SELECT CASE Operation
                CASE IS = 1
                        OPEN "COM1:2400,O,7,1,ASC" FOR INPUT AS #1
                        OUT &H3FC, 9    'Raise COM1 DTR line via direct hardware call
                        LOCATE 4, 66: PRINT "COM1 Connected"
                CASE IS = 0
                        CLOSE #1
        END SELECT
END SUB

SUB DrawScreen (Selection)
'Draws layout

        SELECT CASE Selection
        CASE 1
                
                LOCATE 1, 1: COLOR 7, 4: PRINT BlankBar$
                LOCATE 1, 22: PRINT "UNI-T UT70B Multimeter Interface Program"
                LOCATE 2, 1: COLOR 7, 5: PRINT BlankBar$
                LOCATE 22, 59: COLOR 1, 0: PRINT "(C)2008 Joseph Newman"
                LOCATE 23, (72 - LEN(ProgramVersion$)): COLOR 4, 0: PRINT "Version " + ProgramVersion$
               
        CASE 2
                LOCATE 6, 1: COLOR 4, 0: PRINT "Reading No"
                LOCATE 6, 15: PRINT "Reading"
                LOCATE 6, 30: PRINT "Time"
                LOCATE 21, 65: COLOR 3, 0: PRINT "Hit ESC to exit"

        END SELECT
        COLOR 7, 0
END SUB

FUNCTION GetData$
'Function that looks in port buffer for new data, removes the duplicate
'data sent, and returns it

        STATIC LastDataString$
        STATIC DataString$
        IF LOC(1) THEN DataIn$ = INPUT$(1, 1)   'If there is new data, get it
        IF LEN(DataIn$) AND DataIn$ <> CHR$(10) AND DataIn$ <> CHR$(13) THEN
                DataString$ = DataString$ + DataIn$
                DataIn$ = ""
        ELSEIF LEN(DataIn$) AND DataIn$ = CHR$(13) THEN
                IF LastDataString$ <> DataString$ THEN GetData = DataString$
                LastDataString$ = DataString$
                DataIn$ = ""
                DataString$ = ""
        END IF
END FUNCTION

FUNCTION GetMode$ (Data$, Sign$, NegPos$)
'Function which returns the multimeter mode from a data-string input. Also
'the sign (e.g mV) and the Polarity is passed ByRef.

        Data2$ = Data$
        Data2$ = RIGHT$(Data2$, 4)
        DpData$ = LEFT$(Data$, 1)
        NegPos$ = ""
        SELECT CASE Data2$
                CASE "4800"
                        GetMode = "Degrees Celcius"
                        Sign$ = "C"
                CASE "4000"
                        GetMode = "Degrees Farenheit"
                        Sign$ = "F"
                CASE "5100"
                        GetMode = "Continuity OL"
                        Sign$ = "Ohms"
                CASE "5000"
                        GetMode = "Continuity"
                        Sign$ = "Ohms"
                CASE ";00:"
                        GetMode = "Positive Voltage"
                        IF DpData$ = "0" THEN Sign$ = "mV" ELSE Sign$ = "V"
                CASE ";008"
                        GetMode = "Positive Voltage (Manual)"
                        IF DpData$ = "0" THEN Sign$ = "mV" ELSE Sign$ = "V"
                CASE ";40:"
                        GetMode = "Negative Voltage"
                        IF DpData$ = "0" THEN Sign$ = "mV" ELSE Sign$ = "V"
                        NegPos$ = "-"
                CASE ";408"
                        GetMode = "Negative Voltage (Manual)"
                        IF DpData$ = "0" THEN Sign$ = "mV" ELSE Sign$ = "V"
                        NegPos$ = "-"
                CASE ";108"
                        GetMode = "Positive Voltage OL"
                        IF DpData$ = "0" THEN Sign$ = "mV" ELSE Sign$ = "V"
                CASE ";508"
                        GetMode = "Negative Voltage OL"
                        IF DpData$ = "0" THEN Sign$ = "mV" ELSE Sign$ = "V"
                        NegPos$ = "-"
                CASE "2002"
                        GetMode = "Frequency"
                        Sign$ = "Hz"
                CASE "2802"
                        GetMode = "Speed RPM"
                        Sign$ = "RPM"
                CASE "6102"
                        GetMode = "Capacitance OL"
                        Sign$ = "F"
                CASE "6002"
                        GetMode = "Capacitance nF"
                        Sign$ = "nF"
                CASE "1100"
                        GetMode = "Diode OL"
                CASE "?008"
                        GetMode = "DC A"
                        Sign$ = "A"
                CASE "?004"
                        GetMode = "AC A"
                        Sign$ = "A"
                CASE "900:"
                        GetMode = "DC mA"
                        Sign$ = "mA"
                CASE "9006"
                        GetMode = "AC mA"
                        Sign$ = "mA"
                CASE "=00:"
                        GetMode = "DC uA"
                        Sign$ = "uA"
                CASE "=006"
                        GetMode = "AC uA"
                        Sign$ = "uA"
                CASE "1000"
                        GetMode = "Diode"
                CASE "3102"
                        GetMode = "Resistance OL"
                        Sign$ = "Ohms"
                CASE "3002"
                        GetMode = "Resistance"
                        Sign$ = "Ohms"
                CASE ELSE
                        GetMode = "UNKNOWN " + Data2$
        END SELECT

END FUNCTION

FUNCTION GetValue (Data$, NegPos$)
'Strips off last 4 characters and determines the place of the decimal point

        Data1$ = Data$
        Data1$ = MID$(Data1$, 2, 4)
        DpData$ = LEFT$(Data$, 1)
        SELECT CASE DpData$
                CASE "0"
                        Data1$ = LEFT$(Data1$, 3) + "." + RIGHT$(Data1$, 1)
                CASE "1"
                        Data1$ = LEFT$(Data1$, 1) + "." + RIGHT$(Data1$, 3)
                CASE "2"
                        Data1$ = LEFT$(Data1$, 2) + "." + RIGHT$(Data1$, 2)
                CASE "3"
                        Data1$ = LEFT$(Data1$, 3) + "." + RIGHT$(Data1$, 1)
        END SELECT
        GetValue = VAL(NegPos$ + Data1$)
        
END FUNCTION

SUB ShowHelp
        PRINT "UNI-T UT70B Multimeter Interface Program " + ProgramVersion$
        PRINT "(C)2008 Joseph Newman, http://www.josephn.net"
        PRINT ""
        PRINT "When executing this program, you will be prompted for an output file. All values"
        PRINT "that are captured are dumped to this file in Comma Seperated Values (CSV) format"
        PRINT ""
        PRINT "Please note: This program will only run correctly under Real-Mode DOS, or"
        PRINT "Windows 9x. This is because direct hardware access calls are made, which are "
        PRINT "forbidden under Windows NT's Virtual DOS Machine (NTVDM)."
        PRINT ""
        END
END SUB