Recent

Author Topic: [solved] IntelRealSense sdk can be access from pascal?  (Read 1132 times)

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
[solved] IntelRealSense sdk can be access from pascal?
« on: November 22, 2022, 12:13:49 pm »
Hi I got a Intel sense camera D435. I looking the sdk:

https://github.com/IntelRealSense/librealsense/tree/master/include/librealsense2

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
Quote
rs2_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
« Last Edit: December 05, 2022, 01:34:25 pm by BlueIcaro »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: IntelRealSense sdk can be access from pascal?
« Reply #1 on: November 22, 2022, 09:21:06 pm »
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][+][-]
  1. type
  2.   Trs2_error = record end;
  3.   Prs2_error = ^Trs2_error;

And then simply use Prs2_error where the C code uses rs2_error*.

rs2_context will probably be similar.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: IntelRealSense sdk can be access from pascal?
« Reply #2 on: November 22, 2022, 10:31:29 pm »
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... ;D

I proposed this just because of such issues at hand a couple of years ago.
« Last Edit: November 22, 2022, 10:39:49 pm by Thaddy »
Specialize a type, not a var.

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: IntelRealSense sdk can be access from pascal?
« Reply #3 on: November 23, 2022, 11:29:32 am »
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
« Last Edit: November 23, 2022, 11:34:28 am by BlueIcaro »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: IntelRealSense sdk can be access from pascal?
« Reply #4 on: November 23, 2022, 10:57:37 pm »
Hello, 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

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: IntelRealSense sdk can be access from pascal?
« Reply #5 on: November 24, 2022, 07:52:05 pm »
Hi, Finnaly I used:
Code: [Select]
    type
      Trs2_error = record end;
      Prs2_error = ^Trs2_error;

Quote
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.

I used Integer before your answer. Now I know that is not the right way.

/BlueIcaro

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: IntelRealSense sdk can be access from pascal?
« Reply #6 on: November 25, 2022, 03:50:54 pm »
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

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: IntelRealSense sdk can be access from pascal?
« Reply #7 on: December 03, 2022, 10:57:29 am »
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

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: IntelRealSense sdk can be access from pascal?
« Reply #8 on: December 03, 2022, 12:59:58 pm »
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
I am no C expert but I would try my luck this way
Code: Pascal  [Select][+][-]
  1. type
  2.   rs2_software_video_frame = record
  3.     pixels,
  4.     deleter: Pointer;
  5.     stride,
  6.     bpp: Integer;
  7.     timestamp: rs2_time_t; // you need to watch definition of rs2_time_t
  8.     domain: rs2_timestamp_domain; // you need to watch definition of rs2_timestamp_domain
  9.     frame_number: Integer;
  10.     profile: rs2_stream_profile; // you need to watch definition of rs2_stream_profile
  11.     depth_units: Single; // you need to watch definition of float, I just put single in, maybe it is some other float type
  12.   end;
« Last Edit: December 03, 2022, 01:01:58 pm by KodeZwerg »
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: IntelRealSense sdk can be access from pascal?
« Reply #9 on: December 03, 2022, 01:17:03 pm »
Code: [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

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: IntelRealSense sdk can be access from pascal?
« Reply #10 on: December 04, 2022, 12:19:30 am »
Code: [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

 

TinyPortal © 2005-2018