Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Aufruf von DLL-Funktionen unter WinCE 5.0

uloebich
2010-09-30
2010-10-13
  • uloebich - 2010-09-30

    Ich suche eine Möglichkeit, die Funktionen einer Drittanbieter-DLL unter WinCE 5.0 Core anzusprechen.
    Geht das mit CoDeSys 2.3 und wenn ja, wie?

    Gruß, U.

     
  • RolandWagner

    RolandWagner - 2010-10-13

    Hi,

    ich habe eine nicht-offizielle Anleitung dazu bekommen:

    Zitat:
    The following instructions provide the detailed steps required to create an external DLL that provides functionality to the 3S CoDeSys SP soft PLC running under
    Windows CE.
    a) In Embedded Visual C++, use the new project wizard to create an empty DLL project
    b) Create a C or C++ ++ source file for the primary interface functions
    c) Add the function prototypes as defined by the .h file generated by
    CoDeSys when you created the external library (copy from that file)
    d) Ensure the types are correct
    1. Replace IEC data type ‘BOOL’ by ‘char’
    2. Replace IEC data type ‘INT’ by ‘short’
    3. Replace IEC data type ‘SINT’ by ‘signed char’
    4. Replace IEC data type ‘BOOL’ by ‘char’
    5. Replace IEC data type ‘BOOL’ by ‘char’
    6.
    e) Create a method that returns a pointer to each function based on a
    provided name. This method is called by the runtime system to get a
    function pointer to the actual implementation. The method must take the
    following form:
    f) Add your interface methods as required, conforming to the function
    prototypes provided by the header file generated by CoDeSys.

    \#if __cplusplus
    externC” {
    \#endif
    _declspec(dllexport)
    void* GetFunctionByName(char* functionName)
    {
    // determine which function has been requested
    if(_stricmp(functionName, “Test) == 0)
    // return the address of the desired function
    return Test;
    else
    // add other function name tests here
    // no matching name, return NULL
    return NULL;
    }
    \#if __cplusplus
    }
    \#endif
    char Test(char text, int value)
    {
    TCHAR str[80];
    sprintf(str, “Function Test Called! Parameter: %s, %d”, text, value);
    MessageBox(NULL, str, (LPCSTR)””, MB_ICONEXCLAMATION | MB_OK);
    return TRUE;
    }
    

    3) Compile your source code into a DLL, perhaps named TestLib.dll, but the name is
    not critical.
    4) Copy your DLL into the C:\Windows\System32 directory so the system can find
    it.
    5) Add entries to the windows registry to indicate that the runtime system should
    load the additional DLL. Set the “Path” entry to the name of your DLL file.
    6) If the runtime system is currently running, stop and shutdown the runtime system
    and restart it to ensure the new DLL is included.

    [HKEY_LOCAL_MACHINE\SOFTWARE\3S-Smart Software Solutions GmbH\CoDeSys SP\PLC\External Dlls]
    "CheckExtRef"="Yes"
    [HKEY_LOCAL_MACHINE\SOFTWARE\3S-Smart Software Solutions GmbH\CoDeSys SP\PLC\External Dlls\.0]
    "Path"="TestLib"
    

    7) Returning to the CoDeSys programming environment, create a new project that
    will utilize the new function.
    In the new project, insert the previously created library:
    a) Select Window->Library Manager
    b) Select Insert->Additional Library
    c) In the presented File Chooser, navigate to the library file (TestLib.lib)
    created by CoDeSys when you exported your function definition as an
    external library. It will be someplace similar to:
    C:\Program Files\3S Software\CoDeSys V2.3\Library
    d) Double click the file to load the library into the project. The library will be
    shown in the Library Manager window, and the defined function should be
    available.
    9) Create a test program to invoke the external library function:
    a) Create a new program unit, using the default name PLC_PRG.
    b) Add a structured text (ST) program to the program unit, calling the
    external function.
    10) Test your new program:
    a) Ensure the runtime system is active.
    b) Create a new connection to the runtime system (if required)
    c) “Login” to the runtime system.
    d) When asked if the program should be downloaded, respond yes.
    e) The program should be successfully downloaded.
    f) Execute the program.
    g) The desired behavior should be observed.
    11) Celebrate!

    Wie gesagt: Das ist nicht-offiziell. Aber Du kannst ja hier kommentieren, ob und wie es geklappt hat.
    In jedem Fall hänge ich noch ein Beispiel an.

     

Log in to post a comment.