Menu

Callback issues

2016-03-24
2016-04-05
  • Bert Kortenbach

    Bert Kortenbach - 2016-03-24

    I am using the client verion of Snap7 from Delphi 2007.
    I created a callback function and noticed that it get's called twice sometimes (?)

    *procedure ClientCompletion(usrPtr : pointer; opCode, opResult : integer); stdcall;
    begin
    //Temporary store resultcodes (threadsafe by waiting until "scantasks" picks them up and using a mutex)
    if WaitForSingleObject(Snap7ThreadMutex, INFINITE) <> WAITOBJECT0 then
    RaiseLastOSError;
    try
    cTaskScheduler(usrPtr^).mCallbackOpCode :=opCode;
    cTaskScheduler(usrPtr^).mCallbackOpResult:=opResult;
    finally
    ReleaseMutex(Snap7ThreadMutex)
    end;
    end;
    *

    Both cases with opResult=0 and opCode=1.
    What should I do with opCode? In the documenation of Snap7 I noticed that sometimes opResult gets checked for 0 and sometomes opCode (C# callback example).
    At the moment I am using opResult as the "error code" (0=success >0=error) and I don't use opCode...

     
  • Bert Kortenbach

    Bert Kortenbach - 2016-04-05

    I solved the problem. It had something to do with cTaskScheduler(usrPtr^) pointing to the wrong position in memory.
    However: The question about opCode remains. Anyone ?

     

Log in to post a comment.

MongoDB Logo MongoDB