' *************************************************************
' ** Description: Visual Basic example building one graph
' ** with the Real-Time Graphics Tools for Windows
' *************************************************************
' FEATURES OF THIS DEMO
'
' Scroll Graphs - horizontal, Dynamic Grids
' Dynamic Data sets, Timers, Alarms
Option Explicit
Const NT = 3
Dim hScroll As Integer ' handle to scrolling graph object
Dim hData As Integer ' handle to dynamic data set
Dim nCount As Integer ' update counter
Dim pPageDesc1 As Long ' Page descriptor
Dim pDynGrDesc As Long ' Graph descriptors
' ******************************************************
' ** Builds the graph using Q-C Real-Time Graphics Calls
' ******************************************************
Sub DrawP1G1 (pGrDesc As Long, hdc As Integer)
Dim hAxisX, hAxisY As Integer ' axis handles
Static bFlags(NALMLINES) As Integer
Dim nTraces As Integer, nErr As Integer
Static nLineColor(NT) As Integer
Static nLineWidth(NT) As Integer
Static nLineStyle(NT) As Integer
Dim i As Integer, nGridUpdate As Integer
Dim rSampleInt As Double, rResetInt As Double
Dim rHigh As Double, rLow As Double, rSetp As Double
Dim nText As Integer, hObj As Integer
Static nAlmLineStyle(NALMLINES) As Integer
Static nAlmLineWidth(NALMLINES) As Integer
Static nAlmLineColor(NALMLINES) As Integer
nTraces = 3
nGridUpdate = 4
Call WGSetPlotArea(pGrDesc, hdc, .24, .15, .95, .57, C_BLACK)
' scale the plotting area for an x range of 0 to 1.0
' and y range of -3.0 to 3.0
Call WGScalePlotArea(pGrDesc, 0#, -3#, 1#, 3#)
' set the intercepts to 0.0, -3.0
Call WGSetXYIntercepts(pGrDesc, 0#, -3#)
' axes to be drawn in solid, black, 1 pixels thick
Call WGSetLineStyle(pGrDesc, hdc, PS_SOLID, 1, C_CYAN)
' set current font to Arial, 7 points
nText = WGSetTextByName(C_RED, "Arial", 8, 0)
' draw x axis - major ticks every 0.2 physical units, no minor ticks
hAxisX = WGDrawXAxis(pGrDesc, hdc, .2, 0, POS_MIDDLE)
' draw y axis - major ticks every physical unit, and 1 minor tick
hAxisY = WGDrawYAxis(pGrDesc, hdc, 1#, 1, POS_LEFT)
' Label the x axis, in dec. format, 1 digit after the decimal point.
hObj = WGLabelAxis(pGrDesc, hdc, hAxisX, POS_BELOW, NF_DECIMAL, 1,
LL_ON, "")
nText = WGSetTextByName(C_RED, "Arial", 8, TEXT_ITAL)'
' Label the y axis, in dec. format, 1 digit after the decimal point.
hObj = WGLabelAxis(pGrDesc, hdc, hAxisY, POS_LEFT, NF_DECIMAL, 1,
LL_ON, "")
' Set the line style for the dynamic grids
Call WGSetLineStyle(pGrDesc, hdc, PS_DOT, 1, C_LIGHTCYAN)
' set current font to Arial, 8 points
nText = WGSetTextByName(C_RED, "Arial", 8, TEXT_BOLD)
' Write axes titles
hObj = WGTitleAxis(pGrDesc, hdc, hAxisX, POS_BELOW, "Minutes")
hObj = WGTextNorm(pGrDesc, hdc, "Volts", .1, .35, TA_CENTER Or
TA_BOTTOM, TEXT_VERTLEFT)
' set current font to Arial, 10 points, bold, italic
nText = WGSetTextByName(C_GREEn, "Arial", 10, TEXT_BOLD Or TEXT_ITAL)
' Write graph title
hObj = WGTitleGraph(pGrDesc, hdc, "Horizontal Strip Chart")
' ****************************************************
' SET UP DYNAMIC PORTION OF GRAPH
' Display a dynamic grid at the major tick interval for both
' x and y axes, updating the grid every 4 seconds.
hObj = WRDynGrid(pGrDesc, hAxisX, GRID_MAJOR, nGridUpdate)
hObj = WRDynGrid(pGrDesc, hAxisY, GRID_MAJOR, nGridUpdate)
'Assign each line width and color for the scroll graph
For i = 0 To nTraces - 1
nLineWidth(i) = 2
nLineStyle(i) = PS_SOLID
Next i
nLineColor(0) = C_LIGHTRED
nLineColor(1) = C_WHITE
nLineColor(2) = C_LIGHTGREEN
rSampleInt = .02
rResetInt = .95
' Define dynamic data set - units, no tags, history buffer size = 200
hData = WRDefineDynDataSet("Scroll 1", nTraces, "volts", "", 200)
' create scrolling lines - horizontal, style = linear interp
hScroll = WRSetScrollGraph(pGrDesc, hData, rSampleInt, rResetInt,
OR_HORZ, NO_STEP, nLineStyle(0), nLineWidth(0), nLineColor(0))
' set the flags for the alarm lines
bFlags(0) = True
bFlags(1) = True
bFlags(2) = True
bFlags(3) = False
bFlags(4) = False
For i = 0 To NALMLINES - 1
nAlmLineStyle(i) = PS_SOLID
nAlmLineWidth(i) = 2
Next i
' Assign colors for alarm lines
nAlmLineColor(0) = C_YELLOW
nAlmLineColor(1) = C_RED
nAlmLineColor(2) = C_BLUE
rHigh = .95 ' High
rLow = -1.4 ' Low
rSetp = .25 ' Setpoint
' Assign setpoint, low and high alarm values
nErr = WRSetSetpoint(hData, rSetp)
nErr = WRSetAlarm(hData, ALM_LOW, rLow, "LOW")
nErr = WRSetAlarm(hData, ALM_HIGH, rHigh, "HIGH")
' Draw alarm lines - alarm line updated every 2 seconds,
' lines are horizontal, line style - PS_SOLID
hObj = WRSetAlarmLines(pGrDesc, hData, 2, OR_HORZ, bFlags(0),
nAlmLineStyle(0), nAlmLineWidth(0), nAlmLineColor(0))
End Sub
' ******************************************************
' ** Page window is created when form is loaded
' ******************************************************
Sub Form_Load ()
Timer1.Interval = 250
nCount = 0
' page is created in current window as a child of the main window
pPageDesc1 = WGCreatePage("PAGE1", ScrollG1Form.hWnd, "Simulator",
"", C_LIGHTGRAY, MM_ISOTR, 0, PAGE_FULL, 0, 0, 0, 0, TopDesc)
If (pPageDesc1 <> 0) Then
Call StartGraphs1(pPageDesc1)
Call WGUpdatePage(pPageDesc1)
End If
End Sub
Sub Form_Unload (Cancel As Integer)
Call WRCleanup(TopDesc)
End
End Sub
' ******************************************************
' ** Calls WGCreateGraph to initialize graph
' ******************************************************
Sub StartGraphs1 (pPageDesc As Long)
Dim hdc As Integer
' first graph: light gray bg, white border, border width = 1
pDynGrDesc = WGCreateGraph(pPageDesc, .005, .005, .49, .8,
C_LIGHTGRAY, C_WHITE, 1, TopDesc, hdc)
' Call graph building procedure
Call DrawP1G1(pDynGrDesc, hdc)
End Sub
' ******************************************************
' ** Data is updated by a Timer Control
' ******************************************************
Sub Timer1_Timer ()
Dim rArg As Double
Static rNewVals(3) As Double
' Initialize the DLL every time the timer is called!
' Otherwise the DLL will not know who is calling it.
' Necessary only if multiple RT Tools applications or multiple
' instances of the same application can run simultaneously.
Call WGStart(TopDesc)
If WGIsDescValid(pDynGrDesc) Then
rArg = M_PI * nCount
' simulate data
rNewVals(0) = Sin(rArg / (1020# - nCount))
rNewVals(1) = Sin(rArg / 52#) * Rnd * 1.4
rNewVals(2) = Cos(rArg / 60#) * Rnd * .5
nCount = nCount + 1
If (nCount > 1000) Then
nCount = 0
End If
' Update the data set
Call WRUpdateData(hData, rNewVals(0), 0)
End If
End Sub