[solved] IntelRealSense sdk can be access from pascal? lazarus / 21-General ---------------------------------------------------------------------- BlueIcaro · 2022-11-22 11:13 Hi I got a Intel sense camera D435. I looking the sdk: https://github.com/IntelRealSense/librealsense/tree/master/include/lib realsense2 And I think is write in C, I think. So I started make a unit to access from Pascal (wrapper). Looking the .h files I saw that many functions use Quoters2_error as parameter. For example this function: Quote/** * \brief Creates RealSense context that is required for the rest of the API. * \param[in] api_version Users are expected to pass their version of \c RS2_API_VERSION to make sure they are running the correct librealsense version. * \param[out] error  If non-null, receives any error that occurs during this call, otherwise, errors are ignored. * \return            Context object */ rs2_context* rs2_create_context(int api_version, rs2_error** error); Reading in deep. I found the definition of rs2_error (rs2_type.h): Quote typedef struct rs2_error rs2_error; (...) rs2_error * rs2_create_error(const char* what, const char* name, const char* args, rs2_exception_type type); rs2_exception_type rs2_get_librealsense_exception_type(const rs2_error* error); const char* rs2_get_failed_function            (const rs2_error* error); const char* rs2_get_failed_args                (const rs2_error* error); const char* rs2_get_error_message              (const rs2_error* error); void        rs2_free_error                     (rs2_error* error); The main cuestion is possible use this sdk from free pascal (wrapper)?, and the second question is how can convert rs2_error definition? Thanks /BlueIcaro ---------------------------------------------------------------------- PascalDragon · 2022-11-22 20:21 rs2_error is simply a so called opaque type and you only interact with it using a pointer to it, so you can declare it like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  Trs2_error = record end;  Prs2_error = ^Trs2_error; And then simply use Prs2_error where the C code uses rs2_error*. rs2_context will probably be similar. ---------------------------------------------------------------------- Thaddy · 2022-11-22 21:31 https://www.freepascal.org/docs-html/rtl/system/popaquedata.html https://www.freepascal.org/docs-html/rtl/system/topaquedata.html Which I am guilty of... I proposed this just because of such issues at hand a couple of years ago. ---------------------------------------------------------------------- BlueIcaro · 2022-11-23 10:29 Hello, I was playing and I declared  as follow: Code: [Select]rs2_error = integer; Prs2_error = ^rs2_error;  And I can compile and create a context with any problem (for the moment). Code: [Select]var   f: prs2_context;   e: Prs2_error; begin   f := rs2_create_context(RS2_API_VERSION, e);   rs2_delete_context(f); end.                             But the right way is using opaque type as you said. Thanks PascalDragron an Thaddy. By the way I open a github where I'm uploading my tests and the wrapper. https://github.com/Blueicaro/Pascal-Librealsense Warning, it 100% experimental and I'm not a expert. I'm learning. /BlueIcaro ---------------------------------------------------------------------- PascalDragon · 2022-11-23 21:57 Quote from: BlueIcaro on November 23, 2022, 11:29:32 amHello, I was playing and I declared  as follow: Code: [Select]rs2_error = integer; Prs2_error = ^rs2_error;  Don't declare it as Integer, declare it as record end as I had mentioned in my post or use TOpaqueData as mentioned by Thaddy. ---------------------------------------------------------------------- BlueIcaro · 2022-11-24 18:52 Hi, Finnaly I used: Code: [Select]    type       Trs2_error = record end;       Prs2_error = ^Trs2_error; QuoteDon't declare it as Integer, declare it as record end as I had mentioned in my post or use TOpaqueData as mentioned by Thaddy. I used Integer before your answer. Now I know that is not the right way. /BlueIcaro ---------------------------------------------------------------------- BlueIcaro · 2022-11-25 14:50 Hello, I make some advances, I make two small programs. https://github.com/Blueicaro/Pascal-Librealsense There is a lot of work to do. But for the moment I can access to the library and get information about camera, and get a frame. /BlueIcaro ---------------------------------------------------------------------- BlueIcaro · 2022-12-03 09:57 Hello, I advanced in the wrapper for pascal. But I found this in code of sdk, that I don't know how to translate to pascal: void(*deleter)(void*); Here is the code. Code: [Select]/** \brief All the parameters required to define a video frame. */ typedef struct rs2_software_video_frame {     void* pixels;     void(*deleter)(void*);     int stride;     int bpp;     rs2_time_t timestamp;     rs2_timestamp_domain domain;     int frame_number;     const rs2_stream_profile* profile;     float depth_units; } rs2_software_video_frame; It's a record, but how can I translate void(*deleter)(void*); Any Idea Thanks /BlueIcaro ---------------------------------------------------------------------- KodeZwerg · 2022-12-03 11:59 Quote from: BlueIcaro on December 03, 2022, 10:57:29 amHello, I advanced in the wrapper for pascal. But I found this in code of sdk, that I don't know how to translate to pascal: void(*deleter)(void*); Here is the code. Code: [Select]/** \brief All the parameters required to define a video frame. */ typedef struct rs2_software_video_frame {     void* pixels;     void(*deleter)(void*);     int stride;     int bpp;     rs2_time_t timestamp;     rs2_timestamp_domain domain;     int frame_number;     const rs2_stream_profile* profile;     float depth_units; } rs2_software_video_frame; It's a record, but how can I translate void(*deleter)(void*); Any Idea Thanks /BlueIcaro I am no C expert but I would try my luck this way Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  rs2_software_video_frame = record    pixels,    deleter: Pointer;    stride,     bpp: Integer;    timestamp: rs2_time_t; // you need to watch definition of rs2_time_t    domain: rs2_timestamp_domain; // you need to watch definition of rs2_timestamp_domain    frame_number: Integer;    profile: rs2_stream_profile; // you need to watch definition of rs2_stream_profile    depth_units: Single; // you need to watch definition of float, I just put single in, maybe it is some other float type  end; ---------------------------------------------------------------------- PierceNg · 2022-12-03 12:17 Quote from: BlueIcaro on December 03, 2022, 10:57:29 amCode: [Select]    void(*deleter)(void*); It's a record, but how can I translate void(*deleter)(void*); It's a pointer to a function taking a pointer-to-void as a parameter and returning void (if I read it correctly). In Pascal, define a type for the signature: Code: [Select]type   TDeleterProc = procedure(arg: Pointer); cdecl; Then in the Pascal record definition, declare the field 'deleter: TDeleterProc'. ---------------------------------------------------------------------- BlueIcaro · 2022-12-03 23:19 Quote from: PierceNg on December 03, 2022, 01:17:03 pmQuote from: BlueIcaro on December 03, 2022, 10:57:29 amCode: [Select]    void(*deleter)(void*); It's a record, but how can I translate void(*deleter)(void*); It's a pointer to a function taking a pointer-to-void as a parameter and returning void (if I read it correctly). In Pascal, define a type for the signature: Code: [Select]type   TDeleterProc = procedure(arg: Pointer); cdecl; Then in the Pascal record definition, declare the field 'deleter: TDeleterProc'. Thanks!! /BlueIcaro