Number of SPP port by bluetoothapis.h - c++

How I can get number virtual com port for device connected via Bluetooth in SPP mode?
I am use bluetoothapis.h.
Now I can pair with Device via bluetooth with bluetoothapis.h.
Get list of visible devices.
But I cannot figure out how get number of virtual port for bluetooth device.
There are virtual com ports in device manager.
I use Win7. Please help figure out.

Related

Connecting through TCP to 0.0.0.0 on Wi-Fi while the listener PC has active Wi-Fi and Ethernet doesn't work

I'm creating a TCP connection from a device on Wi-Fi to a computer that's listening on port 0.0.0.0:44440.
When I am only on Wi-Fi, the device is able to connect without a problem. When I enable / plug in Ethernet, the listener never accepts the device's connection request. (Wi-Fi is still connected throughout this process. Checked by ipconfig)
I'm using C++, and the command looks like this:
handle = (int)accept(listening_socket->handle, (struct sockaddr *)&address, &addrlen);
The command gets a handle when a device connects if both are on Wi-Fi only, but continues blocking if the listener is on both Ethernet and Wi-Fi.
0.0.0.0 is supposed to be interface-ambiguous, so it should accept connections from both Ethernet (192.168.x.x) and Wi-Fi (10.161.x.x), but it seems to 'attach' to the interface that is giving the best internet. Checking using "netstat -an", there is an active listener on 0.0.0.0:44440 using each method.
Anyone a pro at networking and know why having multiple running interfaces messes with this?
.
Extra Info
I have done many checks to make sure Wi-Fi and Ethernet are enabled. I am running a UDP broadcast over both interfaces that tells devices to connect to the local computer. So the broadcast contains a message of "192.168.x.x:44440" for devices running on local network and "10.161.x.x:44440" for devices running on Wi-Fi. The device picks up this message and then tries to form a TCP connection on "10.161.x.x:44440." When the computer is only connected through Wi-Fi, connecting like this works. When it's connected through both, the listener running on port 44440 never detects when the device connects. It will still connect local programs running on the same machine from either IP.
Also note, my Ethernet is not the same network as my Wi-Fi (for security reasons). So each network has separate properties
When I connected Ethernet, it reset my Wi-Fi to a public Wi-Fi rather than private. That didn't allow the TCP connection because sharing was now disabled. Though it allowed a UDP connection, which is interesting to me. So if you run into this, make sure your Wi-Fi has network sharing on!

USB port name for serial communcation

I want to write code that will allow me to send a command (not just video) from a computer to a TV, specifically, a command that will change the input. The code needs to be in C++, and the communication must be done through a usb cable.
I am currently using Qt to communicate with the ports, but the only port that I can communicate with is "com1". I was wondering, how do I get the names of the usb ports that devices like my mouse, usb sound adapter, etc are currently using?
And if there is any Qt code that lets me send commands to usb devices, that would be sick.
Just because USB means Universal Serial Bus, doesn't make every USB device a serial port.
USB devices have different classes, handled by different drivers. Human interface input devices like mice and keyboards are of a HID class. These devices are not serial ports, and will not appear on a list of serial ports. Same goes for a majority of other popular devices such as scanners, video cameras, etc.
The only devices that will appear on a list of serial ports are communications class devices (CDC), and USB-to-serial converters that have drivers that expose them as serial ports, like e.g. FTDI chips.
As for your TV, you need to figure out what kind of a device class your TV appears as. You would use a tool like usbview to enumerate USB devices and see their properties. Your TV could even be a composite device that has a HID class device, and some other device class.

Serial communication over RS232 and USB

I plan to write serial driver to send data from target to host. The target is a renasas RX62N. And the host is windows 8.1. The target has RS232 port and the host has a USB port. I plan to use a converter cable with DB9(not sure) and USB connectors. 1) would like to know if I can send and receive from target and host? 2) would like to know if there is a way of getting around writing USB driver to send and receive from host is there software(Program) that could monitor usb port and send and receive dats over USB port? Ive seen software that let you send data and see the data receive by a port.
(1) RS-232 is bidirectional. You can send and receive at the same time.
(2) You do not have to write a USB driver for the host. Windows has this built in. Use the standard Windows serial I/O calls. They work the same way for serial ports and for USB to serial converters.
The USB<->RS-232 converter cable will appear to the PC host as a legacy serial port, support for the CDC/ACM USB profile that implements this port emulation is built into Windows, Linux and OSX. In windows however you will normally have to install "driver" which in most cases will simply be a INF file that maps the cable's USB vendor/product ID to the usbser.sys devive driver. Some USB/Serial devices may have custom drivers.
Common USB CDC/ACM devices from FTDI and Prolific will install drivers automatically via Windows Update (though historically Prolific drivers have been problematic - though recently they have improved).
At the target end, you communicate via the UART that is wired to the RS-232 line driver as you would normally.
For basic testing and keyboard/screen console access to your target, you van use any terminal emulator software such as TeraTerm, HyperTerminal, or Putty.

What usb device is connected to a usb port

I'll try to keep this simple.
I have a hub connected to my PC. This hub has several USB interfaces. I'm listening to WM_DEVICECHANGE event and I get the USB interface path. How can I know what port it was connected to? Looking for a non-WMI solution in c++ or c# for a windows environment.
I tried using IOCTL_USB_GET_NODE_CONNECTION_NAME with USB_NODE_CONNECTION_NAME (where USB_NODE_CONNECTION_NAME.NodeName will hold the path to the device) but this only works if the device connected to the port is a hub as well.
Any help will be much appreciated.
The primary issue in C++ is that there is no standard functions for detecting USB ports.
USB Port identification and implementation is a platform specific issue. For example, Linux handles USB ports quite differently than Windows and many embedded systems don't have USB ports.
So you'll have to look for a 3rd party library or find some OS API to use for your platform.

Logic to recognize the name of the COM port to which a USB to RS422 connector is connected (for Windows application))

I have an application where I am writing data to the serial port via an USB to RS422 convertor. This convertor cable to connected to my PC through an USB hub. The problem I am facing is that each time I change the PC in which I am running the application, the name of the COM port changes. So I will have to change this in my code and recompile the code to run the application.
At present following is the code I am using to initialize the serial port:
if ((comport = CreateFile("\\\\.\\COM7", GENERIC_WRITE, 0,
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL)) == INVALID_HANDLE_VALUE)
{
return false;
}
Here I am exclusively mentioning the name of the COM port. I would like to know if there is an API to know the status of the COM ports and on the fly recognize the COM port to which my convertor is connected ?
What is proper way to detect all available serial ports on Windows?
That question might help you out, at least a bit. So it's probably not possible with an API, as the second answer implies. Serial ports aren't plug & play.
So it's possible to list all ports.
The only possible way I think of, is by polling each device that is in the list. And wait till you get the response you are expecting. It's not that nice.
EDIT:
Might be possible to get the friendly name, if that is what you want.
How do I get the friendly name of a COM port in Windows?
Rather changing the COM port in your application you can set the COM port for your cable from
Device Manager - > Ports -> Right Click your cable name -> Properties -> Port Setting -> Advanced -> Com Port Number (You can select the port number according to the application)
No need to change anything in your application.