Jump to content

DLL callback application crash with "Variable used without being declared"


Recommended Posts

I spoke too soon, I finally had a crash with your test code TheXman. What bother me is that it doesn't show any exit error code...

From 20:39:03 to 20:53:17

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "D:\Users\theshadow\Documents\AutoIT\IPS_AE_manager\IPS_AE_manager_v0_1\test.au3" /UserParams    
+>20:39:02 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0)  Keyboard:0000080C  OS:WIN_10/2009  CPU:X64 OS:X64  Environment(Language:040C)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\theshadow\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\theshadow\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:D:\Users\theshadow\Documents\AutoIT\IPS_AE_manager\IPS_AE_manager_v0_1\test.au3
+>20:39:03 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "D:\Users\theshadow\Documents\AutoIT\IPS_AE_manager\IPS_AE_manager_v0_1\test.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
20:39:03.389    
20:39:03.389    Callback enter
20:39:03.389    $type: 1
20:39:03.389    $data: {"fwversion" : "", "ips" : "0", "dcin" : "0", "battery" : "0", "inputlostdelay" : "0", "cutoffdelay" : "0", "batterylife" : "0", "batteryvoltage" : "0", "maxtemperature" : "", "temperature" : "", "capacity" : "0", "cyclecount" : "0", "ManufactureDate" : "", "ManufactureName" : "", "DesignCapacity" : "0", "DesignVoltage" : "0"}
20:39:03.390    Callback exit
20:39:03.406    Main Process start
20:39:04.811    
20:39:04.811    Callback enter
20:39:04.811    $type: 1
20:39:04.811    $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "1", "battery" : "1", "inputlostdelay" : "0", "cutoffdelay" : "0", "batterylife" : "0", "batteryvoltage" : "0", "maxtemperature" : "", "temperature" : "", "capacity" : "92", "cyclecount" : "0", "ManufactureDate" : "2020-06-23", "ManufactureName" : "", "DesignCapacity" : "0", "DesignVoltage" : "0"}
20:39:04.811    Callback exit
20:39:12.446    
20:39:12.446    Callback enter
20:39:12.446    $type: 0
20:39:12.446    $data: DC-IN is Losted
20:39:12.446    Callback exit
20:39:12.848    
20:39:12.848    Callback enter
20:39:12.848    $type: 1
20:39:12.848    $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "0", "battery" : "1", "inputlostdelay" : "30", "cutoffdelay" : "1", "batterylife" : "0", "batteryvoltage" : "0", "maxtemperature" : "33.65", "temperature" : "33.65", "capacity" : "92", "cyclecount" : "0", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
20:39:12.848    Callback exit
20:39:13.852    
20:39:13.852    Callback enter
20:39:13.852    $type: 1
20:39:13.852    $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "1", "battery" : "1", "inputlostdelay" : "30", "cutoffdelay" : "1", "batterylife" : "1251", "batteryvoltage" : "0", "maxtemperature" : "33.65", "temperature" : "33.65", "capacity" : "92", "cyclecount" : "0", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
20:39:13.852    Callback exit

...

20:53:14.334    Callback enter
20:53:14.334    $type: 1
20:53:14.334    $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "0", "battery" : "1", "inputlostdelay" : "30", "cutoffdelay" : "1", "batterylife" : "1665", "batteryvoltage" : "15698", "maxtemperature" : "33.65", "temperature" : "33.55", "capacity" : "92", "cyclecount" : "5", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
20:53:14.334    Callback exit
20:53:15.338    
20:53:15.338    Callback enter
20:53:15.338    $type: 1
20:53:15.338    $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "1", "battery" : "1", "inputlostdelay" : "30", "cutoffdelay" : "1", "batterylife" : "1665", "batteryvoltage" : "15698", "maxtemperature" : "33.65", "temperature" : "33.55", "capacity" : "92", "cyclecount" : "5", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
20:53:15.338    Callback exit
20:53:15.940    
20:53:15.940    Callback enter
20:53:15.940    $type: 0
20:53:15.940    $data: DC-IN is Losted
20:53:15.940    Callback exit
20:53:16.343    
20:53:16.343    Callback enter
20:53:16.343    $type: 1
20:53:16.343    $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "0", "battery" : "1", "inputlostdelay" : "30", "cutoffdelay" : "1", "batterylife" : "1665", "batteryvoltage" : "15698", "maxtemperature" : "33.65", "temperature" : "33.55", "capacity" : "92", "cyclecount" : "5", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
20:53:16.343    Callback exit
20:53:17.346    
20:53:17.346    Callback enter
20:53:17.346    $type: 1
20:53:17.346    $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "1", "battery" : "1", "inputlostdelay" : "30", "cutoffdelay" : "1", "batterylife" : "2664", "batteryvoltage" : "15698", "maxtemperature" : "33.65", "temperature" : "33.55", "capacity" : "92", "cyclecount" : "5", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
20:53:17.346    Callback exit
+>20:53:17 AutoIt3.exe ended.rc:0
+>20:53:17 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 855.3

 

