ANSI C in AutoIt

  • Hi @ all

    brauch mal n paar Profis hier !!

    sollte diesen Ansi C Code in Auto It zum laufen kriegen.

    Spoiler anzeigen

    /*********************************************************************
    *
    * ANSI C Example program:
    * ReadDigPort.c
    *
    * Example Category:
    * DI
    *
    * Description:
    * This example demonstrates how to read values from a digital
    * input port.
    *
    * Instructions for Running:
    * 1. Select the digital port on the DAQ device to be read.
    * Note: The Data Read indicator is in hexadecimal.
    *
    * Steps:
    * 1. Create a task.
    * 2. Create a Digital Input channel. Use one channel for all
    * lines. In this case, the port itself acts as an individual
    * channel.
    * 3. Call the Start function to start the task.
    * 4. Read the digital data. This read function reads a single
    * sample of digital data on demand, so no timeout is necessary.
    * 5. Call the Clear Task function to clear the Task.
    * 6. Display an error if any.
    *
    * I/O Connections Overview:
    * Make sure your signal input terminals match the Port I/O
    * Control. In this case wire your digital signals to the first N
    * digital lines on your DAQ Device.
    *
    *********************************************************************/

    #include <stdio.h>
    #include <NIDAQmx.h>

    #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

    int main(void)
    {
    int32 error=0;
    TaskHandle taskHandle=0;
    uInt32 data;
    char errBuff[2048]={'\0'};
    int32 read;

    /*********************************************/
    // DAQmx Configure Code
    /*********************************************/
    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateDIChan(taskHandle,"Dev1/port0","",DAQmx_Val_ChanForAllLines));

    /*********************************************/
    // DAQmx Start Code
    /*********************************************/
    DAQmxErrChk (DAQmxStartTask(taskHandle));

    /*********************************************/
    // DAQmx Read Code
    /*********************************************/
    DAQmxErrChk (DAQmxReadDigitalU32(taskHandle,1,10.0,DAQmx_Val_GroupByChannel,&data,1,&read,NULL));

    printf("Data acquired: 0x%X\n",data);

    Error:
    if( DAQmxFailed(error) )
    DAQmxGetExtendedErrorInfo(errBuff,2048);
    if( taskHandle!=0 ) {
    /*********************************************/
    // DAQmx Stop Code
    /*********************************************/
    DAQmxStopTask(taskHandle);
    DAQmxClearTask(taskHandle);
    }
    if( DAQmxFailed(error) )
    printf("DAQmx Error: %s\n",errBuff);
    printf("End of program, press Enter key to quit\n");
    getchar();
    return 0;
    }

    hab schon mal angefangen aber sehe kaum chancen, weil ich ANSI C nicht kenne

    Spoiler anzeigen

    #cs ----------------------------------------------------------------------------


    ANSI C Example program:
    ReadDigPort.c

    Example Category:
    DI

    Description:
    This example demonstrates how to read values from a digital
    input port.

    Instructions for Running:
    1. Select the digital port on the DAQ device to be read.
    Note: The Data Read indicator is in hexadecimal.

    Steps:
    1. Create a task.
    2. Create a Digital Input channel. Use one channel for all
    lines. In this case, the port itself acts as an individual
    channel.
    3. Call the Start function to start the task.
    4. Read the digital data. This read function reads a single
    sample of digital data on demand, so no timeout is necessary.
    5. Call the Clear Task function to clear the Task.
    6. Display an error if any.

    I/O Connections Overview:
    Make sure your signal input terminals match the Port I/O
    Control. In this case wire your digital signals to the first N
    digital lines on your DAQ Device.

    #ce ----------------------------------------------------------------------------

    ;#include <stdio.h> ; fällt glaube ich weg, da nicht benötigt in autoit
    #include <NIDAQmx.h> !! ?? kenn ich nicht .. scheint aber wichtig zu sein ..

    #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) then _Error(); else ; ?? absolut keine ahnung ..

    ; main

    Global $error = 0 ; int32
    Global $taskHandle = 0 ; TaskHandle
    Global $data ; uInt32
    Global $errBuff[2048] = '\0'; char
    Global $read ; int32

    ;----------------------------------------------

    ; DAQmx Configure Code

    DAQmxErrChk(DAQmxCreateTask("", &taskHandle));
    DAQmxErrChk(DAQmxCreateDIChan(taskHandle, "Dev1/port0", "", DAQmx_Val_ChanForAllLines));

    ;----------------------------------------------

    ; DAQmx Start Code

    DAQmxErrChk(DAQmxStartTask(taskHandle));

    ;----------------------------------------------

    ; DAQmx Read Code

    DAQmxErrChk(DAQmxReadDigitalU32(taskHandle, 1, 10.0, DAQmx_Val_GroupByChannel, &data, 1, &read, NULL));

    ;----------------------------------------------


    MsgBox(0, "", "Data acquired: 0x%X\n" & $data);


    Exit


    Func _Error()

    If DAQmxFailed($error) Then
    DAQmxGetExtendedErrorInfo($errBuff, 2048);

    ElseIf $taskHandle = 0 Then

    ;----------------------------------------------

    ; DAQmx Stop Code

    DAQmxStopTask($taskHandle);
    DAQmxClearTask($taskHandle);

    ;----------------------------------------------

    ;### Tidy Error: If/ElseIf statement without a then..
    ElseIf DAQmxFailed($error)
    MsgBox(0, "DAQmx Error: %s\n", $errBuff);


    EndIf


    ;printf("End of program, press Enter key to quit\n");
    ;getchar();

    Return 0;

    EndFunc ;==>_Error

    ich denke mal dass die include zwingend erforderlich ist, kann ich diese auch in autoit anbinden =?
    oder muss ich die dann auch neu schreiben ?

    quelle folgt ... http://www.fileuploadx.de/282213

    .. vielleicht kann mir ja jemand helfen ..

    danke !!

    Einmal editiert, zuletzt von vivus (11. November 2009 um 14:15)

  • Du musst erstens das Include nach AutoIt übersetzen (Stichworte: DLLOpen und DLLCall)
    Dann musst du auch das Programm neu schreiben, z.B. kann AutoIt kein define und auch kein goto.

  • kann man nicht aus der "NIDAQmx.h" .. irgend wie ne dll compilieren ?!

    die ich dann mit dll open ( dll call ) ansprechen kann ?!

    hab mir mal die "NIDAQmx.h" angeschaut .. ist ja ne halbe biebel ..

    .. krieg ich nie hin ..

  • kann man nicht aus der "NIDAQmx.h" .. irgend wie ne dll compilieren ?!

    die ich dann mit dll open ( dll call ) ansprechen kann ?!

    hab mir mal die "NIDAQmx.h" angeschaut .. ist ja ne halbe biebel ..

    .. krieg ich nie hin ..


    Ich glaube dass es bereits eine DLL gibt und die NIDAQmx.h gibt nur die Konstanten und die Funktionsaufrufe an. Diese kannst du nicht in eine DLL kompilieren, sondern musst sie in AutoIt übersetzen.

  • danke ! für die Antwort !!

    .. also wie mache ich weiter ..

    hab jetzt mir mal des komplette *.h file durchgelesen .. ( überflogen )

    aber keinen verweis auf eine DLL gefunden ..

    müsste ja dann irgend wo dort drin stehen.. ? oder ..

    des meiste sind einfache Zuweisungen ..

    würde mir ja wirklich die mühe machen es um zu schreiben, wenn ich danach wüste, dass es funktioniert ..

    ..

    geschweige denn sollte ich erst wissen , ob ich es überhaupt richtig übersetze..

  • ALSO :

    ziel ist es eine National Instrument USB i/o card an zu sprechen .. ..

    Handelt sich um die USB 6501 ( 24 I/O )

    natürlich habe ich diese karte gewählt, weil sie die billigste, dieser USB Familie ist.

    mit der " NIDAQmx.h " sollte es aber möglich sein, jede Karte an zu sprechen.

    deshalb glaube ich, ist dieses file auch soooo groß !!

    wirklich brauchn tut man ja glaube ich "nur" 5 befehle für dieses USB-Board.

    1) verbindung aufbauen ..

    2) setup

    3) ports lesen

    4) ports schreiben

    5) verbindung trennen

    .. alles andere wäre für mich jetzt mal zweitrangig ..

    wichtig ist erst mal, dass überhaupt irgend etwas blinkt !! und ich einen wert oder einen zustand einlesen kann ..

    hab auch schon jedes auffindbare Forum durchforstet. das einzige was man zum Thema Ni und AutoIt findet ist das VISA udf.

    .. was auch sicher irgend wie funktioniert.. aber ich glaube nicht, mit dem USB board.

    zumindest laut NI-HP..

    .. oojee .. wird ne ggaannz harte NUSS !!