Forum > Beginners

Extend WiringPi wrapper "hwiringpi"

<< < (2/4) > >>

Mountaineer:
Hello ccrause,

it's me again!  :-[

Got an error (see below):

Projekt kompilieren, Ziel: project1: Exit code 1, Fehler: 1, Hinweise: 1
unit1.pas(61,27) Error: Call by var for arg no. 3 has to match exactly: Got "<address of procedure;StdCall>" expected "<procedure variable type of procedure;CDecl>"
hwiringpi_DHA.pas(73,10) Hint: Found declaration: wiringPiISR(LongInt;LongInt;var TIsrProc):LongInt; CDecl;

Please help!

ccrause:

--- Quote from: Mountaineer on May 09, 2021, 09:49:47 am ---Hello ccrause,

it's me again!  :-[

Got an error (see below):

Projekt kompilieren, Ziel: project1: Exit code 1, Fehler: 1, Hinweise: 1
unit1.pas(61,27) Error: Call by var for arg no. 3 has to match exactly: Got "<address of procedure;StdCall>" expected "<procedure variable type of procedure;CDecl>"
hwiringpi_DHA.pas(73,10) Hint: Found declaration: wiringPiISR(LongInt;LongInt;var TIsrProc):LongInt; CDecl;

Please help!

--- End quote ---

My apologies, I typed the one version that doesn't work (and also didn't test it, hence all the typo's in the code) :-[ Below a couple of different versions that does compile (at least pass syntax check, I am not linking the executable).  The example also tries to call the wiringPiISR functions with an incorrect procedure signature as a parameter, which the compiler should reject with an error.  This is why I prefer to use typed parameters.

Note that the exact method of passing a procedure as a parameter differ slightly depending on the compiler mode.  In mode ObjFPC or Delphi the following should work:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; type  TISRProc = procedure(); cdecl; function wiringPiISR_1(pin: longint; edgeType: longint; const callback: TISRProc): longint; cdecl; external;function wiringPiISR_2(pin: longint; edgeType: longint; callback: TISRProc): longint; cdecl; external;function wiringPiISR_3(pin: longint; edgeType: longint; constref callback: TISRProc): longint; cdecl; external; procedure correctProc; cdecl; beginend; procedure wrongProc(i: integer); cdecl;beginend; begin  // These calls compile  wiringPiISR_1(1, 1, @correctProc);  wiringPiISR_2(1, 1, @correctProc);  wiringPiISR_3(1, 1, @correctProc);   // These calls do not compile  wiringPiISR_1(1, 1, @wrongProc);  wiringPiISR_2(1, 1, @wrongProc);  wiringPiISR_3(1, 1, @wrongProc);end.
The version below only works in mode Delphi:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; type  TISRProc = procedure(); cdecl; function wiringPiISR_1(pin: longint; edgeType: longint; const callback: TISRProc): longint; cdecl; external;function wiringPiISR_2(pin: longint; edgeType: longint; callback: TISRProc): longint; cdecl; external;function wiringPiISR_3(pin: longint; edgeType: longint; constref callback: TISRProc): longint; cdecl; external; procedure correctProc; cdecl; // not necessary since no parameters are passed.beginend; procedure wrongProc(i: integer); cdecl;beginend; begin  // These calls compile  wiringPiISR_1(1, 1, correctProc);  wiringPiISR_2(1, 1, correctProc);  wiringPiISR_3(1, 1, correctProc);   // These calls do not compile  wiringPiISR_1(1, 1, wrongProc);  wiringPiISR_2(1, 1, wrongProc);  wiringPiISR_3(1, 1, wrongProc);end.

Mountaineer:
Hello ccrause,
thank you for your reply!
I tried to use your new code but got this error (same at all of the 3 versions): %)

Projekt kompilieren, Ziel: project1: Exit code 1, Fehler: 1, Warnungen: 2
project1.lpr(23,0) Warning: "crtbegin.o" not found, this will probably cause a linking failure
project1.lpr(23,0) Warning: "crtend.o" not found, this will probably cause a linking failure
project1.lpr(23,0) Error: Error while linking

Please help!

ccrause:

--- Quote from: Mountaineer on May 09, 2021, 06:15:03 pm ---project1.lpr(23,0) Error: Error while linking[/i]

--- End quote ---
Progress of some sorts. Seems like the linker either cannot locate the library, or the new function you are trying to wrap.

Where is the library located that contains the new wiringPiISR function, and how are you specifying the library name and location to the compiler? 

Can you compile and run the original code that you are trying to modify?

Did you notice there is already an implementation that contains the wiringPiISR definition: https://github.com/laz2wiringpi/laz2wiringpi/blob/6680c13011d2b8feda47253824e1ff88edf14523/h2wiringpi.pas#L362

At least there (around line 40) you can see the linklib statements required to link to the C library.

Mountaineer:
Hello ccrause,
thank you for supporting me!
After trying this and that I got my program compiling with the wrapper "h2wiringPi"!
No compiling errors (without calling a function or procedure of wiringpi)...
...BUT:
As soon as I uncomment the call "wiringPiISR(1, 1, @myISR);" in my test-program/unit it stops without showing the form (in my experience this is usually due to an error).
But compiling was ok.

Do you have any idea what's going wrong?

Enclosed you will find my test-program/unit (unit1) and the wrapper (h2wiringpi)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version