Open AndyHud411 opened 3 years ago
I can't really help with provided information, there might be some wrong configuration in visual studio that results in symbol mismatch.
I recommend just adding the library files into your project and compiling everything together, you won't have any linking issues in that case, just be sure to add these two libraries to linker ws2_32 bthprops
I can't really help with provided information, there might be some wrong configuration in visual studio that results in symbol mismatch.
I recommend just adding the library files into your project and compiling everything together, you won't have any linking issues in that case, just be sure to add these two libraries to linker
ws2_32 bthprops
Thank you so much! Finally got it to work... Now I am having a problem connecting to devices. What is the prerequisite for connecting two devices? Is all they need to be connected to one another through bluetooth? Is the BTSerialPortBinding->Connect(address, Id) taking care of opening a RFCOMM port? or is that something I have to do manually?
yes, you should be able to just Read and Write data after Connect, you might also need to pass value of 1
as channelID
yes, you should be able to just Read and Write data after Connect, you might also need to pass value of
1
as channelID
Finally got it to connect (I Think) but I cannot get anything to read data? It does not seem to be reading anything from the port. It just sits and does nothing. Which I am assuming it is stalling till there is information in the buffer. My functions for sending information looks like this.
`int main() {
unique_ptr<DeviceINQ> inq(DeviceINQ::Create());
vector<device> devices = inq->Inquire();
cout << "--DEVICES--" << endl;
for (const auto& d : devices)
{
cout << d.name << " " << d.address << endl;
}
string deviceName;
cout << "Enter device name to connect to: ";
getline(cin, deviceName);
//deviceName.pop_back();
cout << endl;
cout << "You Chose: " << deviceName << endl;
char buffer[20];
strcpy_s(buffer, "123451234512345");
cout << buffer << endl;
for (const auto& d : devices)
{
if (d.name == deviceName)
{
try {
unique_ptr<BTSerialPortBinding> port(BTSerialPortBinding::Create(d.address, 1));
cout << "Is Connected : " << d.connected << endl;
port->Connect();
cout << "Connected" << endl;
while (true)
{
string trash;
getline(cin, trash);
port->Write(buffer, (int)strlen(buffer));
cout << "DID" << endl;
}
}
catch (BluetoothException msg) {
cout << msg.what();
}
break;
}
}
cout << "No Devices Found...";
}`
and Receiving.
`int main() { std::cout << "Hello World!\n";
unique_ptr<DeviceINQ> inq(DeviceINQ::Create());
vector<device> devices = inq->Inquire();
cout << "--DEVICES--" << endl;
for (const auto& d : devices)
{
cout << d.name << " " << d.address << endl;
}
string deviceName;
cout << "Enter device name to connect to: ";
getline(cin, deviceName);
//deviceName.pop_back();
cout << endl;
cout << "You Chose: " << deviceName << endl;
char buffer[20];
strcpy_s(buffer, "123451234512345");
cout << buffer << endl;
for (const auto& d : devices)
{
if (d.name == deviceName)
{
try {
unique_ptr<BTSerialPortBinding> port(BTSerialPortBinding::Create(d.address, 1));
cout << "Is Connected : " << d.connected << endl;
port->Connect();
cout << "Connected" << endl;
char buffor[20];
while (true)
{
cout << "Tried" << endl;
port->Read(buffer, 20);
string boi = buffor;
cout << boi << endl;
}
}
catch (BluetoothException msg) {
cout << msg.what();
}
break;
}
}
cout << "No Devices Found...";
}`
Thanks for all your help again.
Everything looks correct, not sure what might be the issue, are you sure the device is going to send data straight after connection ?
Everything looks correct, not sure what might be the issue, are you sure the device is going to send data straight after connection ?
I think so, the Bluetooth on my devices has been weird and didn't want to stay connected normally for some reason. Eventually it did, and the ::Connect() started working... When I write to the buffer it doesn't give me an error most of the time. But read just sits and does nothing.
What do you mean "Straight After connection" I connect them then I write data to the buffer. Then the already connected other end calls the read function. Does it matter if you call the read function before or after the data is sent?
Just meant it in the sense that some devices require some input before they start sending anything back, but I don't know what kind of device you're connecting to and if it's expected to send continuous data by itself
Just meant it in the sense that some devices require some input before they start sending anything back, but I don't know what kind of device you're connecting to and if it's expected to send continuous data by itself
Oh, well I am connecting two Windows PC's together with this code. So one end is doing the listening and the other end is doing the sending. I believe I don't need continuous data. Do you know of a way to check that though?
Oh, I don't have any experience with connecting 2 PCs that way, not sure if that requires any additional setup. I think one of them might have to be setup as server and serve RFCOMM service I don't know if you can just connect from both side peer to peer. I only ever used this to communicated with bluetooth devices that expose RFCOMM on their bluetooth.
How do you get the makefile to work in linux? Once you write code in linux how do you compile it with the makefile generated? Is there a place to add my file?
The code is not compiling a lot of the C libraries and I cannot seem to find why...
running
cmake .
make
seems to compile it fine on linux
you can also run make inquiretest
to build test executable
you can also run
make inquiretest
to build test executable
Awesome! Thank you so much it is working... Sorta. Now it only shows the devices on occasion when they are connected. The test doesn't show any items. If you have any ideas let me know.
you can also run
make inquiretest
to build test executableAwesome! Thank you so much it is working... Sorta. Now it only shows the devices on occasion when they are connected. The test doesn't show any items. If you have any ideas let me know.
Found out what the problem was. The DeviceINQ->Inq function only shows the devices that are not currently connected and are sharing their connection. Now my problem is I cannot read or write :C
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:
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.