currently writes an application to connect to the device "BTLink Bluetooth to Serial Adapter"
More information about device: device specification
Have created such a code:
BluetoothAddress btAddress = null;
if (!BluetoothAddress.TryParse(comboBoxDevices.SelectedValue.ToString().Trim(), out btAddress))
throw new Exception(String.Format("Adress: {0} wrong !", comboBoxDevices.SelectedValue.ToString().Trim()));
BluetoothEndPoint endPoint = new BluetoothEndPoint(btAddress, BluetoothService.DialupNetworking);
_bluetoothClient.Connect(endPoint);
I have tested two types of GUIDs:BluetoothService.DialupNetworking, BluetoothService.SerialPort.
I received this message: "No connection could be made because the target machine actively refused it"
What is wrong ?
Best regards,
mykhaylo
I would first try to connect to the target machine using the device's built-in Bluetooth capabilities. Only after this succeeds would I try to connect to it programatically.
To be able to connect to a Bluetooth device you need to know the following:
The Bluetooth profile to use. You've tried both Serial and Dialup, but which of them is actually the desired one? Many devices only support a single profile and will refuse to connect to another device requesting a non supported service.
Authentication information. Some devices require a pre-defined password.
Many devices can only form a connection to a single BT device. Is the target device already connected somewhere else?
The error you are experiencing is most probably related to one of the above and has not to do with the use of the bluetooth library.
Have you checked with 32Feet.net or on their support Forums (the provider of the classes you're using)?
I made a similar setup and program using a standard serial Bluetooth adapter without problems. You need to make sure to use the correct Bluetooth profile, the port must be available and authentication code must be accepted. Just a few suggestions.
Related
I am trying to connect to a virtual com port provided by the drivers of a u-blox GPS device.
The device appears normally under the Sensors tab in Device Manager and I can really get the coordinate data using GeoCoordinateWatcher class from C#.
But I want to read the underlying NMEA data.
So in the process of doing that I installed the Virtual Com Port driver provided by U-BLOX and it generated a u-blox virta com port in devices manager.
Connecting to that using Putty is OK and I can see all the NMEA lines being dumped there.
but when I try to connect to the same port (after Putty is closed obviously) using C# I get the exception mentioned in the title
The given port name does not start with COM/com or does not resolve to
a valid serial port
My code is fairly simple (not the first time I use com ports) and everything is correctly defined (Port Name, Stop Bits, Parity, BaudRate etc). I even tried changing to a "wrong" com port name to see the exception I will get and it is completely different (Com Port does not a exit exception).
So what is happening with C# at this point? Am I doing something wrong? Is this a bug in the SerialPort class? Putty seems to work just fine in connecting and streaming the data.
My code is as simple as the following
m_port = new SerialPort
{
PortName = m_portName,
BaudRate = m_baudRate,
Parity = m_parityBit,
DataBits = m_dataBits,
StopBits = m_stopBit
};
m_port.Open();
I even tried hardcoding the values and I still get the same exception.
I tried many of the suggested solutions found here, none of them helped.
I also tried changing the COM port number from Device Manager advanced settings, that also did not help
As it turns out U-BLOX virtual COM port driver does not fully emulate a COM port which causes issues with .Net. Regardless if it is C# or C++ or any other language running on .Net
The only solution is to either, not use this device, or use an intermediary software.
If you don't have any particular reason for using the VCP driver, use the CDC driver instead. Available as "u-blox GNSS Standard Driver for Windows" at their website:
https://www.u-blox.com/en/product-resources/2673The/field_file_category/driver-221/field_file_products%253Afield_product_category/position-time-152
I had the same problem as you, but by changing the device driver, everything works as expected. It seems like their VCP driver is not fully compatible with the regular serial port driver structure.
I managed to resolve this issue, and thought I'd share my solution.
I wasn't able to use the CDC driver, as my device is a Rugged Windows Device with a dedicated GPS - the CDC solution may only work for removable gps devices via USB. The sensor driver must be installed, and the VCP driver can be installed alongside the sensor to provide a COM port.
Whilst the VCP driver does not fully emulate a COM port, you can use another piece of software to fully emulate the uBlox virtual com port and fill in the gaps. GPS Gate was that software for me - https://gpsgate.com/. The end result is uBlox Sensor -> uBlox VCP -> GPS Gate VCP. I was then able to successfully use the GPS Gate VCP in my C# app, and have GPS data coming down.
GPS Gate also offers a Location API plugin which could remove the uBlox VCP from the equation (uBlox Sensor -> GPS Gate VCP through Location API), but I didn't have much luck with it, plus I already had a working solution.
When I turn on the bluetooth on my laptop. I see there are 2 ports added under device manager COM&LPT
Why does it add 2 ports?
If I need to a read/write via bluetooth which port should I consider using?
Thanks.
If you're using Windows own Bluetooth software, two virtual port COM ports are created after pairing.
I believe one is being used for incoming connection requests and another is used to initiate connections to the device (outgoing).
To determine which one to "use" then please consider this post which should answer that for you.
I would ask if it is possible to get information about connected devices in the local wireless network.
Is there any api for xamarin to do that?
It doesn't seem like Xamarin has an API for this, but Microsoft introduced a Ping (documentation here) and a NetworkInterface class (documentation here) in .NET 2.0 that you could use.
Essentially, what you need to do, is to ping the IP adresses on your local network, which you can do asynchronously using SendAsync(). You then register the callbacks by registering an EventHandler to PingCompleted. The callback will contain a PingCompletedEventArgs which you can use to retrieve basic information (e.g. IP, MAC and Hostname) about the device.
You can find a complete guide of the implementation here.
I hope this helps.
Note: Of course, it all depends on what type of information you expect to retrieve. Although, I think you can only expect to retrieve the basic information about devices on your network, as everything else could potentially be a security risk.
Secondary note: Depending on which devices you wish to discover on your network, you could also use the SNMP component which will allow you to discover devices such as routers, switches, printers, and so on.
I am thinking you are looking for which devices at layer-2 have registered with your wireless controller/accept-point/router and by being connected you are referring to how many have successfully establish 802.x handshake (implying security exchange and channel establishment has occurred).
There exists a tool to do this work (never tested this on my mac) and you can check Flying Squirrel for the above purpose. This will ofcourse be an independent sniffer over the wireless network and you'll require the password used for wifi etc. for making this work.
If you have access to a device that exposes instrumentation (MIB) then you can get that information from the device by SNMP walking the device. At this level you'll of course get the MAC address table and if DHCP is running on your router then perhaps access to DHCP table can give you information about the MAC to IP mapping. On some medium to high end networking gear MIBs like CISCO-DOT11-ASSOCIATION-MIB can be used. Also I am assuming you are refering to 802.11 here there are other wireless protocols like BlueTooth etc. in play as well which use different scanning techniques so the answer depends on what kind of network you are referring to here.
Ok, I figured out a way without snifing the local network. It makes more sense the following way in my case...
Case:
I want to connect to an device which provide an own wlan network. Then I connect to it and pass the home wlan network to it. The device restarts and is now configured as a client in the local home network. And now I need the local ip for service communications.
My Solution:
I do a register call to the device. The device gives me the mac address. Now I register (with phone device) the mac address from the access point device in a online service. After the device has been restarted and get the new local ip address it sends to the online service.
And the I can retrieve the local ip address through polling or through getting push notification from the server...
I'm trying to connect a Windows Phone 8 phone with a generic bluetooth headset using some information stored on a NFC tag. As for bluetooth part, it should be possible to find paired devices, which are active, using
PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
var peers = await PeerFinder.FindAllPeersAsync();
and call
await socket.ConnectAsync(peer.HostName,
serviceName);
to connect to the particural device. However, I am unable to get the serviceName. According to documentation, the device should return advertised service in PeerInformation.ServiceName, but I am only getting blank string.
Is there some workaround for how to get nams of supported services (bluetooth profiles)? I specifically need to connect the bt device using A2DP profile, but I am unable to get (or even find on the internet) the correct service name string.
ConnectAsync opens a socket for the calling program to send/receive data over. That's not what you want, instead you want the OS to connect to the Headset service. In Win32 that's BluetoothSetServiceState but I don't know an equivalent 'modern' API.
Also in Win32 one could use BluetoothAuthenticateDeviceEx which would cause pairing, and *probably* connect the headset services -- and with full Out-Of-Band authentication if supplied by the NFC channel. Again I don't know of an equivalent.
I suppose there's a possibility that doing a ConnectAsync to an arbitrary endpoint (e.g. "15") will cause pairing to start which will then complete and enable the Headset service... The ConnectAsync call itself will fail but it is its side-effect we're interested in. May be worth a try.
Presumably you're getting the headset device's device address from the NFC comms? If so, you can create the HostName object to use in the ConnectAsync as Peter describes: http://peterfoot.net/PersistBluetoothAddressesOnWindowsPhone8.aspx
Hope you can help me on this.
I have a serial device, this device will then be connected to a USB-Serial converter, then the converter will be connected to my PC's usb port. The system will add another COM port to the Device Manager.
My question is, how can I possibly map the COM port number to the converter in C#? I can successfully enumerate available COM port in the system by doing the SerialPort.GetPortNames(), but not sure what COM port number this converter have.
thanks
ar
You can usually get some decent info out of a WMI query, although it requires the device driver to cooperate. Most do afaik. Run a query on the Win32_SerialPort class. You can use the WMI Code Creator tool to experiment with the query and auto-generate the C# code you need.
Don't count on being able to auto-select the device. You'll need a config option to allow the user to select the port. You can display the info you got from the query to help her pick the right one. Or ask her to unplug the device and plug it back in, the added COM port should be the right one.
We solved this different ways for different applications. We used explicit configuration for an instance where we had exactly one device of a particular type, but it wasn't clear what COM port it was going to be assigned until the system was configured. In another case, we had one USB cable that broke out into a hub with a bunch of converters on it, so we probed all the COM ports we could open successfully to look for our devices of interest.
A couple caveats with USB/serial converters on Windows -- if your device is something like a GPS unit that sends out data whenever it's powered on, Windows might detect it as an old serial mouse if it's plugged in during boot. Also, plugging into a different USB port is likely to chew up an additional COM port number (as well as break any explicit configuration you've done).
When i had the same problem (RFID reader), I checked each port if there was any data.
Probably it would be something in COM4 : COM9.
I know that it's not the best solution, but i used it on mobile device where i am sure about my COM connections...
Maybe in your driver's *.ini file there is some information about COM number.
If you are using an FTDI based solution for the USB<-> serial conversion, you can use the FT_PROG utility which is available from the FTDI web site to assign custom VID:PID pairs to the converter, which you can then query to identify which adapter is assigned to which virtual port.
Alternatively, you can make use of the FTDIChip-ID which is unique for each chip, details on this including code samples are located here: http://ftdichip.com/Support/SoftwareExamples/FTDIChip-ID.htm
You would have to look this up somewhere in the registry.
I can only assume this is a FTDI chip. If so, you may be able to get info from using their public API, which is included with the drivers.
If no other answers, I will check later tonite at home, as my JTAG debugger has the same chip.
Update:
Here is the registry key for my device's assigned COM port (under PortName)
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_0483&PID_5740\498C54823932\Device Parameters
I guess you can just enumerate thru the USB devices with the usbser driver.