Edited by oli_the_true_one
Link to comment
Share on other sites

Were you able to successfully port the SDK's IPS-AE sample to AutoIt?  Did you try setting changing the UPS settings to the ones in the sample to see if maybe it provides more stable results?  It sets the input lost delay to 5 minutes where your UPS is set to 30 seconds.  It also sets the cutoff delay to 5 seconds where your UPS is set to 1 second.  Maybe those settings, or one of the others, have something to do with how often it reports or why the script silently dies?  Maybe slowing down the interval in which it reports or does a callback may make it more stable.  I don't know.

I've never used or even heard of EAPI before.  Most importantly, I have no way to test it myself.  Therefore, I can only guess as to what the issue or issues may be, and I try not to guess or make assumptions, if possible.  All I know for sure is that you are using a R&D version of a set of APIs, that aren't available to the public on their public site and you are using the APIs to interface with an external UPS, and that AutoIt is successfully processing the callbacks (up to a point).  The first 2 "knowns" are pretty significant because I can't rule either one of them out as a root cause.  And because I can't rule out issues with the first 2, I can't definitively say that AutoIt or your AutoIt logic is an issue.  Given all of that, I'd say that its up to you to do  some more digging/research, trouble shooting, and a bit of trial & error in order to see if you can get it working.  Hopefully, you are more successful in finding additional EAPI samples on the web than I was.  🙂  Good luck!

 

Edit:

Where is this script running?  Is it running in a VM or a physical PC?  Is the machine going into a power saving mode or to sleep?  Is the UPS' connected directly to a COM port or is it using a USB-to-COM cable?  If USB-to-COM, is the USB port set to allow itself to be turned off to save power?  Those are just some of the questions that popped into my head because the script appears to silently end around 15 minutes after being launched.  10-15 minutes is a common power saving timeout settings.  Just a thought...

 

Edited by TheXman
Link to comment
Share on other sites

8 hours ago, TheXman said:

Were you able to successfully port the SDK's IPS-AE sample to AutoIt?  Did you try setting changing the UPS settings to the ones in the sample to see if maybe it provides more stable results?  It sets the input lost delay to 5 minutes where your UPS is set to 30 seconds.  It also sets the cutoff delay to 5 seconds where your UPS is set to 1 second.  Maybe those settings, or one of the others, have something to do with how often it reports or why the script silently dies?  Maybe slowing down the interval in which it reports or does a callback may make it more stable.  I don't know.

I've never used or even heard of EAPI before.  Most importantly, I have no way to test it myself.  Therefore, I can only guess as to what the issue or issues may be, and I try not to guess or make assumptions, if possible.  All I know for sure is that you are using a R&D version of a set of APIs, that aren't available to the public on their public site and you are using the APIs to interface with an external UPS, and that AutoIt is successfully processing the callbacks (up to a point).  The first 2 "knowns" are pretty significant because I can't rule either one of them out as a root cause.  And because I can't rule out issues with the first 2, I can't definitively say that AutoIt or your AutoIt logic is an issue.  Given all of that, I'd say that its up to you to do  some more digging/research, trouble shooting, and a bit of trial & error in order to see if you can get it working.  Hopefully, you are more successful in finding additional EAPI samples on the web than I was.  🙂  Good luck!

 

Edit:

Where is this script running?  Is it running in a VM or a physical PC?  Is the machine going into a power saving mode or to sleep?  Is the UPS' connected directly to a COM port or is it using a USB-to-COM cable?  If USB-to-COM, is the USB port set to allow itself to be turned off to save power?  Those are just some of the questions that popped into my head because the script appears to silently end around 15 minutes after being launched.  10-15 minutes is a common power saving timeout settings.  Just a thought...

 

