Invoke F # Call Functions

I use F # on Raspberry Pi 2 (ARM 7 and therefore mono). I am currently trying to use the WiringPi library written in C. I was able to successfully use some functions using P / Invoke.

Now I'm trying to use interrupts (see http://wiringpi.com/reference/priority-interrupts-and-threads/ ), but I'm confused by this function with the following C signature

int wiringPiISR (int pin, int edgeType,  void (*function)(void));

What has been translated (see https://github.com/danriches/WiringPi.Net/blob/master/WiringPi/WrapperClass.cs ) by Daniel Rish to a C # library like this

//This is the C# equivelant to "void (*function)(void))" required by wiringPi to define a callback method 
public delegate void ISRCallback(); 

[DllImport("libwiringPi.so", EntryPoint = "wiringPiISR")] 
public static extern int wiringPiISR(int pin, int mode, ISRCallback method); 

How would I do this in F #? I think the DllImport line looks like this (the "method" is reserved in F #)

[<DllImport("libwiringPi.so", EntryPoint = "wiringPiISR")>] 
  extern int wiringPiISR(int pin, int mode, ISRCallback callBack);

What does type determination for ISRCallback look like?

. "a", , void.

+4
1

:

type ISRCallback = delegate of unit -> unit

:

[<DllImport("libwiringPi.so", EntryPoint = "wiringPiISR")>] 
extern int wiringPiISR(int pin, int mode, [<MarshalAs(UnmanagedType.FunctionPtr)>]ISRCallback callBack);

:

let callback : ISRCallback = ISRCallback(fun () -> (*do something interesting here*) ())
let result = wiringPiISR(1, 1, callback)

, .NET . , " ", .

+4

Source: https://habr.com/ru/post/1618178/


All Articles