eriklins / pascal-bindings-for-simpleble-library Goto Github PK
View Code? Open in Web Editor NEWThese are Lazarus/FreePascal Bindings for the SimpleBLE Cross-Platform Library
License: MIT License
These are Lazarus/FreePascal Bindings for the SimpleBLE Cross-Platform Library
License: MIT License
Hello , just wondering . Is this going to work under Win11 64 bit ?
{$ifdef windows}
SimpleBleExtLibrary = 'simpleble-c.dll';
{$else}
{$ifdef darwin}
SimpleBleExtLibrary = 'simpleble-c.dylib';
{$else}
SimpleBleExtLibrary = 'simpleble-c.so';
{$endif}
{$endif}
Eg TCallbackNotify is too generic name (user may have it busy). Better rename to TBleCallback*.
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);
Instead, write in the LPI file properties the including of "../Pascal_Unit".
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
If user needs DLL files, put them into separate folder in the repo root
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!
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.
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,
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?
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)
and add file '.gitignore' which has *.exe
simpleble_manufacturer_data_t = record
simpleble_adapter_t = size_t;
simpleble_peripheral_t = size_t;
simpleble_os_t
better rename to Pascal style!
ie
adapter_on_scan_stop
adapter_on_scan_updated
etc
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.