The input lost delay parameter is in seconds and its value goes from 3 to 360. The cutoff delay is in minutes and its value goes from 1 to 10.

On my developement PC, I use a USB-Serial converter and on the target PC there is a native Serial port. Both have the same crash so it is not related to the converter. It is running on physical PC.

What I would like to do now is to put some logs inside the DLLCallbackRegister to see if it is well trying to run the callback inside the callback and I think it is from what I see in the console. But since I am not able to do that I'm stuck. I could try to close the DLL/unregister the callback when I start the callback, I'm not sure it's going to work and I don't like this solution.

Also, their compiled example in X86 never crashed, after several hours of tests in the same conditions. So this is another hint that something is wrong on the AutoIT side (either my code or the DLL functions).

Thank you very much for the time you spent analyzing all my data and for your suggestions, I appreciate it.

Link to comment
Share on other sites

Below is a slightly modified version of my previous example.  It adds a counter tag to the callback function's entry & exit log messages.  That should make it easier to identify entry/exit pairs.  I also added an OnExit function to hopefully catch and show the reason that the script exited.  It would be interesting to see what the exit reason shows.

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <Constants.au3>

Global $aResult
Global $hEAPIdll
Global $hAtCallback

_WriteLogLine("Main Process start")

HotKeySet("{ESC}","_Terminate")

$hEAPIdll    = DllOpen("D:\EAPI\X86\EAPI.dll")
$hAtCallback = DllCallbackRegister("_getIPSAEdata", "none:cdecl", "int;str")

OnAutoItExitRegister("_OnExit")

$aResult = DllCall($hEAPIdll, "DWORD:cdecl", "EApiUPSInitDev", _
                   "str", "COM3", _
                   "ptr", DllCallbackGetPtr($hAtCallback))

While 1
    Sleep(10)
WEnd

Func _Terminate()
    _WriteLogLine("Main Process exit")
    Exit
EndFunc

Func _getIPSAEdata($type, $data)
    Static $iCounter = 0

    $iCounter += 1

    _WriteLogLine()
    _WriteLogLine("Callback enter #" & $iCounter)
    _WriteLogLine("$type: " & $type & " / $data: " & $data)
    _WriteLogLine("Callback exit  #" & $iCounter)
EndFunc   ;==>_getIPSAEdata

Func _OnExit()
    Local $sExitReason = ""

    Switch @exitMethod
        Case $EXITCLOSE_NORMAL
            $sExitReason = "Normal"
        Case $EXITCLOSE_BYEXIT
            $sExitReason = "By Exit"
        Case $EXITCLOSE_BYCLICK
            $sExitReason = "By Click"
        Case $EXITCLOSE_BYLOGOFF
            $sExitReason = "By Logoff"
        Case $EXITCLOSE_BYSHUTDOWN
            $sExitReason = "By Shutdown"
        Case Else
            $sExitReason = "Unknown"
    EndSwitch

    DllClose($hEAPIdll)
    DllCallbackFree($hAtCallback)

    _WriteLogLine("Exit Reason: " & $sExitReason)
EndFunc

Func _WriteLogLine($sMsg = "")
    Local $sNow = @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC
    ConsoleWrite($sNow & @TAB & $sMsg & @CRLF)
EndFunc

 

