Problem mit ErrorStdOut

  • Ich möchte eine externe DLL (für eine Motorsteuerung) aus Autoit heraus ansteuern.
    Nun ist es vom Aufruf abhängig, ob das Programm funktioniert oder nicht. Aus Scite heraus funktioniert es beispielsweise nicht, weil AutoIt3Wrapper es auf die "falsche" Weise aufruft.

    Spoiler anzeigen
    [autoit]

    $_C843_DLL = DllOpen("C843_GCS_DLL.dll")
    If $_C843_DLL = -1 Then
    ConsoleWrite("DLL could not be opened" & @CRLF)
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Connect to the first board
    $ID = _C843_Connect(1)
    If $ID < 0 Then
    ConsoleWrite("Connection Failed!" & @CRLF)
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Get the list of motors in the parameter files
    $Stages = _C843_qVST($ID)
    MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$Stages' & @lf & @lf & 'Return:' & @lf & $Stages) ;### Debug MSGBOX
    ConsoleWrite("qVST: " & $Stages & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    ; Get the last error
    $Error = _C843_GetError($ID)
    MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$Error' & @lf & @lf & 'Return:' & @lf & $Error) ;### Debug MSGBOX
    ConsoleWrite("GetError: " & $Error & " " & _C843_TranslateError($Error) & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    ; Disconnect from board
    _C843_CloseConnection($ID)

    [/autoit] [autoit][/autoit] [autoit]

    ; ****************************************************************************
    #Region DLL initialization and comm functions
    Func _C843_CloseConnection($Id)
    DllCall($_C843_DLL,"none","C843_CloseConnection","int",$Id)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _C843_Connect($BoardNumber)
    Local $aResult
    $aResult = DllCall($_C843_DLL,"int","C843_Connect","int",$BoardNumber)
    Return $aResult[0]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _C843_GetError($Id)
    Local $aResult
    $aResult = DllCall($_C843_DLL,"int","C843_GetError","int",$Id)
    Return $aResult[0]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _C843_TranslateError($ErrNr)
    local $tData, $aResult, $Return
    $tData = DllStructCreate("char[1024]")
    $aResult = DllCall($_C843_DLL,"int","C843_TranslateError","int",$ErrNr,"ptr",DllStructGetPtr ($tData),"int",1023)
    If $aResult[0] Then
    $Return = DllStructGetData($tData, 1)
    Else
    $Return = "Errormessage to long"
    EndIf
    $tData = 0
    Return $Return
    EndFunc
    #EndRegion

    [/autoit] [autoit][/autoit] [autoit]

    #Region general

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Function Name: _C843_qVST()
    ; Description::Get the names of the available stage types.
    ; Parameter(s):$Id - Id of the C843-board
    ; Return Value(s): Returns list of stages or "" in case of error
    ; @error Value(s):1 - Error Calling C843 DLL
    ; 2 - DLL returned an error
    ; Author(s): Hawkear (Holger Kuhn)
    ;
    ;===============================================================================
    ;
    Func _C843_qVST($Id)
    local $tData, $aResult, $Return
    $tData = DllStructCreate("char[8192]")

    [/autoit] [autoit][/autoit] [autoit]

    ;BOOL C843_FUNC_DECL C843_qVST(const int iId, char* buffer, const int maxlen);
    $aResult = DllCall($_C843_DLL,"int","C843_qVST","int",$Id,"ptr",DllStructGetPtr ($tData),"int",8191)

    [/autoit] [autoit][/autoit] [autoit]

    If @error > 0 Then
    $Return = ""
    SetError(1)
    Else
    If $aResult[0] Then
    $Return = DllStructGetData($tData, 1)
    Else
    $Return = ""
    SetError(2)
    EndIf
    EndIf
    $tData = 0
    Return $Return
    EndFunc
    #endregion

    [/autoit]

    Rufe ich das Programm mit /ErrorStdOut und vollem Pfad auf, dann funktioniert es nicht.

    Code
    C:\Programme\AutoIt3\autoit3.exe /ErrorStdOut D:\SVN\AutoIt\C843_Test.au3


    Rückgabe:

    Code
    qVST: 
    GetError: -1039 Could not open parameter file

    Anders funktioniert es

    Code
    C:\Programme\AutoIt3\autoit3.exe D:\SVN\AutoIt\C843_Test.au3
    C:\Programme\AutoIt3\autoit3.exe /ErrorStdOut C843_Test.au3
    C:\Programme\AutoIt3\autoit3.exe C843_Test.au3


    Rückgabe:

    Code
    qVST: C-136.10 
    C-136.10-PWM 
    <Lange Liste mit Motoren>
    
    
    GetError: 0 No error

    Was ist denn bei dem Aufruf mit /ErrorStdOut so gross anders?
    Hat jemand eine Idee, wie man das Problem umgehen kann?

    Ciao, Holger

    Einmal editiert, zuletzt von Hawkear (24. September 2009 um 10:22)

  • Als Workaround habe ich jetzt die AutoIt3Wrapper.au3 angepasst (Version 2.0.0.1 ab Zeile 1036)
    Ich würde aber trotzdem gerne wissen, was ErrorStdOut an der Umgebung ändert, dass eine externe DLL nicht mehr funktioniert.

    [autoit]


    ; Run your script
    $ScriptFile_In_Path = StringLeft($ScriptFile_In, StringInStr($ScriptFile_In, "\", 0, -1))
    $ScriptFile_In_File = StringMid($ScriptFile_In, StringInStr($ScriptFile_In, "\", 0, -1) + 1)
    $Pid = Run('"' & $AutoIT3_PGM & '" /ErrorStdOut "' & $ScriptFile_In_File & '" ' & $s_CMDLine, $ScriptFile_In_Path, -1, $STDERR_CHILD + $STDOUT_CHILD)

    [/autoit]

    Ciao, Holger