| | Displaying of analogous values
Task
Displaying of analogous values of EX/EY outputs of the fischertechnik
interfaces. Can be used with temperature control of
the starter pack (e.g.).
Asking for the values is easy : ft.Analogs(ftiAEX) (FishFa50.OCX) or
ftiGetAnalog(0) (umFishEx respectively. But how to show them with an analogous
instrument?
Case 1 : Take a picture and look vor a needle. Mostly that will work, but what
about variable size, varying printout. That lead to case 2 : draw it yourself,
this case is discussed here. The sources for the project are in the package AnaInstr.ZIP.
in addition you need FishFa50.ZIP or umFish.ZIP
(if using umFishEx).
The Draw Sub : ShowDisplay
Private Sub ShowDisplay(ByVal aWert As Single)
' --- Zeichnen eines Analoginstrumentes und
' Eintrag des aktuellen Meßwertes
Const kStrich = 5, lStrich = 8, anzStriche = 21 Const sWinkel = 1.05, iRadius = 75
Const zRadius = 40, zStrich = 48,
Const zBereich = 1000, zTeilung = 250
Dim dWinkel!, aWinkel!, sWert&, dText$
Dim a!, b!, c!, x!, y!, x1!, y1!, x2!, y2!, w!
Dim i&
picAnalog.Cls
picAnalog.Scale (-50, 100)-(50, 20)
' ---------- Minor Ticks ----------------------
aWinkel = sWinkel
dWinkel = sWinkel / (anzStriche - 1)
For i = 1 To anzStriche
x1 = Cos(aWinkel) * iRadius
y1 = Sin(aWinkel) * iRadius
x2 = x1 + Cos(aWinkel) * kStrich
y2 = y1 + Sin(aWinkel) * kStrich
picAnalog.Line (x1, y1)-(x2, y2)
aWinkel = aWinkel + dWinkel
Next i
' ------------ Major Ticks -----------------
aWinkel = sWinkel
sWert = zBereich
dWinkel = sWinkel / ((anzStriche - 1) / 5)
For i = 1 To (anzStriche - 1) / 5 + 1
x1 = Cos(aWinkel) * iRadius
y1 = Sin(aWinkel) * iRadius
x2 = x1 + Cos(aWinkel) * lStrich
y2 = y1 + Sin(aWinkel) * lStrich
picAnalog.Line (x1, y1)-(x2, y2)
picAnalog.CurrentX = x2 - 5
picAnalog.CurrentY = y2 + 10
picAnalog.Print sWert
aWinkel = aWinkel + dWinkel
sWert = sWert - zTeilung
Next i
' -------------- Analog Wert ------------------
aWinkel = sWinkel + ((zBereich - aWert) / zBereich) * sWinkel
x1 = Cos(aWinkel) * zRadius
y1 = Sin(aWinkel) * zRadius
x2 = x1 + Cos(aWinkel) * zStrich
y2 = y1 + Sin(aWinkel) * zStrich
' -------------- Digital Wert ------------------
picAnalog.Line (x1, y1)-(x2, y2), QBColor(12)
lblText.Caption = "AnalogWert : " & aWert
lblText.Left = 0 - lblText.Width / 2
lblText.Top = 32
End Sub
For the first view : no fischertechnik but a lot of school with Sin/Cos. But
it is easier as it seems.
- In the first part Constants are defined, used in the draw part later on.
Reason : Constanst can be changed more easy than values on different
locations and they describe there content.
KStrich/lStrich : length of the short/long scale lines
anzStrich : number of scale lines
sWinkel : scale angle in radiant (the scale is part of a circle)
iRadius : inner radius of the scale
zRadius : inner radius of the needle
zStrich : length of the needle
zBereich : display area (max value, start with 0)
zTeilung : value for the major ticks
dWinkel : delta angle (step from scale line to scale line)
aWinkel : beginning angle ( !! all angles in radiant : Pi = 180°)
sWert : act. scale value
dText : act. scale value as string
- picAnalog.Cls
the device consists out of an (empty) PictureBox (and lblText). Within the
PictureBox the actual device is drawed (with each new value).
- picAnalog.Scale
Defining the scale of the PictureBox. The drawing area is 100 x 100 units,
the lower 20 in y direction are cut. The values for x are from -50 to +50,
the y values are +20 to +100. The values of the constant refer to this scale
units. The real size of the PictureBox is meaningless.
- Minor Ticks
First the minor ticks are drawn - from right to left (sin/cos values are to
handle easier in this case) one by one. From the inner side to the outer.
The coodinates for the inner point (x1/y1) are counted first and then the
outer by adding there length part. Cos(aWinkel)*iRadius computes the x value
of the inner point ( base is the point 0,0, just beyond the PictureBox).
-
Major Ticks
Nearly the same, but a little bit longer. Each 5. scale line is drawn again.
And its value is printed. The coodinates for the Print are set by
CurrentX/CurrentY.
- Analog Wert
Dawing the needle on the actual position. Therefore the analogous value
(aWert) is transformed in an angle (radiant) as percentage of the zBereich.
The needle is drawn like the scale lines but in red.
- Digital Wert
To make it more exact, the aWert is converted to a numeric value and shown
in the Label lblText. lblText will be positioned centered.
That was the bigger part. Looking for the analogous value to be displayed is
easy, do it in a loop ending with ESC-Key :
The Display Loop cmdAction
Private Sub cmdAction_Click()
' --------- Anzeige Meßwert von EX ------------
' Abbruch : ESC-Taste oder E1 = True
ft.AnalogScan = True
ft.OpenInterface "COM1"
cmdEnde.Enabled = False
cmdAction.Enabled = False
Do
ShowDisplay ft.Analogs(ftiAEY)
Loop Until ft.Finish(1)
ft.CloseInterface
ShowDisplay 0
cmdAction.Enabled = True
cmdEnde.Enabled = True
cmdEnde.SetFocus
End Sub
The code above shows the version with FishFa50.OCX, the ZIP file also
contains an umFish version (nearly the same change ft. to fti, drop
ft.AnalogScan). Most of the code is for locking the button while the display
loop is running. End with ESC-Key or E1 switch.
Possible Extensions
Possibly urgent :
picAnalog as parameter of ShowDisplay (ByVal picanalog As PictureBox) to show
both EX and EY. In that case two PictureBoxed are placed on the form.
May by difficult :
Display the values given from the interface (0 - 1024) in a free choosable
range. e.g. 0 - 100° C (what is that in Fahrenheit). Therefore some
calculations must be done.
A take for specialists :
converting it to an OCX control (look AnaOCX, Visual
Basic solution mapping of raw values included .... )
|