Edited by TheXman
Link to comment
Share on other sites

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "D:\Users\theshadow\Documents\AutoIT\IPS_AE_manager\IPS_AE_manager_v0_1\test2.au3" /UserParams    
+>16:23:38 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0)  Keyboard:0000080C  OS:WIN_10/2009  CPU:X64 OS:X64  Environment(Language:040C)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\theshadow\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\theshadow\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  params:-w 3 -w 4 -w 5 -w 6 -d  from:C:\Program Files (x86)\AutoIt3  input:D:\Users\theshadow\Documents\AutoIT\IPS_AE_manager\IPS_AE_manager_v0_1\test2.au3
+>16:23:38 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "D:\Users\theshadow\Documents\AutoIT\IPS_AE_manager\IPS_AE_manager_v0_1\test2.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
16:23:38.795    Main Process start
16:23:38.803    
16:23:38.803    Callback enter #1
16:23:38.803    $type: 1 / $data: {"fwversion" : "", "ips" : "0", "dcin" : "0", "battery" : "0", "inputlostdelay" : "0", "cutoffdelay" : "0", "batterylife" : "0", "batteryvoltage" : "0", "maxtemperature" : "", "temperature" : "", "capacity" : "0", "cyclecount" : "0", "ManufactureDate" : "", "ManufactureName" : "", "DesignCapacity" : "0", "DesignVoltage" : "0"}
16:23:38.803    Callback exit  #1
16:23:40.226    
16:23:40.226    Callback enter #2
16:23:40.226    $type: 1 / $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "1", "battery" : "1", "inputlostdelay" : "0", "cutoffdelay" : "0", "batterylife" : "0", "batteryvoltage" : "0", "maxtemperature" : "", "temperature" : "", "capacity" : "100", "cyclecount" : "0", "ManufactureDate" : "2020-06-23", "ManufactureName" : "", "DesignCapacity" : "0", "DesignVoltage" : "0"}
16:23:40.226    Callback exit  #2
16:23:40.628    
16:23:40.628    Callback enter #3
16:23:40.628    $type: 0 / $data: DC-IN is Losted
16:23:40.628    Callback exit  #3
16:23:41.231    
16:23:41.231    Callback enter #4
16:23:41.231    $type: 1 / $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "0", "battery" : "1", "inputlostdelay" : "0", "cutoffdelay" : "0", "batterylife" : "0", "batteryvoltage" : "0", "maxtemperature" : "29.05", "temperature" : "29.05", "capacity" : "100", "cyclecount" : "0", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "0", "DesignVoltage" : "0"}
16:23:41.231    Callback exit  #4
16:23:42.235    
16:23:42.235    Callback enter #5
16:23:42.235    $type: 1 / $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "1", "battery" : "1", "inputlostdelay" : "0", "cutoffdelay" : "0", "batterylife" : "0", "batteryvoltage" : "0", "maxtemperature" : "29.05", "temperature" : "29.05", "capacity" : "100", "cyclecount" : "0", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "0"}
16:23:42.235    Callback exit  #5
16:23:42.637    
16:23:42.637    Callback enter #6
16:23:42.637    $type: 0 / $data: DC-IN is Losted
16:23:42.637    Callback exit  #6
16:23:43.239    
16:23:43.239    Callback enter #7
16:23:43.239    $type: 1 / $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "0", "battery" : "1", "inputlostdelay" : "0", "cutoffdelay" : "0", "batterylife" : "0", "batteryvoltage" : "0", "maxtemperature" : "29.05", "temperature" : "29.05", "capacity" : "100", "cyclecount" : "0", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
16:23:43.239    Callback exit  #7
16:23:44.242    
16:23:44.242    Callback enter #8
16:23:44.242    $type: 1 / $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "1", "battery" : "1", "inputlostdelay" : "0", "cutoffdelay" : "0", "batterylife" : "0", "batteryvoltage" : "0", "maxtemperature" : "29.05", "temperature" : "29.05", "capacity" : "100", "cyclecount" : "0", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
16:23:44.242    Callback exit  #8
16:23:44.644    
16:23:44.644    Callback enter #9
16:23:44.644    $type: 0 / $data: DC-IN is Losted
16:23:44.644    Callback exit  #9
16:23:45.247    
16:23:45.247    Callback enter #10
16:23:45.247    $type: 1 / $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "0", "battery" : "1", "inputlostdelay" : "0", "cutoffdelay" : "0", "batterylife" : "0", "batteryvoltage" : "0", "maxtemperature" : "29.05", "temperature" : "29.05", "capacity" : "100", "cyclecount" : "0", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
16:23:45.247    Callback exit  #10

...

