agamnentzar / bluetooth-serial-port Goto Github PK
View Code? Open in Web Editor NEWmulti-platform bluetooth serial port library for C++
License: Other
multi-platform bluetooth serial port library for C++
License: Other
hi,professor:
like the topic said
please help!
Update the VERSION argument value or use a ... suffix to tell
CMake that the project does not need compatibility with older versions.
This appears while compiling.
Ok.
Thank you for the library!
I can connect with remote devices but is it possible to implement a bluetooth 'server' with bluetooth-serial-port? Remote devices open a connection with the local device.
I need to listen connections from remote devices...
DJuego
i am connect pc to raspberry pi to send a message. but it can't read any character?
this is program from pi:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <exception>
#include <vector>
#include <memory>
#include <ctime>
#include "DeviceINQ.h"
#include "Enums.h"
#include "BluetoothException.h"
#include "BTSerialPortBinding.h"
#include <QThread>
using namespace std;
string formatDate(const char *format, time_t time)
{
if (time <= 0)
return "--";
char buffer[256] = { 0 };
tm *timeinfo = localtime(&time);
if (timeinfo)
strftime(buffer, sizeof(buffer), format, timeinfo);
return buffer;
}
int main()
{
try
{
unique_ptr<DeviceINQ> inq(DeviceINQ::Create());
vector<device> devices = inq->Inquire();
for (const auto& d : devices)
{
cout << "\tname: " << d.name << endl;
cout << "\taddress: " << d.address << endl;
cout << "\tclass: " << GetDeviceClassString(d.deviceClass) << endl;
cout << "\tmajor class: " << GetDeviceClassString(d.majorDeviceClass) << endl;
cout << "\tservice class: " << GetServiceClassString(d.serviceClass) << endl;
cout << "\tlast seen: " << formatDate("%c", d.lastSeen) << endl;
cout << "\tlast used: " << formatDate("%c", d.lastUsed) << endl;
cout << "\tchannel ID: " << inq->SdpSearch(d.address) << endl;
cout << endl;
if(d.name == "DESKTOP-B1U1RIH") {
BTSerialPortBinding *bt = BTSerialPortBinding::Create(d.address, 1);
bt->Connect();
char readC[100];
while(true) {
if(bt->IsDataAvailable()) {
std::cout<<"start read";
bt->Read(readC, 100);
std::cout<<"read: "<<readC<<std::endl;
}
else {
std::cout<<"IsDataAvailable not available"<<std::endl;;
}
QThread::sleep(1);
}
}
}
cout << endl << "done, found " << devices.size() << " device(s)" << endl;
}
catch (const BluetoothException& e)
{
cout << e.what() << endl;
}
return 0;
}
This is program in pc:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <exception>
#include <vector>
#include <memory>
#include <ctime>
#include "DeviceINQ.h"
#include "Enums.h"
#include "BluetoothException.h"
#include "BTSerialPortBinding.h"
#include <QThread>
using namespace std;
string formatDate(const char *format, time_t time)
{
if (time <= 0)
return "--";
char buffer[256] = { 0 };
tm *timeinfo = localtime(&time);
if (timeinfo)
strftime(buffer, sizeof(buffer), format, timeinfo);
return buffer;
}
int main()
{
try
{
unique_ptr<DeviceINQ> inq(DeviceINQ::Create());
vector<device> devices = inq->Inquire();
for (const auto& d : devices)
{
cout << "\tname: " << d.name << endl;
cout << "\taddress: " << d.address << endl;
cout << "\tclass: " << GetDeviceClassString(d.deviceClass) << endl;
cout << "\tmajor class: " << GetDeviceClassString(d.majorDeviceClass) << endl;
cout << "\tservice class: " << GetServiceClassString(d.serviceClass) << endl;
cout << "\tlast seen: " << formatDate("%c", d.lastSeen) << endl;
cout << "\tlast used: " << formatDate("%c", d.lastUsed) << endl;
cout << "\tchannel ID: " << inq->SdpSearch(d.address) << endl;
cout << endl;
if(d.name == "raspberrypi") {
BTSerialPortBinding *bt = BTSerialPortBinding::Create(d.address, 5);
bt->Connect();
while(true) {
std::string data = "test send serialport";
bt->Write(data.c_str(), data.length());
QThread::sleep(1);
}
}
}
cout << endl << "done, found " << devices.size() << " device(s)" << endl;
}
catch (const BluetoothException& e)
{
cout << e.what() << endl;
}
return 0;
}
Where did I go wrong? Anyone can help?
Thank you.
Hi,
It seems that DeviceINQ::SdpSearch() always fails (it returns -1 for all devices) .
I just ran test/main.cpp code and it lists all devices but with -1 for channels. So when I can't create a BTSerialPortBinding, because it needs positive channel id.
I have tested this on windows 7, VS 2015.
Is there is a function that checks if connection is still alive and device hasn't disconnected? (Windows)
I am attempting to use this library in my project, how do I include it in my c++ project?
What I've tried:
Built the project using CMake - specifying the downloaded unzipped project as the source and another folder for the binary output.
My build output: http://i65.tinypic.com/2vmfu4o.png
I have built a .lib file and added it to Linker -> Input -> Additional Dependencies. Then I included the .lib file path directory, however when I try to #include "DeviceINQ.h" or #include I get an error can't find source file. I tried to view the contents of the .lib file in Visual Studio Command Prompt, this was the output:
http://i64.tinypic.com/1zvrivb.png
Here it shows that DeviceINQ is an object but I still cannot include the header file. Any Ideas, thankyou.
Hello everyone,
I am having difficulties getting this library to work. I am currently using Visual Studio 2019. I have looked in a past thread about this same problem pretty much but when I followed that answer it did not work. My Errors:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __thiscall DeviceINQ::~DeviceINQ(void)" (??1DeviceINQ@@QAE@XZ) referenced in function "public: void * __thiscall DeviceINQ::`scalar deleting destructor'(unsigned int)" (??_GDeviceINQ@@QAEPAXI@Z) PleaseSerialWork C:\Users\Swagm\source\repos\PleaseSerialWork\PleaseSerialWork\PleaseSerialWork.obj 1
Error LNK2019 unresolved external symbol "public: static class DeviceINQ * __cdecl DeviceINQ::Create(void)" (?Create@DeviceINQ@@SAPAV1@XZ) referenced in function _main PleaseSerialWork C:\Users\Swagm\source\repos\PleaseSerialWork\PleaseSerialWork\PleaseSerialWork.obj 1
Error LNK2019 unresolved external symbol "public: class std::vector<struct device,class std::allocator > __thiscall DeviceINQ::Inquire(int)" (?Inquire@DeviceINQ@@QAE?AV?$vector@Udevice@@v?$allocator@Udevice@@@std@@@std@@h@Z) referenced in function _main PleaseSerialWork C:\Users\Swagm\source\repos\PleaseSerialWork\PleaseSerialWork\PleaseSerialWork.obj 1
Error LNK1120 3 unresolved externals PleaseSerialWork C:\Users\Swagm\source\repos\PleaseSerialWork\Debug\PleaseSerialWork.exe 1
Here is a bit more info.
(Additional Includes) : C:\Users\Swagm\bluetooth-serial-port\src
(Additional Libraries in Linker) : C:\Users\Swagm\bluetooth-serial-port\Debug\bluetoothserialport.lib
I have tried everything. I really hope I can get this working because this utility would be insanely useful for my current project. Thank you so much in advanced.
Hi, I got your code to compile on raspbian but I only get this output with the test
`pi@raspberrypi:~/bluetooth-serial-port $ ./inquiretest
done, found 0 device(s)`
using hcitool I get this:
pi@raspberrypi:~/bluetooth-serial-port $ sudo hcitool lescanLE Scan ... 4A:A1:54:5B:D0:8E (unknown) 4A:A1:54:5B:D0:8E (unknown) 78:A5:04:16:9E:68 (unknown) 78:A5:04:16:9E:68 Kevo
My distro version is:
Raspbian GNU/Linux 9 (stretch)
Linux raspberrypi 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l GNU/Linux
and gcc version:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Raspbian 6.3.0-18+rpi1+deb9u1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-armhf/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-armhf --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-armhf --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1+deb9u1)
I tried to compile and run ur code . I am using cmake from macports. It is creating btscan and libbluetoothserialport.a. when I try to excute that
syntax error near unexpected token
newline' ./libbluetoothserialport.a: line 1: !<arch>'
can u please help me how to make it work in mac. !!
In README.md, it is
BTSerialPortBinding::IsDataAvailable(buffer, length)
In BTSerialPortBinding.h, it is
bool IsDataAvailable();
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.