Bluetooth COM Ports - c#

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.

Related

Is it possible to simulate com port sending and receiving data using only C# programming?

I have a device which sends data by com port on my computer.
I know how to simulate it, but the controller must be plugged in to simulate sending data (using Proteus)
Is it possible to simulate the com port sending data without having any external device plugged in?
For example: I want to write a C# program which opens the com port and waits for data, and another c# program which writes data on the same port.
The best way to do this is to use a software COM port emulator. I use com0com :
Null-modem emulator
This provides virtual NM COM port pairs on the system (ie: what is output to one is input to the other and vice-versa). The devices show up in Device Manager just like a real COM port so you interact with them in C# as though they were real hardware devices.
For simplicity's sake, get yourself a com port or null modem emulator. You'll get very far off track, and maybe waste a lot of time, trying to do this yourself.
See this post, too:
Faking an RS232 Serial Port

Device information on com port c#

I had such a problem: in the three com ports have devices with which I work in software. Not installed drivers. The problem is: How can I find out which of the ports is connected with which of device? Thanks in advance
You may not be able to identify the devices in the COM ports. There is no industry standard nor requirement for device names. Some protocols such as SCSI, ATAPI and USB have commands that you can use to identify the device. For standard RS232, there is no such requirement.
What kind of devices do you have to identify? Plotters, thumbdrives, tape drives, etc?
There is no reliable way to do this. You can poll the COM ports, but many devices don't even respond to commands they receive. A COM port could only have Tx and Gnd wired up, so the connected device might not even be able to respond. You have very little to work with when dealing with RS232.

Getting info on USB-Serial converter

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.

Create a virtual serial port for widcomm stack under 32feet

Currently I am doing a project involves a bluetooth communication setup between a PDA and a small embedded device. This small embedded device can only be communicated with a virtual serial port over a bluetooth link.
The PDA is the ipaq running with windows mobile 6, and I am using c#.
I had done a program which can communication with the serial port over bluetooth. But the only issue is every time I run this program, I have to active the bluetooth radio, and manually pairing this device with the pda via the bluetooth manager. What I want to do is when running this program, it can establish the bluetooth connection between the pda and the embedded module.
So I am using functions from the 32feet prject. This is one issue is I cant make the virutal serial port part, as I think the 32feet project can only make virual serial ports for the window bluetooth stack but not the widcomm bluetooth stact, which the ipaq is using.
Therefore, are there any existing c# classes or stacks that can make virtual serial port under widcomm for windows mobile 6.
Thanks
See my answer at Widcomm bluetooth : how to open the virtual COM. I generally recommend using a direct sockets (BluetoothClient) connection. That seems better to me than having to create a virtual serial port, which is difficult on various platforms, and then open it, and then gets no errors when the peer device goes out of range etc etc. :-)
Alan

question about PORT

I have written a program in C# that sends text to COMx.
I wish to test it using HyperTerminal, meaning I want to read the text that I send with my program. When I set the WAIT FOR CALL in HyperTerminal, my program is refused access to the given port.
How can I test my program? Is it possible?
The best answer I can give is that the serial port is locked by your program and hence HyperTerminal cannot access the port as it is in use by your program. The best thing is to use a null modem cable loopback device in which you can send data and it will get looped back, like what EricLaw suggests.
Hope this helps,
Best regards,
Tom.
tommieb75 and EricLaw's answers are both right. When an application opens a serial port, the port is opened exclusively and no other app can work with it.
In order to test my serial applications I always use com0com. You can create a pair of virtual linked serial ports and setup your app to write to one of them and the HyperTerminal to listen to the other one.
This tool has helped me countless times. I strongly recommend it.
Take your serial cable and solder in on your RX or TX side of the COM port. Now, connect this to another COM port on your PC. Tada - now you can monitor what you are sending or receiving on this port by listening in on the other. Don't terminate TX on this other COM port so you don't disturb this connection. I have a couple of these cables in the office for this very purpose. I don't trust Serial Port monitoring software.
Your best bet would probably be to put a null-modem DB9 cable from COM1 to COM2 and use COM2 to talk to COM1.

Categories

Resources