16:26:30.102    
16:26:30.102    Callback enter #265
16:26:30.102    $type: 1 / $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "1", "battery" : "1", "inputlostdelay" : "30", "cutoffdelay" : "1", "batterylife" : "2353", "batteryvoltage" : "16355", "maxtemperature" : "29.05", "temperature" : "29.05", "capacity" : "100", "cyclecount" : "7", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
16:26:30.102    Callback exit  #265
16:26:30.505    
16:26:30.505    Callback enter #266
16:26:30.505    $type: 0 / $data: DC-IN is Losted
16:26:30.505    Callback exit  #266
16:26:31.109    
16:26:31.109    Callback enter #267
16:26:31.109    $type: 1 / $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "0", "battery" : "1", "inputlostdelay" : "30", "cutoffdelay" : "1", "batterylife" : "2353", "batteryvoltage" : "16354", "maxtemperature" : "29.05", "temperature" : "29.05", "capacity" : "100", "cyclecount" : "7", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
16:26:31.109    Callback exit  #267
16:26:32.114    
16:26:32.114    Callback enter #268
16:26:32.114    $type: 1 / $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "1", "battery" : "1", "inputlostdelay" : "30", "cutoffdelay" : "1", "batterylife" : "2353", "batteryvoltage" : "16354", "maxtemperature" : "29.05", "temperature" : "29.05", "capacity" : "100", "cyclecount" : "7", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
16:26:32.114    Callback exit  #268
16:26:32.515    
16:26:32.515    Callback enter #269
16:26:32.515    $type: 0 / $data: DC-IN is Losted
16:26:32.515    Callback exit  #269
16:26:33.117    
16:26:33.117    Callback enter #270
16:26:33.117    $type: 1 / $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "0", "battery" : "1", "inputlostdelay" : "30", "cutoffdelay" : "1", "batterylife" : "2353", "batteryvoltage" : "16354", "maxtemperature" : "29.05", "temperature" : "29.05", "capacity" : "100", "cyclecount" : "7", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
16:26:33.117    Callback exit  #270
16:26:34.123    
16:26:34.123    Callback enter #271
16:26:34.123    $type: 1 / $data: {"fwversion" : "VER001.116", "ips" : "1", "dcin" : "1", "battery" : "1", "inputlostdelay" : "30", "cutoffdelay" : "1", "batterylife" : "2353", "batteryvoltage" : "16354", "maxtemperature" : "29.05", "temperature" : "29.05", "capacity" : "100", "cyclecount" : "7", "ManufactureDate" : "2020-06-23", "ManufactureName" : "FUCO", "DesignCapacity" : "1750", "DesignVoltage" : "14400"}
16:26:34.123    Callback exit  #271
16:26:34.525    
16:26:34.525    Callback enter #272
16:26:34.525    $type: 0 / $data: DC-IN is Losted
16:26:34.525    Callback exit  #272
16:26:34.525    
16:26:34.525    Callback enter #273
+>16:26:34 AutoIt3.exe ended.rc:0
+>16:26:34 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 177.3

AutoIT is not executing _OnExit() when it crashes 🥺

Link to comment
Share on other sites

10 minutes ago, oli_the_true_one said:

AutoIT is not executing _OnExit() when it crashes

That is very interesting!  This time it silently ended after only 3 minutes.  I think the last time was closer to 15 minutes.  I wonder why it ended so much sooner?

I wish I knew more about the AutoIt internals to be able to know under what conditions AutoIt could silently crash and show an rc = 0.  ;)

I wonder if you would see the same results if the sample was compiled as a CUI executable and run from within a cmd console?

Edited by TheXman
Link to comment
Share on other sites

Yes, indeed. It's completly random. Yesterday, it lasted more than 30 minutes. It looks like (but  maybe it's just a coincidence), it lasts longer if I am not doing other things with the PC (internet browsing, video playing, etc).

