I have used Bluetooth API and I have written some codes. I have used functions and structures from this link- https://msdn.microsoft.com/en-us/library/windows/desktop/aa362930(v=vs.85).aspx
The code I used were simple ones, where I check whether the device is connected/remembered/authenticated.
Initially, I wrote the code in Visual Studio 2013, in Windows 7 with internal Bluetooth v2.1. The code was working fine and I was getting the output properly. (i.e, whether the device is connected,remembered,authenticated). I used this structure https://msdn.microsoft.com/en-us/library/windows/desktop/aa362924(v=vs.85).aspx
Now, I tried that same code in Windows 7 and in Windows 10 with both using an external Bluetooth dongle with version v2.0. And then, I was not getting results. For example- for a particular device, I am getting the status for remembered,authenticated- properly, but the connected status is always the wrong result.
So, I want to know whether those Bluetooth APIs( the link which I have attached) are limited to only some of the bluetooth versions / operating systems ? If so, what are they limited to ?
NOTE- I didn't post the code because, I feel this question is about compatibility issue and not some problem in the code.
Related
I'm trying to search and connect to advertising Bluetooth Low Energy devices from C++ code.
I would like a piece of code to use laptop's wireless chip to discover and connect to BLE devices, regardless of their GATT Services.
I want in fine to use GATT properties (Services, Characteristics, Descriptors, Notification).
Programmatically
I have the BluetoothLEAdvertisementWatcher Class documentation from Windows API.
I tried to make working this example but without good results.
I also tried this example, but no success.
Manually
I figured out using Windows 10 Action Center, and use manual pairing to connect devices (because Windows con see and connect my device).
Then I could use directely the Windows.Devices.Bluetooth.GenericAttributeProfile Namespace
Is there a way to implement that automatically?
Hello Raphaƫl and welcome to stackoverflow. When you say "without good results" or "but no success", you should detail why (compilation error, runtime error...).
I used this piece of code:
Getting BLE Beacons in C++ Windows 10 Desktop Application
It compiles under Win10, so should the third link you posted (https://github.com/urish/win-ble-cpp) as it's very similar if you look at the includes here. Just note that this is not regular win32 projects: from Visual Studio you must create a new "Windows"/"Universal" C++ project, else they won't compile.
Alternatively, if you're OK with using a 3rd party library, you could simply use QtBluetooth, recent version supports windows 10. Then you can easily access BLE features from aregular win32 project.
Edit: I found the problem! To anyone with similar problems, here is what I did:
The device used Hardware Flowcontrol, which apperently is no problem with Linux but on Windows, this parameter has to be set explizitly!
The Problem
We want to read out devices which trace the outline of a spectacle frame.
They use the RS232 Port. We've implemented the communication with the QSerialPort class from QT 5.7. Our Test-Setup currently features two tracers from diffenrent vendors and a Windows 7 PC. The communication with tracer 1 is working correctly; tracer 2 does not send any data to the Windows PC.
Testing
For testing I've written a very simple programm wich just prints out all bytes as ASCII characters received via the serial-port. It also allows you to enter some text to send answers back to the device.
Testing the exact same sourcecode on Linux is working perfectly with both devices.
Testsoftware on Linux (Device Requesting initialization)
. On Windows (using same cables and adapters) the log remains blank.
Connecting the Windows PC with a Nullmodem-Cable to the Linux PC or to the other device, the communication is working as expected.
Testing the communication with PuTTy on Windows, both devices are working.
The Code
The code in the testapplication looks like this:
After setting up the parameters for the port and opening it:
QObject::connect(&m_serialPort, SIGNAL(readyRead()), this, SLOT(bytesReady()));
The slot:
void Device::bytesReady(){
while(m_serialPort.bytesAvailable()){
emit read(m_serialPort.read(1).at(0));
}
}
After that, the "Konsole"-Class converts the Bytes received to readable ASCII characters and displays them in a QTextEdit
Conclusion/Question
We are suspecting there is a bug in Qt or Windows, but we haven't any idea how to further investigate the problem. The testing on Linux shows that the device itself works fine, and our test program as well. Are there any setting in Windows or any spezial thing I've to do to setting up the serialPort?
I figured it out myself. See the top of the question for the solution.
OK, first I shall point that I am completely new to Windows Apps Development, which is good, since I am trying to develop a Windows Store App for PC to use a PrimeSense Scanner connected via USB. I have asked a more specific question about this here.
This time I have a more generic question, which is more related to Windows Store app development. I am using VS2013 Express and compiling for Win32.
When I compile my application for VS2012 and run it as an execcutable file, I can connect to the scanner perfectly. But I can't do the same with VS2013 and running it as a Store app.
I know the device is connected and the drivers are updated and all dlls file placed in the Widnows System 32 directory.
I have also added all Capabilities to the App Manifest and also added the following Device Capability
<m2:DeviceCapability Name="usb">
<!--OSRFX2 Device-->
<m2:Device Id="vidpid:1d27 0609">
<m2:Function Type="classId:ff * *" />
<m2:Function Type="name:vendorSpecific" />
</m2:Device>
</m2:DeviceCapability>
The vid and pid, obviously match the corresponding codes of the device.
One of the errors I recieve when trying to conenct to the scanner using OpenNI is:
Could not open to "\\?\usb#vid_1d27&pid_0609&mi_00#7&1601586a&0&0000#{c3b5f022-5a42-1980-1909-ea72095601b1}" USB Device not found
This error is quite frustrating since I know the device is connected. So I tend to think that there is some level os specificity on the Windows Store App side of the game that is not enabling my to connect to the device. As I said, I am compiling for Win32.
Is there a chance that the drivers will not work for a Windows Store App. Is there some extra stuff I should do inside the Windows Store App logic that I am not doing and that is necessary to connect the USB device? I am sorry, but I am completely new to Windows Store App development.
Thank you.
You can't do that from metro apps.
You typically create a handle to that usb device by calling CreateFile with that object mananger path as the file to 'create'. CreateFile is not allowed in metro apps - "desktop apps only" - and its 'replacement', CreateFile2, specifically doesn't allow opening object manager objects.
Furthermore, the documentation for CreateFile2 states that in metro apps this function can only open files and directories (and not things like pipes, mailslots, consoles, etc.).
See also this post on social.msdn
Unless I missed something, I don't think this is possible.
I'm using source codes based from the following links w/my broadcom bluetooth device:
I want to make a bluetooth server that automatically starts and other devices can pair with it.
http://www.codeproject.com/Articles/252882/Bluetooth-Server-Programming-on-Windows
http://msdn.microsoft.com/en-us/library/windows/desktop/aa362932(v=vs.85).aspx
I can get the code to compile fine, allegedly the server starts, it tells me my local bluetooth device, the server port, but I cannot see the advertisement when I scan for bluetooth devices w/my iphone or ipad.
Device manager reports my bluetooth driver as functional. I'm doing this in a vm machine on win 7.
Both links say nothing about BluetoothEnableDiscovery() function. Would I need this? I tried but not sure how it works.
Everything looks ok, in the entire process I don't receive a single error. I just think I need to set it to discoverable some how or make it advertise so my other devices can see it and pair with it.
If you have any ideas, I would appreciate them. Thanks.
EDIT: Would anyone know how I can change between Secure Simple Pairing modes, or set a a 4/8 digit key for pairing in winapi c++?
With Microsoft BT stack (even with a Widcomm dongle), under Win7, your server has to expose a 'service' first.
it can be "Discoverable' but without any service exposed, no-one will "see" your server from the outside.
Check out WSASetService: https://msdn.microsoft.com/en-us/library/aa362921(v=vs.85).aspx
PS: the service will live during your app execution only...
There is a multithreaded program that operates simultaneously with a device via COM port based communication and remote (IP) video stream. The program also uses OpenCV library to process the data.
The trouble is that it shuts down without any signals (neither run-time, nor any other errors are caught; log file has no anything useful as well). The most top level application error event handler is set and still there are no any signs of the program crash. It just closes after awhile.
The biggest difficulty is that it works fine on all our PCs for days non-stop. But fails on customers PCs so that testing process is very slow. Customer is in a different country (Asian localization, whilst ours is European), but the program is built with Unicode support.
So far we have got some assumptions about localization issues and antivirus activity... but it gives nothing in result.
The program is written with MinGW 4.4.x C++ and wxWidgets 2.9.3
Any suggestions of the probable origin would be appreciate.
Solved.
The problem was inside OpenCV build 2.3.1, that we use. The function cv::imdecode(...) uses stdio.h`s tempnam() function to generate temporary file during decoding. Under x86 Windows systems this function fails after 32767 new names for temporary file. Under x64 Windows systems it returns some nonsense string, but it still works.
So the solution I came with was to change the way of receiving-decoding images from our device.
Thanks everybody for comments.