53
A.2
Q-Basic example for MICROVIP3 PLUS reading
' EXAMPLE OF MICROVIP3 PLUS READING
'
' INSTRUMENT TYPE : MICROVIP3 PLUS
' PHISICAL ADDRESS : 01
' TRANSMISSION PARAMETERS : 9600 baud, NO par, 1 Stop BIT
DECLARE SUB Pause (n!)
DECLARE SUB SetArrayMeasures ()
DECLARE FUNCTION CheckLrc! (EnergyReply$)
DECLARE SUB ShowData (EnergyReply$)
DECLARE FUNCTION AsciiToFloat! (Data$)
DECLARE FUNCTION AsciiHexToDec! (A$)
DECLARE FUNCTION LRC$ (strng$)
CONST TRUE = -1: CONST FALSE = 0
TYPE Measure
Nome AS STRING * 6
NCh AS INTEGER
OutRow AS INTEGER
OutCol AS INTEGER
END TYPE
DIM SHARED Measures(40) AS Measure '
CR$ = CHR$(13)
LF$ = CHR$(10)
'Name,OutRow,OutCol
DATA V,1,1,A,1,2,W,1,3,PF,2,1,V1,3,1,V2,3,2,V3,3,3,I1,4,1,I2,4,2,I3,4,3
DATA W1,5,1,W2,5,2,W3,5,3,PF1,6,1,PF2,6,2,PF3,6,3
DATA VAr1,7,1,VAr2,7,2,VAr3,7,3
DATA VA1,8,1,VA2,8,2,VA3,8,3,CF1,9,1,CF2,9,2,CF3,9,3
DATA VA,10,1,VAr,10,2,Hz,10,3
DATA kWh,11,1,kVArh,11,2,AvgVAr,12,1,AvgVA,12,2,AvgW,12,3
DATA PeakVA,13,1, PeakW,13,2,kWh1,14,1,kWh2,14,2,kWh3,14,3
SetArrayMeasures
DO
OPEN "COM1: 9600,N,7,1" FOR RANDOM AS #1
' Standard request of 65 words (41H) starting from addr. FE00
' Instrument's address=01 , Reading Command=03
Request$ = "0103FE000041"
Request$ = ":" + Request$ + LRC(Request$) + CR$ + LF$
PRINT #1, Request$
INPUT #1, EnergyReply$
Pause (5) 'pause between two requests
' Read clock
Request$ = "01030DFC0003"
Request$ = ":" + Request$ + LRC(Request$) + CR$ + LF$
PRINT #1, Request$
INPUT #1, Tim$
CLOSE #1
CLS : LOCATE 1, 1
PRINT EnergyReply$
IF CheckLrc(EnergyReply$) THEN
ShowData (EnergyReply$)
END IF
Min$ = MID$(Tim$, 8, 2): HH$ = MID$(Tim$, 10, 2)
DD$ = MID$(Tim$, 12, 2): MM$ = MID$(Tim$, 14, 2)
YY$ = MID$(Tim$, 16, 2)
LOCATE 23, 1: PRINT "Energy Time = "; HH$; ":"; Min$;
PRINT " - "; DD$; "/"; MM$; "/"; YY$
Pause (5)
LOOP WHILE INKEY$ = ""
END
FUNCTION AsciiHexToDec (A$)
'Converts a hexadecimal numbers, written as two ascii char., into a decimal
MSC$ = LEFT$(A$, 1) ' first char
LSC$ = RIGHT$(A$, 1) ' second char
IF MSC$ >= "A" THEN
TEMP = (ASC(MSC$) - ASC("A") + 10) * 16
ELSE
TEMP = VAL(MSC$) * 16
END IF
IF LSC$ >= "A" THEN
TEMP = TEMP + (ASC(LSC$) - ASC("A") + 10)
ELSE
TEMP = TEMP + VAL(LSC$)
END IF
AsciiHexToDec = TEMP
END FUNCTION
FUNCTION AsciiToFloat (Data$)
'Convert a number from the Energy reply's format to a float
Exponent = AsciiHexToDec(RIGHT$(Data$, 2))
IF Exponent > 200 THEN Exponent = Exponent - 256 ' FF=-1, FE=-2 ect...