Tomorrow I will run a compiled version in the console and check the behavior (I didn't take the UPS home today).

+++

Link to comment
Share on other sites

  • Developers
1 hour ago, oli_the_true_one said:

Notice how Callback #10 comes in the middle of Callback #9 😶

Isn't that the whole purpose of using call back so it runs Async and can handle multiple requests?

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I would try this callback method for the next: 

Maybe this gives more feedback when crashing or it does not crash at all.

The UDF has to be changed a bit because @unicode does not exist anymore.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

 

2 hours ago, JockoDundee said:

And where’s Callback exit #3?

Yes, indeed. I didn't see that one.

1 hour ago, Jos said:

Isn't that the whole purpose of using call back so it runs Async and can handle multiple requests?

Jos 

Shouldn't it be queued ?

1 hour ago, funkey said:

I would try this callback method for the next: 

Maybe this gives more feedback when crashing or it does not crash at all.

The UDF has to be changed a bit because @unicode does not exist anymore.

Thanks, I will have a look at this UDF

Edited by oli_the_true_one
Link to comment
Share on other sites

1 minute ago, oli_the_true_one said:

Shouldn't it be queued ?

If you set a HotKey “callback” for the SPACEBAR and then hold down the SPACEBAR  and let it typomatic 10 spaces in a second or two, faster than the function can process each key, what happens is this:

each new SPACEBAR event interrupts the execution of the previous one, calling the callback function again (with its own local var copy).  When it finally catches up, then it works it’s way backwards, finishing with the first event it didn’t have time to process.

I see no reason to think this callback wouldn’t work the same.

Practically what this means is the routines have to be written carefully with respect to global variables so as not to get confused.

Code hard, but don’t hard code...

Link to comment
Share on other sites

The oddest thing that I see in the log is the last message before it ends.  It shows "Main process start" again.  How is that possible?  Why did that happen?  :think:

Edited by TheXman
Link to comment
Share on other sites

the pointer to the internal stack of the return addresses appears misaligned if there are overlapping callbacks, that is, if a new callback is activated before the end of the previous call.

could you try this little solution workaround attempt? I simply added four lines marked "; <----" which should "exit" the callback call immediately if one is already running.

I know it's a little naive but it's also cheap so it might be worth a try ....

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <Constants.au3>

Global $aResult
Global $hEAPIdll
Global $hAtCallback
Global $bIsCallBackActive = False ;    <----

_WriteLogLine("Main Process start")

HotKeySet("{ESC}", "_Terminate")

$hEAPIdll = DllOpen("D:\EAPI\X86\EAPI.dll")
$hAtCallback = DllCallbackRegister("_getIPSAEdata", "none:cdecl", "int;str")

OnAutoItExitRegister("_OnExit")

$aResult = DllCall($hEAPIdll, "DWORD:cdecl", "EApiUPSInitDev", _
        "str", "COM3", _
        "ptr", DllCallbackGetPtr($hAtCallback))

While 1
    Sleep(10)
WEnd

Func _Terminate()
    _WriteLogLine("Main Process exit")
    Exit
EndFunc   ;==>_Terminate

Func _getIPSAEdata($type, $data)
    If $bIsCallBackActive Then Return ; <----
    $bIsCallBackActive = True ;         <----
    Static $iCounter = 0
    $iCounter += 1

    _WriteLogLine()
    _WriteLogLine("Callback enter #" & $iCounter)
    _WriteLogLine("$type: " & $type & " / $data: " & $data)
    _WriteLogLine("Callback exit  #" & $iCounter)
    $bIsCallBackActive = False ;        <----
EndFunc   ;==>_getIPSAEdata

Func _OnExit()
    Local $sExitReason = ""

    Switch @exitMethod
        Case $EXITCLOSE_NORMAL
            $sExitReason = "Normal"
        Case $EXITCLOSE_BYEXIT
            $sExitReason = "By Exit"
        Case $EXITCLOSE_BYCLICK
            $sExitReason = "By Click"
        Case $EXITCLOSE_BYLOGOFF
            $sExitReason = "By Logoff"
        Case $EXITCLOSE_BYSHUTDOWN
            $sExitReason = "By Shutdown"
        Case Else
            $sExitReason = "Unknown"
    EndSwitch

    DllClose($hEAPIdll)
    DllCallbackFree($hAtCallback)

    _WriteLogLine("Exit Reason: " & $sExitReason)
EndFunc   ;==>_OnExit

Func _WriteLogLine($sMsg = "")
    Local $sNow = @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC
    ConsoleWrite($sNow & @TAB & $sMsg & @CRLF)
EndFunc   ;==>_WriteLogLine

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

To conclude the subject,

I did try the DLL with Qt and I've run into similar crashes with some simple variables copy inside the callback. The reason, that is surely the same in AutoIT, is a race condition between the callback, subcallback and main process for these variables. My issue was resolved by using a signal and a slot to pass the callback data to my process function.

I don't think AutoIT is able / does not give the tools to manage that kind of situation (correct me if I am wrong).

Thank you all for your answers and for your guidance !

+++

oli

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...