Announcement

Collapse
No announcement yet.

Failure To Properly Terminate Execution

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

  • Failure To Properly Terminate Execution

    Hello Everyone,

    I occasionally receive the following error message:

    Error 496 In Program.Bas(148:1): Destination File Write Error Line 148:End Function

    When I get this error I can type "(ctrl)+(alt)+(del)" to bring up a list of programs that
    are executing on my machine and I see 'Program.bas' on the list. What drives me crazy is
    that the program terminates properly about 80% of the time (luck i guess) and that there
    does not seem to be any reason as to when it does and does not terminate properly.

    I have posted an abbreviated version of the code (but one that does contain the problem)
    below and would appreciate any help to find the problem.

    Thanks in Advance

    Wesley

    Code:
    'Wesley Brown
    'February 22, 2001
    
    #Compile Exe
    #Register None
    #Dim All
    #Include "WIN32API.INC"
    '===========================================================================================
    'Define Constants
    $AppTitle           = "Program That Has Problems"
    $ComPort            = "COM1"
    %Exit               = 200  'Button, Exit Program
    %Idt_Timer1         = 300  'Timer, Money & Volumn Update
    %Idt_Timer2         = 301  'Timer, Screen Update
    %MesgBox            = 400  'TextBox, Status Messages
    '-------------------------------------
    'Define Globals
    Global hComm        As Long
    Global hDlg         As Long
    Global hListen      As Long
    Global hLogic       As Long
    Global LogicClose   As Long
    Global ListenClose  As Long
    Global Result       As Long
    Global TtlBytes     As Long
    Global BytesIn      As String
    Global LBR          As String
    '-------------------------------------
    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
       While IsFalse ListenClose&
          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
          'Process BytesIn
          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
    '===========================================================================================
    'Dialog Control Callback Functions
    
    '===========================================================================================
    CallBack Function Dialog_Callback()
       Select Case CbMsg
              Case %Wm_Timer
                 Select Case CbWparam
                        Case %Idt_Timer1
                             'Timer1 Routine
                        Case %Idt_Timer2
                             'Timer2 Routine
                    End Select 'CbWparam
              Case %Wm_InitDialog
                 SetTimer  hDlg, %Idt_Timer1, 100, ByVal %Null
                 SetTimer  hDlg, %Idt_Timer2, 500, ByVal %Null
              Case %Wm_Destroy
                 KillTimer hDlg, %Idt_Timer1
                 KillTimer hDlg, %Idt_Timer2
          End Select 'CbMsg
       End Function
    
    '===========================================================================================
    CallBack Function Quit_Callback() As Long
        ' Kill the dialog and let PBMAIN() continue
        Dialog End hDlg, 0
    End Function
    '===========================================================================================
    Function PbMain
      'Initialize Serial Port
      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 Button,   hDlg, %Exit,        "Exit", 373, 350,  50,  14, Call Quit_Callback
    
    '===========================================================================================
    
    'Create A "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
    
    '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 Comm Port
      Call EndComms
      Function = %True
    
    End Function
    
    '===========================================================================================
    
    Function MainProg(ByVal hWnd As Long) As Long
      While IsFalse LogicClose&
            'Main Program Code
         Wend '(While IsFalse ThreadClose)
      Function = %True
    End Function

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


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

  • #2
    Wesley,

    I only ever get that error message when I try to compile a file
    that is already running. Normally a disk file cannot be overwritten
    if it is running.

    This can be a problem if a program has crashed and is no longer
    visible on the screen but still in memory. If this is the case
    you will have to chase down what the problem is with the program
    that prevents it from terminating.

    Regards,

    [email protected]

    ------------------
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com

    Comment


    • #3
      I guess that Wesley works under Win9x.
      Under Win2000 nothing happends "except" that CPU is busy 100%.

      Wesley, once again --
      following is able to kill any PC
      Code:
         While (IsFalse ListenClose&) And (LBR$ <> "x")
            If (IsFalse ListenClose&) And (Comm(#hComm, RxQue) = 0 ) Then Iterate Loop
      If nothing to do, you should give another tasks to work.
      Change to
      Code:
         While (IsFalse ListenClose&) And (LBR$ <> "x")
            If (IsFalse ListenClose&) And (Comm(#hComm, RxQue) = 0 ) Then Sleep 1: Iterate Loop
      and look CPU usage.

      [This message has been edited by Semen Matusovski (edited February 22, 2001).]

      Comment


      • #4
        Thank you Semen. I have changed my code accordingly and appreciate your input. Furthermore,
        I appreciate the patience that you (and others like you) show towards newbees such as myself.
        I just hope that Lance never decides to put a "post limit" into place .

        Wesley

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


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

        Comment


        • #5
          I see this message a lot. It almost always happens when I am trying to
          compile a DLL, and had previously used the DLL from the Debugger.

          If I execute my main exe in the Debugger, and the debugger intercepts a
          crash, and I then close the debugger, I will get this message when I try to
          re-compile any DLL's which were open at the time.

          I have to exit the IDE and start over.

          If I compile the DLL and EXE, then execute them externally to the IDE and
          debugger, i do not get this message.


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

          John Kovacich
          Thanks,

          John Kovacich
          Ivory Tower Software

          Comment

          Working...
          X