Giter VIP home page Giter VIP logo

pascal-bindings-for-simpleble-library's People

Contributors

chip45com avatar eriklins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pascal-bindings-for-simpleble-library's Issues

proper IFDEFs

  {$ifdef windows}
  SimpleBleExtLibrary = 'simpleble-c.dll';
  {$else}
    {$ifdef darwin}
    SimpleBleExtLibrary = 'simpleble-c.dylib';
    {$else}
    SimpleBleExtLibrary = 'simpleble-c.so';
    {$endif}
  {$endif}

rename TCallback*

Eg TCallbackNotify is too generic name (user may have it busy). Better rename to TBleCallback*.

better rename these callback types, give them some prefix like "TSimpleBle"

type
  TCallbackScanStart = procedure(adapter: simpleble_adapter_t; userdata: PPointer);
  TCallbackScanStop = procedure(adapter: simpleble_adapter_t; userdata: PPointer);
  TCallbackScanUpdated = procedure(adapter: simpleble_adapter_t; peripheral: simpleble_adapter_t; userdata: PPointer);
  TCallbackScanFound = procedure(adapter: simpleble_adapter_t; peripheral: simpleble_adapter_t; userdata: PPointer);

Exception on simpleble_free

Hi!
I`m using SimpleBle with examples for Pascal binding.
Everything works fine, but on some machines there is a strange behavior, library throws exception on simpleble_free.

  procedure AdapterOnScanStart(Adapter: TSimpleBleAdapter; Userdata: PPointer);
  var
    Identifier: PChar;
  begin
    Identifier := SimpleBleAdapterIdentifier(Adapter);
    if Identifier = '' then
      Exit;
    WriteLn('Adapter ' + Identifier + ' started scanning.');
    SimpleBleFree(Identifier);
  end;                  

And at SimpleBleFree(Identifier) (same as simpleble_free) I get

изображение

изображение

And sometimes app works nice, sometime I need to restart it ten times, sometimes nothing helps.
I use SimpleBle win64 0.7.3 shared version.

Looks like library does want to free string it just allocated.

Project itself is here https://github.com/magdel/ble2com

Allow dynamic loading in Windows

By just providing the references to the functions and labelling them 'external' the DLL files will be loaded statically. If there is a problem (e.g. the DLL file isn't found) then the program will throw a system error and fail to run.

Windows allows DLL files to be loaded dynamically using the LoadLibrary function. Now if the program fails to load the DLL files it is up to the program how to handle the error, perhaps by providing a message to the user.

This amendment adds the ability to load the libraries in Windows dynamically.

Usage:

By default static loading is still used. To use dynamic loading uncomment the line:
{$DEFINE DYNAMIC_LOADING}

There are then two functions exposed:

function SimpleBleLoadLibrary(dllPath:string=''): Boolean;
procedure SimpleBleUnloadLibrary();

In your program you can call the load routine without a parameter in which case Windows will search its normal path for the DLLs (e.g. in the EXE's directory and in Windows\System32). Or you can specify the path either as an explicit full path or a relative path. For example your code might be:

if not SimpleBleLoadLibrary() then begin
   if not SimpleBleLoadLibrary('./dll64') then begin
      writeln('Failed to load library');
      readln;
      exit;
   end;
end;

Before leaving your program you should clean up the memory by calling the SimpleBleUnloadLibrary procedure.

Note that one difference between the static and dynamic loading is that with static this would be allowed:
if not SimpleBleAdapterIsBluetoothEnabled then writeln('BLE is not enabled on this PC');
But with dynamic, even though the function has no parameters, it must still be called with the brackets:
if not SimpleBleAdapterIsBluetoothEnabled() then writeln('BLE is not enabled on this PC');

P.S. I would have added this as a pull request but I don't use Github much so didn't want to start creating forks etc!

simpleble.zip

Linux version compiled with wrong source

The Linux version only works if these lines are commented out:

  TSimpleBleService = record
    Uuid: TSimpleBleUuid;
    // DataLength: NativeUInt;
    // Data: array[0..27-1] of Byte;
    CharacteristicCount: NativeUInt;
    Characteristics: array[0..SIMPLEBLE_CHARACTERISTIC_MAX_COUNT-1] of TSimpleBleCharacteristic;
  end;

Because of this, I think, Linux InsideBlue 0.6 crashes when connecting. IB 0.6 also returns the wrong MTU on some devices (Linux version says MTU is 3, Windows version says it's 160), possibly the same problem.

missing DLL

I'm trying to use the bindings as dynamic loading DLL.
I've compiled the scan example and moved simpleble-c.dll, simpleble.dll, to the build debug folder where .exe is located but im getting Access Violation error.
In your readme there is mention of fmt.dll but I cant find it.

Regards,

size_t

type
  {$IFDEF UNIX}
  size_t = csize_t;
  {$ENDIF}

looks bad, because you define global type size_t when SimpleBle unit is used. can you avoid size_t by replacing it with LongInt, or SizeInt, or Int64?

Connect and notify examples throw error when listing peripherals services under Linux

ErrCode := simpleble_peripheral_services_get(Peripheral, i, Service);

gives segmentation fault:

$ ./SimpleBleConnectExample 
Found BLE adapter and got handle.
Adapter hci0 started scanning.
Adapter hci0 found device: BT510_3C3A [FC:DA:65:F9:3C:3A]
Adapter hci0 found device:  [4A:36:1D:B8:0E:63]
Adapter hci0 found device: LAIRD BL654-EF69F4 [EF:9D:93:EF:69:F4]
Adapter hci0 found device: BT510_8617 [D7:93:7D:9B:86:17]
Adapter hci0 found device:  [67:37:37:7B:29:41]
Adapter hci0 found device:  [90:F1:57:F6:11:D4]
Adapter hci0 started scanning.
The following devices were found:
[0] BT510_3C3A [FC:DA:65:F9:3C:3A]
[1]  [4A:36:1D:B8:0E:63]
[2] LAIRD BL654-EF69F4 [EF:9D:93:EF:69:F4]
[3] BT510_8617 [D7:93:7D:9B:86:17]
[4]  [67:37:37:7B:29:41]
[5]  [90:F1:57:F6:11:D4]
Please select a device to connect to: 2
Connecting to LAIRD BL654-EF69F4 [EF:9D:93:EF:69:F4]
Successfully connected, listing 2 services.
Segmentation fault (core dumped)

type names

  simpleble_manufacturer_data_t = record
  simpleble_adapter_t = size_t;
  simpleble_peripheral_t = size_t;

  simpleble_os_t 

better rename to Pascal style!
ie

  • TSimpleBleManufacturerData
  • TSimpleBleAdapter
  • TSimpleBlePeripheral
  • etc

Can't find SO file

A problem with my Linux Mint 21 set up I'm sure, but there doesn't seem to be any way to contact Erik other than raising an issue. I'm getting SO errors:

graham@graham-dell:~/Pascal/SimpleBLE$ ls -la
total 5124
drwxrwxr-x 2 graham graham    4096 Jan 21 13:49 .
drwxrwxr-x 8 graham graham    4096 Jan 21 13:40 ..
lrwxrwxrwx 1 graham graham      11 Jan 21 13:49 libfmt.so -> libfmt.so.8
lrwxrwxrwx 1 graham graham      15 Jan 21 13:49 libfmt.so.8 -> libfmt.so.8.1.1
-rwxrwxr-x 1 graham graham  576824 Nov  7 02:14 libfmt.so.8.1.1
lrwxrwxrwx 1 graham graham      19 Jan 21 13:49 libsimpleble-c.so -> libsimpleble-c.so.0
lrwxrwxrwx 1 graham graham      23 Jan 21 13:49 libsimpleble-c.so.0 -> libsimpleble-c.so.0.6.0
-rwxrwxr-x 1 graham graham  205440 Nov  7 02:14 libsimpleble-c.so.0.6.0
lrwxrwxrwx 1 graham graham      17 Jan 21 13:49 libsimpleble.so -> libsimpleble.so.0
lrwxrwxrwx 1 graham graham      21 Jan 21 13:49 libsimpleble.so.0 -> libsimpleble.so.0.6.0
-rwxrwxr-x 1 graham graham 2480816 Nov  7 02:14 libsimpleble.so.0.6.0
-rw-r--r-- 1 graham graham 1042268 Nov  7 17:51 shared_libs.zip
-rwxrwxr-x 1 graham graham  924272 Nov  7 04:41 SimpleBleScanExample
graham@graham-dell:~/Pascal/SimpleBLE$ ./SimpleBleScanExample
./SimpleBleScanExample: error while loading shared libraries: libsimpleble.so.0: cannot open shared object file: No such file or directory
graham@graham-dell:~/Pascal/SimpleBLE$ 

I tried setting the LD_LIBRARY_PATH but that didn't help. Is there a "sudo apt get" command for installing the libraries?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.