Announcement

Collapse
No announcement yet.

Very Slow Execution

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wesley Brown
    replied
    Thanks John, Phil, Chris, and Florent . All of your ideas have given me new insight as to many
    ways that I can improve performance. I will be spending the next day or two implimenting them
    and will be back in touch to let you know how things turned out.

    I sincerely appreciate your help . . .

    Wesley

    ------------------

    Leave a comment:


  • Florent Heyworth
    replied
    Hi Wesley

    You need to identify in which functions/subs your program spends
    the most time - that means writing benchmark code and logging it
    to file using GetTickCount() or some other timer method.

    Your problem could be a feedback loop as pointed out by John or
    it could be comm access (dud driver, timing conflict, something
    else...).

    Good luck

    Florent

    ------------------

    Leave a comment:


  • John Kovacich
    replied
    I noticed that in MainProgram, if update=1, presumably because you
    selected a pump or an octane, and if the pump is disabled (is that possible?)
    it sets the check box to off, this then triggers another callback which
    sets the update to 1, etc.

    Is it possible, that scenarios like this could be causing a feedback
    loop in your callbacks?

    Normally I would expect such a loop to lead to resource issues and
    a CRASH, but since you have your threads running at priority, you might
    be fending off any crash.


    ------------------
    Thanks,

    John Kovacich

    Leave a comment:


  • Phil Tippit
    replied
    Wesley,

    Try these changes to update the pump display.
    It made a remarkable change when I tested it.
    Code:
    'under globals
    
    GLOBAL AmtD()       AS INTEGER
    GLOBAL VolD()       AS INTEGER
    GLOBAL moneyamt     AS STRING
    GLOBAL volumnamt    AS STRING
    
    ' in pbmain dim
    DIM  AmtD(1,7)
    DIM  VolD(1,7)
    
    
    ' in function mainprog
    
    'Handle Is On, Pump Is Authorized
               IF Stat(TmpCP&,6) = 0 THEN             'Octane Not Selected
                     Mesg = Mesg + "Please Select Octane"
                     CONTROL SET TEXT hDlg, %MesgBox, Mesg
                     Stat(TmpCP&,21) = 0  'Zero Money
                     Stat(TmpCP&,22) = 0  'Zero Volumn
                     moneyamt$=FORMAT$(Stat(TmpCP&,21),"####.##")
                     volumnamt$=FORMAT$(Stat(TmpCP&,22),"###.###")
    
                    FOR i% = 7 TO 1 STEP -1
                      CONTROL SET TEXT hDlg, AmtD(i%), MID$(MoneyAmt$,i%)
                    NEXT
                    FOR i% = 7 TO 1 STEP -1
                      CONTROL SET TEXT hDlg, VOLd(i%), MID$(VolumnAmt$,i%)
                    NEXT
    
                     CONTROL SET TEXT HDlg, %Price1, Prices(TmpCP&,1)
                     CONTROL SET TEXT HDlg, %Price2, Prices(TmpCP&,2)
                     CONTROL SET TEXT HDlg, %Price3, Prices(TmpCP&,3)
                     CONTROL ENABLE hDlg&, %Octane1
                     CONTROL ENABLE hDlg&, %Octane2
                     CONTROL ENABLE hDlg&, %Octane3
                     CONTROL SET CHECK hDlg&, %Octane1, 0
                     CONTROL SET CHECK hDlg&, %Octane2, 0
                     CONTROL SET CHECK hDlg&, %Octane3, 0
                     UpDate = 0
                     GOTO EndUpDate
                 ELSE
                    
    DoDisplays:
    
       FOR I% = 1 TO 16
          ' note for if statement
          ' Stop incrementing display if check mark removed
          ' should goto Sale Complete
          ' just a comment from my testing of your code.
          'IF Stat(I%,7)=1 AND Stat(I%,8)=0 and Stat(i%,3) = 1 THEN         'Start Pressed, Pump Not Paused
    
    
          IF Stat(I%,7)=1 AND Stat(I%,8)=0 THEN         'Start Pressed, Pump Not Paused
                Stat(I%,22) = Stat(I%,22) + %VolIncAmt  'Increment Volumn Amount
                Stat(I%,21) = Stat(I%,21) + Stat(I%,23) 'Increment Sale Amount
                moneyamt$=FORMAT$(Stat(TmpCP&,21)/1000000,"####.##")
                volumnamt$=FORMAT$(Stat(TmpCP&,22)/1000,"###.###")
          END IF
       NEXT I%
    
       FOR i% = 7 TO 1 STEP -1
          CONTROL SET TEXT hDlg, AmtD(i%), MID$(MoneyAmt$,i%)
       NEXT
       FOR i% = 7 TO 1 STEP -1
          CONTROL SET TEXT hDlg, VOLd(i%), MID$(VolumnAmt$,i%)
       NEXT
    RETURN
    
    'in initialize
    
        AMTd%(1)=    %AmtDsp01  '  'TextBox     - Dollar Amount Pumped, $xxx.xx
        AMTd%(2)=    %AmtDsp02  '  'TextBox     - Dollar Amount Pumped, x$xx.xx
        AMTd%(3)=    %AmtDsp03  '  'TextBox     - Dollar Amount Pumped, xx$x.xx
        AMTd%(4)=    %AmtDsp04  '  'TextBox     - Dollar Amount Pumped Decimal Point
        AMTd%(5)=    %AmtDsp00  '  'TextBox     - Dollar Amount Pumped, xxx$.xx
        AMTd%(6)=    %AmtDsp05  '  'TextBox     - Dollar Amount Pumped, xxxx.$x
        AMTd%(7)=    %AmtDsp06  '  'TextBox     - Dollar Amount Pumped, xxxx.x$
    
        VOLd%(1)=    %VolDsp01  '  'TextBox     - Volumn Amount Pumped, #xxx.xx
        VOLd%(2)=    %VolDsp02  '  'TextBox     - Volumn Amount Pumped, x#xx.xx
        VOLd%(3)=    %VolDsp03  '  'TextBox     - Volumn Amount Pumped, xx#x.xx
        VOLd%(4)=    %VolDsp00  '  'TextBox     - Volumn Amount Pumped Decimal Point
        VOLd%(5)=    %VolDsp04  '  'TextBox     - Volumn Amount Pumped, xxx#.xx
        VOLd%(6)=    %VolDsp05  '  'TextBox     - Volumn Amount Pumped, xxxx.#x
        VOLd%(7)=    %VolDsp06  '  'TextBox     - Volumn Amount Pumped, xxxx.x#
    Phil
    -------------------

    ------------------




    [This message has been edited by Phil Tippit (edited February 15, 2001).]

    Leave a comment:


  • Chris Boss
    replied
    Wesley;

    I get the impression that your app is regularly updating the
    Dialogs control very quickly.

    Maybe a problem could be related to Windows not being able to keep
    up with the changes to the controls.

    Maybe you could store all the values for the controls in Global
    variables and not update the controls directly. Then use a timer or a
    thread with a delay (so it is timed), and regularly read those
    global variables and update the Dialogs controls about 1 to 5 times
    a second (but no more than 5). You could even add an option to determine
    how often the controls are updated (1/2 sec, 1/3 sec, 1/4 sec 1/5 sec).

    If you flood a Dialog with too many requests to redraw controls
    (by anything like changing an option button to checked, etc.) the
    app will likely come to a crawl. Because there are so many bytes being moved
    around when redrawing controls, it can really slow things down.

    Your problem may be similiar to a recent discussion about updating
    a progress bar during reading a file and it was slow. The progress bar
    was being updated everytime a record was read and it slowed down
    terribly.
    ------------------


    [This message has been edited by Chris Boss (edited February 15, 2001).]

    Leave a comment:


  • Wesley Brown
    replied
    Originally posted by Semen Matusovski:
    I don't see delays in threads, which sould be to give another tasks to work.
    To set priority is also bad.

    Semen, I agree that messin' around with Priority is not a good idea. I decided to try
    setting a higher Priority only out of desperation. The "benchmark" without changing
    the Priority of 'hLogic' is approx 0.092 gallons/minute. With the Priority set higher,
    speed increases to 0.296 gallons/minute.

    I can't help but think that I have some very fundamental flaws in my code somewhere
    that is bogging it down. When I am executing in the debugger, when I press 'Stop', it
    always seems stop in the middle of Dialog_Callback(). I'm new at this but I do
    not understand why that routine is even visited when the dialog is not being physically
    moved around, the mouse is still, no buttons are being pressed, etc . . .

    I'm really at a loss to explain why execution is so slow. Perhaps my machine is part of
    the problem? I'm running on a 450Mhz Pentium III laptop, with 128 Mb memory.

    Thanks for your input Semen, I hope I can find what is wrong so that execution will be
    sufficiently fast enough without resorting to changing thread Priorities.

    Wesley Brown

    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    I don't see delays in threads, which sould be to give another tasks to work.
    To set priority is also bad.

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Wesley Brown
    replied
    Chris Boss:
    Wesley,

    It looks like you used the variable hListen instead of hLogic.
    The second thread is not getting its priority set correctly.
    Thanks for pointing that out to me Chris. I have changed that block of code as follows:

    Code:
    'Create "Listen" Thread To Monitor Input From Serial Port
      Thread Create TxRxData(hDlg) To hListen
    'Create "Logic" Thread (main program)
      Thread Create MainProg(hDlg) To hLogic
      Value1 = SetPriorityClass(hLogic,  %High_Priority_Class)
      Value2 = SetThreadPriority (hLogic,%Thread_Priority_Highest)
    'Start the dialog box & run until DIALOG END executed.
      Dialog Show Modal hDlg,  Call Dialog_Callback To Result
    Notice that I am no longer changing the priority of the "Listen" thread.
    With %VolIncAmt = 1, I am now "pumping" 0.648 gallons/minute. I need to
    get to 10.000 gallons/minute but the code is already much faster
    than it was this time yesterday. Thanks for you help

    Wesley Brown

    ------------------

    Leave a comment:


  • Wesley Brown
    replied
    Phil Tippit:
    Wesley,

    Take a look at this and see if it doesn't speed things
    up a little.
    Thank you for your help Phil. You are right, that did speed things up a bit.
    'DoDisplays' has been changed to the following:

    Code:
    DoDisplays:
       For I% = 1 To 16
          If Stat(I%,7)=1 And Stat(I%,8)=0 Then         'Start Pressed, Pump Not Paused
                Stat(I%,22) = Stat(I%,22) + %VolIncAmt  'Increment Volumn Amount
                Stat(I%,21) = Stat(I%,21) + Stat(I%,23) 'Increment Sale Amount
                TempStr1 = Right$("000000" + Trim$(Str$(Stat(TmpCP&,21) \ 10000)), 6)
                TempStr2 = Right$("000000" + Trim$(Str$(Stat(TmpCP&,22))), 6)
                For J% = 1 To 6
                   Money(TmpCP&,J%)  = Mid$(TempStr1,J%,1)
                   Volumn(TmpCP&,J%) = Mid$(TempStr2,J%,1)
                   Next J%
             End If
          Next I%
       Control Set Text hDlg, %AmtDsp01, Money(TmpCP&,1)
       Control Set Text hDlg, %AmtDsp02, Money(TmpCP&,2)
       Control Set Text hDlg, %AmtDsp03, Money(TmpCP&,3)
       Control Set Text hDlg, %AmtDsp04, Money(TmpCP&,4)
       Control Set Text hDlg, %AmtDsp00, "."
       Control Set Text hDlg, %AmtDsp05, Money(TmpCP&,5)
       Control Set Text hDlg, %AmtDsp06, Money(TmpCP&,6)
       Control Set Text hDlg, %VolDsp01, Volumn(TmpCP&,1)
       Control Set Text hDlg, %VolDsp02, Volumn(TmpCP&,2)
       Control Set Text hDlg, %VolDsp03, Volumn(TmpCP&,3)
       Control Set Text hDlg, %VolDsp00, "."
       Control Set Text hDlg, %VolDsp04, Volumn(TmpCP&,4)
       Control Set Text hDlg, %VolDsp05, Volumn(TmpCP&,5)
       Control Set Text hDlg, %VolDsp06, Volumn(TmpCP&,6)
    Return
    Leading Zeros are now displayed, but right now speed is more important than appearance.

    It is necessary to recalculate 'Money(TmpCp,J%)' and 'Money(TmpCp,J%)' every time for every pump for two reasons:
    (1) I must be ready to send all 6 digits of Money & Volumn back to the console as individual ASCII characters
    whenever I receive a 'Command 6' (not coded yet)
    (2) I must keep up with all pumps that are pumping (not just the one that has the focus)

    Thank you for you help. I sincerely appreciate it

    Wesley Brown

    ------------------

    Leave a comment:


  • Chris Boss
    replied
    Wesley;

    I noticed the following in your code :

    Code:
    'Create A "Listen" Thread To Monitor Input From Serial Port
    Thread Create TxRxData(hDlg) To hListen
    Value1 = SetPriorityClass(hListen,  %High_Priority_Class)
    Value2 = SetThreadPriority (hListen,%Thread_Priority_Highest)
    Code:
    'Create "Logic" Thread (main program)
    Thread Create MainProg(hDlg) To hLogic
    Value1 = SetPriorityClass(hListen,  %High_Priority_Class)
    Value2 = SetThreadPriority (hListen,%Thread_Priority_Highest)
    I think you used the wrong variable in the second block of
    code. It looks like you used the variable hListen instead of
    hLogic. The second thread is not getting its priority set correctly.



    ------------------

    Leave a comment:


  • Phil Tippit
    replied
    Wesley,

    Take a look at this and see if it doesn't speed things
    up a little.
    Code:
    DoDisplays:
       FOR I% = 1 TO 16
          IF Stat(I%,7)=1 AND Stat(I%,8)=0 THEN         'Start Pressed, Pump Not Paused
                Stat(I%,22) = Stat(I%,22) + %VolIncAmt  'Increment Volumn Amount
                Stat(I%,21) = Stat(I%,21) + Stat(I%,23) 'Increment Sale Amount
                   ' your are doing following 2 lines 16 times for your value
                   ' Tmpcp&  see notes below
                Money(TmpCp&) = RIGHT$("      "+TRIM$(STR$(Stat(TmpCP&,21) \ 10000)),6)
                Volumn(Tmpcp&) = RIGHT$("      "+TRIM$(STR$(Stat(TmpCP&,22))),6)
          END IF
       NEXT I%
       
            ' the above code may be this, its your program
       'FOR I% = 1 TO 16
       '   IF Stat(I%,7)=1 AND Stat(I%,8)=0 THEN         'Start Pressed, Pump Not Paused
       '         Stat(I%,22) = Stat(I%,22) + %VolIncAmt  'Increment Volumn Amount
       '         Stat(I%,21) = Stat(I%,21) + Stat(I%,23) 'Increment Sale Amount
       '   END IF
       'NEXT I%
       'Money(TmpCp&) = RIGHT$("      "+TRIM$(STR$(Stat(TmpCP&,21) \ 10000)),6)
       'Volumn(Tmpcp&) = RIGHT$("      "+TRIM$(STR$(Stat(TmpCP&,22))),6)
          
       ' another maybe
               ' the above code may be this, its your program
       '
       '   IF Stat(TmpCp&,7)=1 AND Stat(TmpCp&,8)=0 THEN         'Start Pressed, Pump Not Paused
       '         Stat(TmpCp&,22) = Stat(TmpCp&,22) + %VolIncAmt  'Increment Volumn Amount
       '         Stat(TmpCp&,21) = Stat(TmpCp&,21) + Stat(TmpCp&,23) 'Increment Sale Amount
       '         Money(TmpCp&) = RIGHT$("      "+TRIM$(STR$(Stat(TmpCP&,21) \ 10000)),6)
       '         Volumn(Tmpcp&) = RIGHT$("      "+TRIM$(STR$(Stat(TmpCP&,22))),6)
       '   END IF
    
    
       CONTROL SET TEXT hDlg, %AmtDsp01, Money(TmpCP&,1)
       CONTROL SET TEXT hDlg, %AmtDsp02, Money(TmpCP&,2)
       CONTROL SET TEXT hDlg, %AmtDsp03, Money(TmpCP&,3)
       CONTROL SET TEXT hDlg, %AmtDsp04, Money(TmpCP&,4)
       CONTROL SET TEXT hDlg, %AmtDsp00, "."
       CONTROL SET TEXT hDlg, %AmtDsp05, Money(TmpCP&,5)
       CONTROL SET TEXT hDlg, %AmtDsp06, Money(TmpCP&,6)
       '------------------------------------------------
       CONTROL SET TEXT hDlg, %VolDsp01, Volumn(TmpCP&,1)
       CONTROL SET TEXT hDlg, %VolDsp02, Volumn(TmpCP&,2)
       CONTROL SET TEXT hDlg, %VolDsp03, Volumn(TmpCP&,3)
       CONTROL SET TEXT hDlg, %VolDsp00, "."
       CONTROL SET TEXT hDlg, %VolDsp04, Volumn(TmpCP&,4)
       CONTROL SET TEXT hDlg, %VolDsp05, Volumn(TmpCP&,5)
       CONTROL SET TEXT hDlg, %VolDsp06, Volumn(TmpCP&,6)
    Phil

    ------------------


    [This message has been edited by Phil Tippit (edited February 14, 2001).]

    Leave a comment:


  • Chris Boss
    replied
    Wesley;

    I reposted your code using the UBB codes so it indents correctly.
    It was tough trying to follow the code without the indenting.


    Code:
    'Wesley Brown
    'February 14, 2001
    
    #Compile Exe
    #Register None
    #Include "WIN32API.INC"
    '===========================================================================================
    $AppTitle           = "Simulation Program"
    $ComPort            = "COM1"
    
    %VolIncAmt          = 53
    
    %Exit               = 178  'Button      - Exit Program
    %Frame              = 179  'Frame       - Around Pump Displays
    %Label00            = 181  'Text Label  - Current Pump Status
    %Label01            = 182  'Text Label  - Enable
    %Label02            = 183  'Text Label  - Pump
    %Label03            = 184  'Text Label  - Select
    %Label04            = 185  'Text Label  - Handle
    %Label05            = 186  'Text Label  - On/Off
    %MesgBox            = 188  'TextBox     - Pump Status Messages
    %Price1             = 189  'TextBox     - 87 Octane Price
    %Price2             = 190  'TextBox     - 89 Octane Price
    %Price3             = 191  'TextBox     - 92 Octane Price
    %Octane1            = 192  'RadioButton - 87 Octane Price Select
    %Octane2            = 193  'RadioButton - 88 Octane Price Select
    %Octane3            = 194  'RadioButton - 92 Octane Price Select
    %Start              = 195  'Button      - Start Pumping
    %Stop               = 196  'Button      - Stop Pumping
    %VolDisp            = 197  'TextBox     - Gallons Pumped
    %AmtDsp00           = 220  'TextBox     - Dollar Amount Pumped Decimal Point
    %AmtDsp01           = 221  'TextBox     - Dollar Amount Pumped, $xxx.xx
    %AmtDsp02           = 222  'TextBox     - Dollar Amount Pumped, x$xx.xx
    %AmtDsp03           = 223  'TextBox     - Dollar Amount Pumped, xx$x.xx
    %AmtDsp04           = 224  'TextBox     - Dollar Amount Pumped, xxx$.xx
    %AmtDsp05           = 225  'TextBox     - Dollar Amount Pumped, xxxx.$x
    %AmtDsp06           = 226  'TextBox     - Dollar Amount Pumped, xxxx.x$
    %VolDsp00           = 230  'TextBox     - Volumn Amount Pumped Decimal Point
    %VolDsp01           = 231  'TextBox     - Volumn Amount Pumped, #xxx.xx
    %VolDsp02           = 232  'TextBox     - Volumn Amount Pumped, x#xx.xx
    %VolDsp03           = 233  'TextBox     - Volumn Amount Pumped, xx#x.xx
    %VolDsp04           = 234  'TextBox     - Volumn Amount Pumped, xxx#.xx
    %VolDsp05           = 235  'TextBox     - Volumn Amount Pumped, xxxx.#x
    %VolDsp06           = 236  'TextBox     - Volumn Amount Pumped, xxxx.x#
    %Select01           = 801
    %Select02           = 802
    %Select03           = 803
    %Select04           = 804
    %Select05           = 805
    %Select06           = 806
    %Select07           = 807
    %Select08           = 808
    %Select09           = 809
    %Select10           = 810
    %Select11           = 811
    %Select12           = 812
    %Select13           = 813
    %Select14           = 814
    %Select15           = 815
    %Select16           = 816
    %OnOff01            = 901
    %OnOff02            = 902
    %OnOff03            = 903
    %OnOff04            = 904
    %OnOff05            = 905
    %OnOff06            = 906
    %OnOff07            = 907
    %OnOff08            = 908
    %OnOff09            = 909
    %OnOff10            = 910
    %OnOff11            = 911
    %OnOff12            = 912
    %OnOff13            = 913
    %OnOff14            = 914
    %OnOff15            = 915
    %OnOff16            = 916
    '===========================================================================================
    Global CPump&               'Pump That Has Focus Of Dialog Box
    Global TmpCP&               'Used In MainProg In Case CPump& Changes Before Loop Is Complete
    Global PAddrNum     As Long
    Global Temp01       As Long
    Global Temp02       As Long
    Global Temp03       As Long
    Global TtlBytes     As Long
    Global UpDate       As Long
    Global hComm        As Long
    Global hDlg         As Long
    Global hListen      As Long
    Global hLogic       As Long
    Global Result       As Long
    Global Stat()       As Long
    Global ThreadClose  As Long
    Global Value1       As Long
    Global Value2       As Long
    
    Global BytesIn      As String
    Global BytesOut     As String
    Global DataIn()     As String
    Global ConCmnd      As String
    Global LBR          As String
    Global Mesg         As String
    Global PAddr        As String
    Global Prices()     As String
    Global TempStr1     As String
    Global TempStr2     As String
    Global Money()      As String
    Global Volumn()     As String
    
    '===========================================================================================
    Function MakeFont(Font As Asciiz,  _
                      Charset As Long, _
                      Bold As Long,    _
                      Italic As Long,  _
                      PointSize As Long) As Long
             Local hDC      As Long
             Local CyPixels As Long
             hDC       = GetDC(%hWnd_DeskTop)
             CyPixels  = GetDeviceCaps(hDC, %LogPixelsY)
             ReleaseDC %hWnd_DeskTop, hDC
             Function = CreateFont(MulDiv(PointSize, CyPixels, 72), 0, 0, 0, Bold, Italic,     _
                        0, 0, CharSet, %Out_tt_Precis, %Clip_Default_Precis, %Default_Quality, _
                        %Ff_DontCare, Font)
    End Function
    '===========================================================================================
    Function EndComms() As Long
          Dim Dummy As String
          If Comm(#hComm, RxQue) Then Comm Recv #hComm, Comm(#hComm, RxQue), Dummy
          Comm Close #hComm
    End Function
    '===========================================================================================
    Function TxRxData(ByVal hWnd As Long) As Long
       TtlBytes = 0
       While IsFalse ListenClose&
          BytesIn   = ""
          LBR$      = ""
          While (IsFalse ListenClose&) And (LBR$ <> "x")
             If (IsFalse ListenClose&) And (Comm(#hComm, RxQue) = 0 ) Then Iterate Loop
             Comm Recv #hComm, 1, LBR$
             If LBR$ = Chr$(&H05) Then LBR$ = "x"
             BytesIn = LBR$
             TtlBytes = 1
             Wend
          While (IsFalse ListenClose&) And (LBR$ <> "z")
             If (IsFalse ListenClose&) And (Comm(#hComm, RxQue) = 0 ) Then Iterate Loop
             Comm Recv #hComm, 1, LBR$
             If (LBR$ = Chr$(&H17)) Then LBR$ = "y"
             If (LBR$ = Chr$(&H04)) Then LBR$ = "z"
             BytesIn = BytesIn & LBR$
             Incr TtlBytes
             Wend
          PAddr  = Mid$(BytesIn,2,1)
          PAddrNum = Val(PAddr) + 1
          Select Case PAddr
                 Case "A"
                      PAddrNum = 11
                 Case "B"
                      PAddrNum = 12
                 Case "C"
                      PAddrNum = 13
                 Case "D"
                      PAddrNum = 14
                 Case "E"
                      PAddrNum = 15
                 Case "F"
                      PAddrNum = 16
              End Select
          If Stat(PAddrNum,0) <> 0 Then
                ConCmnd = Mid$(BytesIn,3,1)
                Stat(PAddrNum,1) = 1
                Select Case ConCmnd
                       Case "0"  'Command 0
                            Stat(PAddrNum,12) = Val(Mid$(BytesIn,4,6))
                            Stat(PAddrNum,13) = Val(Mid$(BytesIn,10,2))
                            Stat(PAddrNum,13) = Stat(PAddrNum,12) - Stat(PAddrNum,13)
                            Stat(PAddrNum,4) = 1
                            UpDate = 1
                            Comm Send #hComm, Chr$(&H02)
                            Comm Send #hComm, PAddr
                            Comm Send #hComm, Chr$(&H30)
                            Comm Send #hComm, Chr$(&H39)
                            Comm Send #hComm, Chr$(&H39)
                            Comm Send #hComm, Chr$(&H39)
                            Comm Send #hComm, Chr$(&H39)
                            Comm Send #hComm, Chr$(&H39)
                            Comm Send #hComm, Chr$(&H39)
                            Comm Send #hComm, Chr$(&H31)
                            Comm Send #hComm, Chr$(&H35)
                            Comm Send #hComm, Chr$(&H17)
                            Comm Send #hComm, Chr$(&H41)
                            Comm Send #hComm, Chr$(&H04)
                       Case "1"  'Command 1
                            Stat(PAddrNum,4) = 0
                            UpDate = 1
                       Case "2"  'Command 2
                            Stat(PAddrNum,4) = 1
                            UpDate = 1
                       Case "3"  'Command 3
                            Temp01 = Val(Mid$(BytesIn,4,1))
                            Prices(PAddrNum,Temp01) = Mid$(BytesIn,5,1) +"."+ Mid$(BytesIn,6,3)
                            Temp01 = Temp01 + 13
                            Temp02 = Val(Mid$(BytesIn,5,4))
                            Stat(PAddrNum,Temp01) = Temp02
                            If ( (Stat(PAddrNum,14)<>0)    And _
                                 (Stat(PAddrNum,15)<>0)    And _
                                 (Stat(PAddrNum,16)<>0) ) Then
                                  Stat(PAddrNum,2) = 1
                                  Control Enable hDlg&, 900 + PAddrNum
                               Else
                                  Stat(PAddrNum,2) = 1
                                  Control Disable hDlg&, 900 + PAddrNum
                               End If
                            UpDate = 1
                       Case "4"  'Command 4
                       Case "5"  'Command 5
                            Stat(PAddrNum,4)  = 0
                            Stat(PAddrNum,5)  = 0
                            Stat(PAddrNum,9)  = 0
                            Stat(PAddrNum,10) = 0
                            Stat(PAddrNum,11) = 0
                            UpDate = 1
                       Case "6"  'Command 6
                       Stat(CPump&,1) = 1
                            BytesOut = Str$(&H02)
                            UpDate = 1
                       Case "7"  'Command 7
                       Case "8"  'Command 8
                       Case "9"  'Command 9
                       Case "A"  'Command A
                       Case "B"  'Command B
                       Case "C"  'Command C
                       Case "D"  'Command D
                       Case "E"  'Command E
                       Case "F"  'Command F
                    End Select
             End If
          Wend
    Function = %True
    End Function
    '===========================================================================================
    Function StartComms As Long
      Comm Open $COMPORT As #hComm
      If ErrClear Then Exit Function          ' Exit if port cannot be opened
      Comm Set #hComm, Baud     = 9600        ' 9600 baud
      Comm Set #hComm, Byte     = 8           ' 8 bits
      Comm Set #hComm, Parity   = %False      ' No parity
      Comm Set #hComm, CtsFlow  = 0           ' Disable CTS Flow
      Comm Set #hComm, RtsFlow  = 0           ' Disable RTS Flow
      Comm Set #hComm, Xinpflow = 0           ' Disable Xon/Xoff on Input
      Comm Set #hComm, Stop     = 0           ' 1 stop bit
      Comm Set #hComm, TxBuffer = 4096        ' 4k transmit buffer
      Comm Set #hComm, RxBuffer = 4096        ' 4k receive buffer
      Function = %True
    End Function
    '===========================================================================================
    CallBack Function Pump01Selected ()
       CPump& = 1
       Control Get Check hDlg, %OnOff01  To Stat&(1,3)
       Update = 1
       End Function
    CallBack Function Pump02Selected ()
       CPump& = 2
       Control Get Check hDlg, %OnOff02  To Stat&(2,3)
       Update = 1
       End Function
    CallBack Function Pump03Selected ()
       CPump& = 3
       Control Get Check hDlg, %OnOff03  To Stat&(3,3)
       Update = 1
       End Function
    CallBack Function Pump04Selected ()
       CPump& = 4
       Control Get Check hDlg, %OnOff04  To Stat&(4,3)
       Update = 1
       End Function
    CallBack Function Pump05Selected ()
       CPump& = 5
       Control Get Check hDlg, %OnOff05  To Stat&(5,3)
       Update = 1
       End Function
    CallBack Function Pump06Selected ()
       CPump& = 6
       Control Get Check hDlg, %OnOff06  To Stat&(6,3)
       Update = 1
       End Function
    CallBack Function Pump07Selected ()
       CPump& = 7
       Control Get Check hDlg, %OnOff07  To Stat&(7,3)
       Update = 1
       End Function
    CallBack Function Pump08Selected ()
       CPump& = 8
       Control Get Check hDlg, %OnOff08  To Stat&(8,3)
       Update = 1
       End Function
    CallBack Function Pump09Selected ()
       CPump& = 9
       Control Get Check hDlg, %OnOff09  To Stat&(9,3)
       Update = 1
       End Function
    CallBack Function Pump10Selected ()
       CPump& = 10
       Control Get Check hDlg, %OnOff10  To Stat&(10,3)
       Update = 1
       End Function
    CallBack Function Pump11Selected ()
       CPump& = 11
       Control Get Check hDlg, %OnOff11  To Stat&(11,3)
       Update = 1
       End Function
    CallBack Function Pump12Selected ()
       CPump& = 12
       Control Get Check hDlg, %OnOff12  To Stat&(12,3)
       Update = 1
       End Function
    CallBack Function Pump13Selected ()
       CPump& = 13
       Control Get Check hDlg, %OnOff13  To Stat&(13,3)
       Update = 1
       End Function
    CallBack Function Pump14Selected ()
       CPump& = 14
       Control Get Check hDlg, %OnOff14  To Stat&(14,3)
       Update = 1
       End Function
    CallBack Function Pump15Selected ()
       CPump& = 15
       Control Get Check hDlg, %OnOff15  To Stat&(15,3)
       Update = 1
       End Function
    CallBack Function Pump16Selected ()
       CPump& = 16
       Control Get Check hDlg, %OnOff16  To Stat&(16,3)
       Update = 1
       End Function
    CallBack Function Octane1Selected ()
       Stat(CPump&,6) = 1
       Update = 1
    End Function
    CallBack Function Octane2Selected ()
       Stat(CPump&,6) = 2
       Update = 1
       End Function
    CallBack Function Octane3Selected ()
       Stat(CPump&,6) = 3
       Update = 1
       End Function
    CallBack Function StartPump ()
       Stat(CPump&,7) = 1
       Stat(CPump&,8) = 0
       Update = 1
    End Function
    CallBack Function StopPump ()
       Stat(CPump&,8) = 1
       Update = 1
       End Function
    '===========================================================================================
    CallBack Function Dialog_Callback()
          Dim hFont1 As Long, hFont2 As Long, hFont3 As Long, hFont4 As Long
          Dim BrushLtBr As Static Long, BrushWhite As Static Long
          Dim BrushBlue As Static Long, BrushGrn As Static Long
       Select Case CbMsg
             Case %Wm_InitDialog
                'Wm_InitDialog is received from Windows immediately before a dialog box is
                'displayed. Dialog box procedures typically use this message to initialize
                'controls and carry out any other initialization tasks that affect the
                'appearance of the dialog box.
                BrushGrn   = CreateSolidBrush (&H00FF00)
                BrushLtBr  = CreateSolidBrush (&HFF0000)
                BrushWhite = CreateSolidBrush (%White)
                BrushBlue  = CreateSolidBrush (%Blue)
                hFont1 = MakeFont ("Times New Roman", %Ansi_CharSet, %Fw_Bold,   %False, 12)
                Control Send   hDlg, %MesgBox,  %Wm_SetFont, hFont1, 0
                hFont2 = MakeFont ("Courier New",     %Ansi_CharSet, %Fw_Bold,   %False, 40)
                Control Send   hDlg, %AmtDsp00, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %AmtDsp01, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %AmtDsp02, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %AmtDsp03, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %AmtDsp04, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %AmtDsp05, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %AmtDsp06, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %VolDsp00, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %VolDsp01, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %VolDsp02, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %VolDsp03, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %VolDsp04, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %VolDsp05, %Wm_SetFont, hFont2, 0
                Control Send   hDlg, %VolDsp06, %Wm_SetFont, hFont2, 0
                hFont3 = MakeFont ("Arial",           %Ansi_CharSet, %Fw_Normal, %False, 17)
                Control Send   hDlg, %Price1,   %Wm_SetFont, hFont3, 0
                Control Send   hDlg, %Price2,   %Wm_SetFont, hFont3, 0
                Control Send   hDlg, %Price3,   %Wm_SetFont, hFont3, 0
                hFont4 = MakeFont ("Arial",           %Ansi_CharSet, %Fw_Normal, %False, 15)
                ' Return 0 to stop the dialog box engine setting focus
                Function = %False
             Case %Wm_Destroy
                'Wm_Destroy is received from Windows just before destroying a Window
                DeleteObject BrushGrn
                DeleteObject BrushLtBr
                DeleteObject BrushWhite
                DeleteObject BrushBlue
                DeleteObject hFont1
                DeleteObject hFont2
                DeleteObject hFont3
                DeleteObject hFont4
             Case %Wm_CtlColorDlg           'Determines Color Of Dialog BackGround
                'Wm_CtlColorDlg is received from Windows before Windows draws the dialog box. By
                'responding to this message, the dialog box can set its text and background
                'colors by using the given display device context handle.
                Function = BrushLtBr        'Set Background Color Of Entire Dialog
             Case %Wm_CtlColorStatic, %Wm_CtlColorEdit
                'Wm_CtlColorStatic message is sent to the parent window of a static control when
                'the control is about to be drawn. By responding to this message, the parent
                'window can use the given device context handle to set the text and background
                'colors of the static control.
                Select Case GetDlgCtrlId(CbLparam)
                   Case %MesgBox
                      SetTextColor CbWparam, %Blue
                      SetBkColor CbWparam, %White
                      Function = BrushWhite
                   Case %Label00, %Label01, %Label02, %Label03, %Label04, %Label05, _
                        %Octane1, %Octane2, %Octane3
                      SetTextColor CbWparam, %White 'Text Color
                      SetBkColor CbWparam,   %Blue  'BackGround Color (behind text)
                      Function = BrushBlue          'Color of Shade Area
                   Case %AmtDsp00, %AmtDsp01, %AmtDsp02, _
                        %AmtDsp03, %AmtDsp04, %AmtDsp05, %AmtDsp06, _
                        %VolDsp00, %VolDsp01, %VolDsp02, _
                        %VolDsp03, %VolDsp04, %VolDsp05, %VolDsp06, _
                        %Price1,   %Price2,   %Price3
                      SetTextColor CbWparam, %Black 'Text Color
                      SetBkColor CbWparam,   %Green 'BackGround Color (behind text)
                      Function = BrushGrn           'Color Of Shade Area
                End Select
          End Select
       End Function
    '===========================================================================================
    CallBack Function Quit_Callback() As Long
        ' Kill the dialog and let PBMAIN() continue
        Dialog End hDlg, 0
    End Function
    
    '===========================================================================================
    
    Function PbMain
      Dim  Stat   (35,35)
      Dim  Prices (16, 3)
      Dim  Money  (16, 6)
      Dim  Volumn (16, 6)
      Dim  DataIn (16,1:50)
      If IsFalse StartComms Then
            MsgBox "Failure to start communications!",, $AppTitle
            Exit Function
         End If
      'Create a Modal Dialog Box
      Dialog New 0, $AppTitle,,, 500, 380, %Ws_PopUp   Or %Ws_Visible Or %Ws_ClipChildren _
                         Or %Ws_Caption Or %Ws_SysMenu Or %Ws_MinimizeBox, 0 To hDlg
      Control Add Label,    hDlg, %Label02,     "Pump",  47,  10,  25,  13
      Control Add Label,    hDlg, %Label03,   "Select",  46,  19,  25,  13
      Control Add Button,   hDlg, %Select01, "Pump 01",  35,  32,  40,  16, Call Pump01Selected
      Control Add Button,   hDlg, %Select02, "Pump 02",  35,  53,  40,  16, Call Pump02Selected
      Control Add Button,   hDlg, %Select03, "Pump 03",  35,  74,  40,  16, Call Pump03Selected
      Control Add Button,   hDlg, %Select04, "Pump 04",  35,  95,  40,  16, Call Pump04Selected
      Control Add Button,   hDlg, %Select05, "Pump 05",  35, 116,  40,  16, Call Pump05Selected
      Control Add Button,   hDlg, %Select06, "Pump 06",  35, 137,  40,  16, Call Pump06Selected
      Control Add Button,   hDlg, %Select07, "Pump 07",  35, 158,  40,  16, Call Pump07Selected
      Control Add Button,   hDlg, %Select08, "Pump 08",  35, 179,  40,  16, Call Pump08Selected
      Control Add Button,   hDlg, %Select09, "Pump 09",  35, 200,  40,  16, Call Pump09Selected
      Control Add Button,   hDlg, %Select10, "Pump 10",  35, 221,  40,  16, Call Pump10Selected
      Control Add Button,   hDlg, %Select11, "Pump 11",  35, 242,  40,  16, Call Pump11Selected
      Control Add Button,   hDlg, %Select12, "Pump 12",  35, 263,  40,  16, Call Pump12Selected
      Control Add Button,   hDlg, %Select13, "Pump 13",  35, 284,  40,  16, Call Pump13Selected
      Control Add Button,   hDlg, %Select14, "Pump 14",  35, 305,  40,  16, Call Pump14Selected
      Control Add Button,   hDlg, %Select15, "Pump 15",  35, 326,  40,  16, Call Pump15Selected
      Control Add Button,   hDlg, %Select16, "Pump 16",  35, 347,  40,  16, Call Pump16Selected
      Control Add Label,    hDlg, %Label04,   "Handle",  83,  10,  25,  13
      Control Add Label,    hDlg, %Label05,   "On/Off",  83,  19,  25,  13
      Control Add CheckBox, hDlg, %OnOff01,         "",  89,  35,   8,   8, Call Pump01Selected
      Control Add CheckBox, hDlg, %OnOff02,         "",  89,  56,   8,   8, Call Pump02Selected
      Control Add CheckBox, hDlg, %OnOff03,         "",  89,  77,   8,   8, Call Pump03Selected
      Control Add CheckBox, hDlg, %OnOff04,         "",  89,  98,   8,   8, Call Pump04Selected
      Control Add CheckBox, hDlg, %OnOff05,         "",  89, 119,   8,   8, Call Pump05Selected
      Control Add CheckBox, hDlg, %OnOff06,         "",  89, 140,   8,   8, Call Pump06Selected
      Control Add CheckBox, hDlg, %OnOff07,         "",  89, 161,   8,   8, Call Pump07Selected
      Control Add CheckBox, hDlg, %OnOff08,         "",  89, 182,   8,   8, Call Pump08Selected
      Control Add CheckBox, hDlg, %OnOff09,         "",  89, 203,   8,   8, Call Pump09Selected
      Control Add CheckBox, hDlg, %OnOff10,         "",  89, 224,   8,   8, Call Pump10Selected
      Control Add CheckBox, hDlg, %OnOff11,         "",  89, 245,   8,   8, Call Pump11Selected
      Control Add CheckBox, hDlg, %OnOff12,         "",  89, 266,   8,   8, Call Pump12Selected
      Control Add CheckBox, hDlg, %OnOff13,         "",  89, 287,   8,   8, Call Pump13Selected
      Control Add CheckBox, hDlg, %OnOff14,         "",  89, 308,   8,   8, Call Pump14Selected
      Control Add CheckBox, hDlg, %OnOff15,         "",  89, 329,   8,   8, Call Pump15Selected
      Control Add CheckBox, hDlg, %OnOff16,         "",  89, 350,   8,   8, Call Pump16Selected
      Control Add Button,   hDlg, %Exit,        "Exit", 373, 350,  50,  14, Call Quit_Callback
      Control Add TextBox,  hDlg, %MesgBox,         "", 120,  11, 370,  12, _
                  %Es_ReadOnly, %Ws_Ex_ClientEdge
      Control Set Text hDlg, %MesgBox, "Initializing . . . . . Please Wait"
      Control Add TextBox,  hDlg, %AmtDsp01,       " ", 126,  40,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %AmtDsp02,       " ", 146,  40,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %AmtDsp03,       " ", 166,  40,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %AmtDsp04,       " ", 186,  40,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %AmtDsp00,       ".", 204,  40,  16,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %AmtDsp05,       " ", 220,  40,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %AmtDsp06,       " ", 240,  40,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %VolDsp01,       " ", 126,  73,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %VolDsp02,       " ", 146,  73,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %VolDsp03,       " ", 166,  73,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %VolDsp00,       ".", 184,  73,  16,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %VolDsp04,       " ", 200,  73,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %VolDsp05,       " ", 220,  73,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %VolDsp06,       " ", 240,  73,  20,  30, %Es_ReadOnly
      Control Add TextBox,  hDlg, %Price1,   " .   "  , 130, 106,  39,  15, %Es_ReadOnly
      Control Add TextBox,  hDlg, %Price2,   " .   "  , 173, 106,  39,  15, %Es_ReadOnly
      Control Add TextBox,  hDlg, %Price3,   " .   "  , 216, 106,  39,  15, %Es_ReadOnly
      Control Add Option,   hDlg, %Octane1,         "", 145, 125,  10,  10, _
                                                                  %Ws_Group Call Octane1Selected
      Control Add Option,   hDlg, %Octane2,         "", 188, 125,  10,  10  Call Octane2Selected
      Control Add Option,   hDlg, %Octane3,         "", 231, 125,  10,  10  Call Octane3Selected
      Control Add Frame,    hDlg, %Frame,           "", 120,  28, 145, 110, ,%Ws_Ex_TransParent
      Control Add Button,   hDlg, %Start, "Begin Fueling", 130, 142,  50,  14  Call StartPump
      Control Add Button,   hDlg, %Stop,  "Pause Fueling", 205, 142,  50,  14  Call StopPump
    
    '  Control Add Frame,    hDlg,    %Frame,        "", 294,  28, 187, 117, ,%Ws_Ex_TransParent
      Control Add Label,    hDlg, %Label00,    "Status Of Selected Pump", 266,   1,  80,  9
    
    '===========================================================================================
    
    'Create A "Listen" Thread To Monitor Input From Serial Port
      Thread Create TxRxData(hDlg) To hListen
      Value1 = SetPriorityClass(hListen,  %High_Priority_Class)
      Value2 = SetThreadPriority (hListen,%Thread_Priority_Highest)
    
    'Create "Logic" Thread (main program)
      Thread Create MainProg(hDlg) To hLogic
      Value1 = SetPriorityClass(hListen,  %High_Priority_Class)
      Value2 = SetThreadPriority (hListen,%Thread_Priority_Highest)
      
    'Start the dialog box & run until DIALOG END executed.
      Dialog Show Modal hDlg,  Call Dialog_Callback To Result
    
    '===========================================================================================
    
    'Close Down "Logic" Thread
      LogicClose& = %True
      Thread Suspend hLogic To Result
      Do
         Thread Close hLogic To Result
         Loop Until IsTrue Result
    'Close Down "Listen" Thread
      ListenClose& = %True
      Thread Suspend hListen To Result
      Do
         Thread Close hListen To Result
         Loop Until IsTrue Result
    ' Flush & Close The Communication Port. Close The Receive File (if open)
      Call EndComms
      Function = %True
    End Function
    '===========================================================================================
    Function MainProg(ByVal hWnd As Long) As Long
      GoSub Initialize
      While IsFalse LogicClose&
         If UpDate = 1 Then
               TmpCP& = CPump&
               Mesg = "Pump" + Str$(TmpCP&) + ": "
               If Stat(TmpCP&,0) = 0 Then       'Pump Is Disabled
                     Mesg = Mesg + "Disabled"
                     Control Set Text hDlg, %MesgBox, Mesg
                     Control Disable hDlg&, %Octane1
                     Control Disable hDlg&, %Octane2
                     Control Disable hDlg&, %Octane3
                     Control Set Check hDlg&, %Octane1, 0
                     Control Set Check hDlg&, %Octane2, 0
                     Control Set Check hDlg&, %Octane3, 0
                     Control Disable hDlg&, %Start
                     Control Disable hDlg&, %Stop
                     Control Set Text hDlg, %Price1,   " -.---"
                     Control Set Text hDlg, %Price2,   " -.---"
                     Control Set Text hDlg, %Price3,   " -.---"
                     GoSub DoDisplays
                     UpDate = 0
                     GoTo EndUpdate
                  End If
               'Enabled Box Is Checked
               If Stat(TmpCP&,1) = 0 Then       'Console Not Found
                     Mesg = Mesg + "Waiting For Communications From Console"
                     Control Set Text hDlg, %MesgBox, Mesg
                     Control Disable hDlg&, %Octane1
                     Control Disable hDlg&, %Octane2
                     Control Disable hDlg&, %Octane3
                     Control Set Check hDlg&, %Octane1, 0
                     Control Set Check hDlg&, %Octane2, 0
                     Control Set Check hDlg&, %Octane3, 0
                     Control Disable hDlg&, %Start
                     Control Disable hDlg&, %Stop
                     Control Set Text hDlg, %Price1,   " -.---"
                     Control Set Text hDlg, %Price2,   " -.---"
                     Control Set Text hDlg, %Price3,   " -.---"
                     GoSub DoDisplays
                     UpDate = 0
                     GoTo EndUpdate
                  End If
               'Console Has Been Found
               If Stat(TmpCP&,2) = 0 Then             'Prices Not Loaded
                     Mesg = Mesg + "Console Found, Loading Prices . . . Please Wait"
                     Control Set Text hDlg, %MesgBox, Mesg
                     Control Disable hDlg&, %Octane1
                     Control Disable hDlg&, %Octane2
                     Control Disable hDlg&, %Octane3
                     Control Set Check hDlg&, %Octane1, 0
                     Control Set Check hDlg&, %Octane2, 0
                     Control Set Check hDlg&, %Octane3, 0
                     Control Disable hDlg&, %Start
                     Control Disable hDlg&, %Stop
                     Control Set Text hDlg, %Price1,   " -.---"
                     Control Set Text hDlg, %Price2,   " -.---"
                     Control Set Text hDlg, %Price3,   " -.---"
                     GoSub DoDisplays
                     UpDate = 0
                     GoTo EndUpdate
                  End If
               'Prices Loaded
               If Stat(TmpCP&,3) = 0 Then             'Pump Handle Off
                    If Stat(TmpCP&,9) = 0 Then        'Handle Off, $flag Not Set
                          Mesg = Mesg + "Handle Off"
                          Control Set Text hDlg, %MesgBox, Mesg
                          Control Set Text HDlg, %Price1, Prices(TmpCP&,1)
                          Control Set Text HDlg, %Price2, Prices(TmpCP&,2)
                          Control Set Text HDlg, %Price3, Prices(TmpCP&,3)
                          Control Set Check hDlg&, %Octane1, 0
                          Control Set Check hDlg&, %Octane2, 0
                          Control Set Check hDlg&, %Octane3, 0
                          Control Disable hDlg&, %Octane1
                          Control Disable hDlg&, %Octane2
                          Control Disable hDlg&, %Octane3
                          Control Disable hDlg&, %Start
                          Control Disable hDlg&, %Stop
                          Stat(TmpCP&,6) = 0          'Octane Not Selected
                          UpDate = 0
                          GoTo EndUpdate
                       Else                           'Handle Off, $flag Is Set (Sale Has Ended)
                          Mesg =Mesg+ "Sale Complete, Waiting For Console Acknowledgement"
                          Control Set Text hDlg, %MesgBox, Mesg
                          Control Set Text HDlg, %Price1, Prices(TmpCP&,1)
                          Control Set Text HDlg, %Price2, Prices(TmpCP&,2)
                          Control Set Text HDlg, %Price3, Prices(TmpCP&,3)
                          Select Case Stat(TmpCP&,6)
                                 Case 1
                                     Control Enable  hDlg&, %Octane1
                                     Control Disable hDlg&, %Octane2
                                     Control Disable hDlg&, %Octane3
                                     Control Set Check hDlg&, %Octane1, 1
                                     Control Set Check hDlg&, %Octane2, 0
                                     Control Set Check hDlg&, %Octane3, 0
                                 Case 2
                                     Control Disable hDlg&, %Octane1
                                     Control Enable  hDlg&, %Octane2
                                     Control Disable hDlg&, %Octane3
                                     Control Set Check hDlg&, %Octane1, 0
                                     Control Set Check hDlg&, %Octane2, 1
                                     Control Set Check hDlg&, %Octane3, 0
                                 Case 3
                                     Control Disable hDlg&, %Octane1
                                     Control Disable hDlg&, %Octane2
                                     Control Enable  hDlg&, %Octane3
                                     Control Set Check hDlg&, %Octane1, 0
                                     Control Set Check hDlg&, %Octane2, 0
                                     Control Set Check hDlg&, %Octane3, 1
                              End Select
                          Stat(TmpCP&,4)  = 1
                          Stat(TmpCP&,5)  = 0
                          Stat(TmpCP&,7)  = 0
                          Stat(TmpCP&,8)  = 0
                          Stat(TmpCP&,9)  = 0
                          Stat(TmpCP&,10) = 0
                          Stat(TmpCP&,11) = 0
                          Stat(TmpCP&,23) = 0
    
                          UpDate = 1
                          GoTo EndUpDate
                       End If 'Not End Of Sale
                  End If 'Pump Handle Off
               'Pump Handle Is On
               If Stat(TmpCP&,4) = 0 Then             'Pump Is Not Aurhorized
                     Mesg = Mesg + "Waiting For Authorization From Console"
                     Control Set Text hDlg, %MesgBox, Mesg
                     Control Set Text HDlg, %Price1, Prices(TmpCP&,1)
                     Control Set Text HDlg, %Price2, Prices(TmpCP&,2)
                     Control Set Text HDlg, %Price3, Prices(TmpCP&,3)
                     Control Disable hDlg&, %Octane1
                     Control Disable hDlg&, %Octane2
                     Control Disable hDlg&, %Octane3
                     Control Set Check hDlg&, %Octane1, 0
                     Control Set Check hDlg&, %Octane2, 0
                     Control Set Check hDlg&, %Octane3, 0
                     Control Disable hDlg&, %Start
                     Control Disable hDlg&, %Stop
                     UpDate = 0
                     GoTo EndUpdate
                  End If
               'Handle Is On, Pump Is Authorized
               If Stat(TmpCP&,6) = 0 Then             'Octane Not Selected
                     Mesg = Mesg + "Please Select Octane"
                     Control Set Text hDlg, %MesgBox, Mesg
                     Stat(TmpCP&,21) = 0  'Zero Money
                     Stat(TmpCP&,22) = 0  'Zero Volumn
                     TempStr1 = "000000"
                     TempStr2 = "000000"
                     For J% = 1 To 6
                        Money(TmpCP&,J%)  = Mid$(TempStr1,J%,1)
                        Volumn(TmpCP&,J%) = Mid$(TempStr2,J%,1)
                        Next J%
                     If Money(TmpCP&,1) = "0" Then
                           Control Set Text hDlg, %AmtDsp01, " "
                        Else
                           Control Set Text hDlg, %AmtDsp01, Money(TmpCP&,1)
                           Control Set Text hDlg, %AmtDsp02, Money(TmpCP&,2)
                           Control Set Text hDlg, %AmtDsp03, Money(TmpCP&,3)
                           GoTo Label03
                        End If
                     If Money(TmpCP&,2) = "0" Then
                           Control Set Text hDlg, %AmtDsp02, " "
                        Else
                           Control Set Text hDlg, %AmtDsp02, Money(TmpCP&,2)
                           Control Set Text hDlg, %AmtDsp03, Money(TmpCP&,3)
                           GoTo Label03
                        End If
                     If Money(TmpCP&,3) = "0" Then
                           Control Set Text hDlg, %AmtDsp03, " "
                        Else
                           Control Set Text hDlg, %AmtDsp03, Money(TmpCP&,3)
                        End If
    Label03:
                     Control Set Text hDlg, %AmtDsp04, Money(TmpCP&,4)
                     Control Set Text hDlg, %AmtDsp00, "."
                     Control Set Text hDlg, %AmtDsp05, Money(TmpCP&,5)
                     Control Set Text hDlg, %AmtDsp06, Money(TmpCP&,6)
                     If Volumn(TmpCP&,1) = "0" Then
                           Control Set Text hDlg, %VolDsp01, " "
                        Else
                           Control Set Text hDlg, %VolDsp01, Volumn(TmpCP&,1)
                           Control Set Text hDlg, %VolDsp02, Volumn(TmpCP&,2)
                           GoTo Label04
                        End If
                     If Volumn(TmpCP&,2) = "0" Then
                           Control Set Text hDlg, %VolDsp02, " "
                        Else
                           Control Set Text hDlg, %VolDsp02, Volumn(TmpCP&,2)
                        End If
    Label04:
                     Control Set Text hDlg, %VolDsp03, Volumn(TmpCP&,3)
                     Control Set Text hDlg, %VolDsp00, "."
                     Control Set Text hDlg, %VolDsp04, Volumn(TmpCP&,4)
                     Control Set Text hDlg, %VolDsp05, Volumn(TmpCP&,5)
                     Control Set Text hDlg, %VolDsp06, Volumn(TmpCP&,6)
                     Control Set Text HDlg, %Price1, Prices(TmpCP&,1)
                     Control Set Text HDlg, %Price2, Prices(TmpCP&,2)
                     Control Set Text HDlg, %Price3, Prices(TmpCP&,3)
                     Control Enable hDlg&, %Octane1
                     Control Enable hDlg&, %Octane2
                     Control Enable hDlg&, %Octane3
                     Control Set Check hDlg&, %Octane1, 0
                     Control Set Check hDlg&, %Octane2, 0
                     Control Set Check hDlg&, %Octane3, 0
                     UpDate = 0
                     GoTo EndUpDate
                  Else                                'User Chose Octane
                     Select Case Stat(TmpCP&,6)
                            Case 1
                                Control Set Text HDlg, %Price1, Prices(TmpCP&,1)
                                Control Set Text HDlg, %Price2, " -.---"
                                Control Set Text HDlg, %Price3, " -.---"
                                Stat(TmpCP&,23) = Stat(TmpCP&,14) * %VolIncAmt
                                Control Enable  hDlg&, %Octane1
                                Control Disable hDlg&, %Octane2
                                Control Disable hDlg&, %Octane3
                                Control Set Check hDlg&, %Octane1, 1
                                Control Set Check hDlg&, %Octane2, 0
                                Control Set Check hDlg&, %Octane3, 0
                            Case 2
                                Control Set Text HDlg, %Price1, " -.---"
                                Control Set Text HDlg, %Price2, Prices(TmpCP&,2)
                                Control Set Text HDlg, %Price3, " -.---"
                                Stat(TmpCP&,23) = Stat(TmpCP&,15) * %VolIncAmt
                                Control Disable hDlg&, %Octane1
                                Control Enable  hDlg&, %Octane2
                                Control Disable hDlg&, %Octane3
                                Control Set Check hDlg&, %Octane1, 0
                                Control Set Check hDlg&, %Octane2, 1
                                Control Set Check hDlg&, %Octane3, 0
                            Case 3
                                Control Set Text HDlg, %Price1, " -.---"
                                Control Set Text HDlg, %Price2, " -.---"
                                Control Set Text HDlg, %Price3, Prices(TmpCP&,3)
                                Stat(TmpCP&,23) = Stat(TmpCP&,16) * %VolIncAmt
                                Control Disable hDlg&, %Octane1
                                Control Disable hDlg&, %Octane2
                                Control Enable  hDlg&, %Octane3
                                Control Set Check hDlg&, %Octane1, 0
                                Control Set Check hDlg&, %Octane2, 0
                                Control Set Check hDlg&, %Octane3, 1
                         End Select
                  End If
    
               'Octane Has Been Selected
               If Stat(TmpCP&,7) = 0 Then             'Start Button Has Not Been Pressed
                     Mesg = Mesg+ "Press Start To Begin Fuel Delivery"
                     Control Set Text hDlg, %MesgBox, Mesg
                     Control Enable hDlg&, %Start
                     UpDate = 0
                     GoTo EndUpDate
                  End If
               'Start Button Has Been Pressed, Wait For .01 To Be Pumped
               If Money(TmpCP&,6) <> "0" Then  Stat(TmpCP&,9) = 1
    
               If Stat(TmpCP&,8)=0 Then               'Not Paused
                     Mesg = Mesg+ "Fuel Delivery In Progress"
                     Control Set Text hDlg, %MesgBox, Mesg
                     Control Disable hDlg&, %Start
                     Control Enable hDlg&, %Stop
                  Else
                     Mesg = Mesg+ "Fuel Delivery Paused . . . . "
                     Control Set Text hDlg, %MesgBox, Mesg
                     Control Enable hDlg&, %Start
                     Control Disable hDlg&, %Stop
                  End If
            EndUpDate:
            End If 'UpDate = 1
       GoSub DoDisplays
      Wend '(While IsFalse ThreadClose)
      Function = %True
    '-----------------------------------------------------------------------------------
    DoDisplays:
       For I% = 1 To 16
          If Stat(I%,7)=1 And Stat(I%,8)=0 Then         'Start Pressed, Pump Not Paused
                Stat(I%,22) = Stat(I%,22) + %VolIncAmt  'Increment Volumn Amount
                Stat(I%,21) = Stat(I%,21) + Stat(I%,23) 'Increment Sale Amount
                Temp03 = Stat(TmpCP&,21) \ 10000
                TempStr1 = "000000" + Trim$(Str$(Temp03))
                TempStr1 = Right$(TempStr1, 6)
                TempStr2 = "000000" + Trim$(Str$(Stat(TmpCP&,22)))
                TempStr2 = Right$(TempStr2, 6)
                For J% = 1 To 6
                   Money(TmpCP&,J%)  = Mid$(TempStr1,J%,1)
                   Volumn(TmpCP&,J%) = Mid$(TempStr2,J%,1)
                   Next J%
             End If
          Next I%
       If Money(TmpCP&,1) = "0" Then
             Control Set Text hDlg, %AmtDsp01, " "
          Else
             Control Set Text hDlg, %AmtDsp01, Money(TmpCP&,1)
             Control Set Text hDlg, %AmtDsp02, Money(TmpCP&,2)
             Control Set Text hDlg, %AmtDsp03, Money(TmpCP&,3)
             GoTo Label01
          End If
       If Money(TmpCP&,2) = "0" Then
             Control Set Text hDlg, %AmtDsp02, " "
          Else
             Control Set Text hDlg, %AmtDsp02, Money(TmpCP&,2)
             Control Set Text hDlg, %AmtDsp03, Money(TmpCP&,3)
             GoTo Label01
          End If
       If Money(TmpCP&,3) = "0" Then
             Control Set Text hDlg, %AmtDsp03, " "
          Else
             Control Set Text hDlg, %AmtDsp03, Money(TmpCP&,3)
          End If
    Label01:
       Control Set Text hDlg, %AmtDsp04, Money(TmpCP&,4)
       Control Set Text hDlg, %AmtDsp00, "."
       Control Set Text hDlg, %AmtDsp05, Money(TmpCP&,5)
       Control Set Text hDlg, %AmtDsp06, Money(TmpCP&,6)
       If Volumn(TmpCP&,1) = "0" Then
             Control Set Text hDlg, %VolDsp01, " "
          Else
             Control Set Text hDlg, %VolDsp01, Volumn(TmpCP&,1)
             Control Set Text hDlg, %VolDsp02, Volumn(TmpCP&,2)
             GoTo Label02
          End If
       If Volumn(TmpCP&,2) = "0" Then
             Control Set Text hDlg, %VolDsp02, " "
          Else
             Control Set Text hDlg, %VolDsp02, Volumn(TmpCP&,2)
          End If
    Label02:
       Control Set Text hDlg, %VolDsp03, Volumn(TmpCP&,3)
       Control Set Text hDlg, %VolDsp00, "."
       Control Set Text hDlg, %VolDsp04, Volumn(TmpCP&,4)
       Control Set Text hDlg, %VolDsp05, Volumn(TmpCP&,5)
       Control Set Text hDlg, %VolDsp06, Volumn(TmpCP&,6)
    Return
    '-----------------------------------------------------------------------------------
    Initialize:
    Control Set Text hDlg, %MesgBox, "Initializing . . . . . Please Wait"
       For I% = 1 To 16
          Stat(I%,0)  = 1 'Enabled?
          Stat(I%,1)  = 1 'Console Found?
          Stat(I%,2)  = 1 'Prices Loaded?
          Stat(I%,3)  = 0 'Handle On?
          Stat(I%,4)  = 1 'Armed?
          Stat(I%,5)  = 0 'PostPay?
          Stat(I%,6)  = 0 'Octane Selected?
          Stat(I%,7)  = 0 'Start Pressed?
          Stat(I%,8)  = 0 'Paused?
          Stat(I%,9)  = 0 '$flag?
          Stat(I%,10) = 0 'Thru?
          Stat(I%,11) = 0 'Limit Reached?
          Stat(I%,12) = 0 'Dollar Allowcation
          Stat(I%,13) = 0 'Valve Slow Down
          Stat(I%,14) = 1329      'Cash, Price A
          Prices(I%,1) = "1.329"  'Cash, Price A
          Stat(I%,15) = 1439      'Cash, Price B
          Prices(I%,2) = "1.439"  'Cash, Price B      
          Stat(I%,16) = 1549      'Cash, Price C
          Prices(I%,3) = "1.549"  'Cash, Price C
          Stat(I%,17) = 0 'PrePay Amount
          Stat(I%,18) = 0 'Valve Slow-Down Amount
          Stat(I%,19) = 0 'Command 5 Received
          Stat(I%,20) = 0 'Pump Status
          Stat(I%,21) = 0 'Money
          Stat(I%,22) = 0 'Volumn
          Stat(I%,23) = 0 '_______________
          Stat(I%,24) = 0 '_______________
          Stat(I%,25) = 0 '_______________
          Stat(I%,26) = 0 '_______________
          Stat(I%,27) = 0 '_______________
          Stat(I%,28) = 0 '_______________
          Stat(I%,29) = 0 '_______________
          Stat(I%,30) = 0 '_______________
          Money(I%,1)   = "0"
          Money(I%,2)   = "0"
          Money(I%,3)   = "0"
          Money(I%,4)   = "0"
          Money(I%,5)   = "0"
          Money(I%,6)   = "0"
          Volumn(I%,1)  = "0"
          Volumn(I%,2)  = "0"
          Volumn(I%,3)  = "0"
          Volumn(I%,4)  = "0"
          Volumn(I%,5)  = "0"
          Volumn(I%,6)  = "0"
        Next I%
    'Disable "Start" Radio Buttons
       Control Disable hDlg&, %Start
       Control Disable hDlg&, %Stop
    'Default CPump& To Pump 1
       CPump& = 1
       Update = 1
    Return
    End Function
    '===========================================================================================

    ------------------

    Leave a comment:


  • John Kovacich
    replied
    You might try optimizing some instructions like this:
    Comm Send #hComm, Chr$(&H02)
    Comm Send #hComm, PAddr
    Comm Send #hComm, Chr$(&H30)
    Comm Send #hComm, Chr$(&H39)
    Comm Send #hComm, Chr$(&H39)
    Comm Send #hComm, Chr$(&H39)
    Comm Send #hComm, Chr$(&H39)
    Comm Send #hComm, Chr$(&H39)
    Comm Send #hComm, Chr$(&H39)
    Comm Send #hComm, Chr$(&H31)
    Comm Send #hComm, Chr$(&H35)
    Comm Send #hComm, Chr$(&H17)
    Comm Send #hComm, Chr$(&H41)
    Comm Send #hComm, Chr$(&H04)

    I would think the following should run a little pinch faster
    Comm Send #hComm, Chr$(&H02)
    Comm Send #hComm, PAddr
    Comm Send #hComm,"099999915"
    Comm Send #hComm, Chr$(&H17)
    Comm Send #hComm, Chr$(&H41)
    Comm Send #hComm, Chr$(&H04)

    Perhaps, better still, since you are an assembler guy, imbed the
    assembler code.

    I also wonder if setting the thread priorities to high might stealing
    cycles from library functions (like comm).



    ------------------
    Thanks,

    John Kovacich

    Leave a comment:


  • Peter Scheutz
    replied
    Wesley -- (and others )

    Just a note:
    When you post source code, wrap it with CODE tags to preserve format.
    It makes it much more readable.
    Click the "UBB Code is ON" to the left of the edit box to see how.

    --
    Best Regards
    Peter Scheutz

    ------------------

    Leave a comment:


  • Wesley Brown
    replied
    The constant %VolIncAmt (currently = 53) determines how fast the simulator "pumps". When finished,
    I must be able to "pump" 10 gallons/minute simultaneously on all 16 pumps.
    When I first began this program I fully expected that I would have to put some type of delay
    statements in the code to keep it from going so fast that the displays couldn't be read. As it turns
    out it is about 50 times slower than it needs to be. In other words, I need to be able to set %VolIncAmt
    equal to 1 and still be able to process 10.000 gallons per minute.

    Keep in mind that I have been a Z80 assembler programmer for the past 9 years and that this is my
    very first Windows program. Aside from needing to know what I need to do different to speed things
    up, I am open to constructive critisism of any kind. I'm not proud . . . I won't be offended . . .
    and I'm a big boy (6'2" & 245lbs) and so I can take it.

    Thanks in advance to anyone who takes the time to look through my program.
    I sincerely appreciate your help.

    I originally posted the code at this point. However, I did not have UUB codes enabled.
    Thanks to Peter Scheutz for making me aware of UUB codes ... and to Chris Boss for being nice
    enough re-post the code for me using UUB codes.

    To conserve space, the source code is 2 posts below this one (Chris's Post)


    [This message has been edited by Wesley Brown (edited February 14, 2001).]

    Leave a comment:


  • Steve Hutchesson
    replied
    Wesley,

    They get hard to read when they are very large and a lot of the
    code will be normal inteerface stuff. Could you isolate some of
    the code that is not going fast enough ? I am sure there are
    forum members who would be pleased to help you get it going
    properly.

    Regards,

    [email protected]

    ------------------

    Leave a comment:


  • Phil Tippit
    replied
    Wesley,

    The only way to know is to post it.

    I have a 400 line program I've been trying to Post to the
    Source Code Forum for 4 months, and it still want post.

    But, I have also seen in that same time period, programs
    with over a 1000 lines being posted.

    Good Luck,
    Phil

    ------------------

    Leave a comment:


  • Wesley Brown
    started a topic Very Slow Execution

    Very Slow Execution

    Hi Everyone (again )

    I am still plugging along on my first PB/DLL program. Progress is being made and I
    sometimes think that I'm beginning to understand some of the concepts behind
    Windows programming.

    I am having some very serious execution speed problem and would like to post my
    source to the forum so that I can get some suggestions as to what the problem(s) is/are.
    However, I am concerned that it may be too long (950 lines).

    Is posting that many lines is acceptable?

    Thanks,

    Wesley Brown

    ------------------
Working...
X