Create a virtual serial port for widcomm stack under 32feet - c#

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

Related

ArgumentException: The given port name does not start with COM/com or does not resolve to a valid serial port

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.

Windows 8.1 Universal Store App connect to COM port

I'm currently writing a code in C# that would allow the user to read from the usb COM port (I currently have a microcontroller feeding it constant values to the usb port through serial print) and print it to the output of visual studio.
I've been reading up on a lot of documentation, specifically the MS's guide to conecting to USB:
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn312121.aspx#step1
but I'm now finding that the USB device isn't supported.
However, would it be possible to simply read from the Serial port instead of entirely connecting the USB device to the project?
Since it's a Store App, I can't use Serial.IO.Ports

Detecting Bluetooth SPP serial port disconnect (C# 4.5, Windows 8.1)

C# application using .NET 4.5 running on Windows 8.1
Classic Bluetooth device connects and uses SPP, using Microsoft Bluetooth stack only. Device is paired prior starting the application (the application is not involved in pairing and thinks its a real serial port).
Application connects to the SPP COM port using C# SerialPort class.
All works OK, until...
Bluetooth device is powered off, but...
SerialPort.IsConnected still reports true (for at least a minute).
I've tried hooking the main form's WndProc and trapping WM_DEVICECHANGE, but while I see messages for USB devices coming and going, no message is generated after the Bluetooth device is powered off.
Anybody know how to get PROMPT and ACCURATE information about the connection?
Thanks!
Best Regards, Dave

How to create a memory flash virtually via USB for an external device?

I'm working on a project in which I want to make a virtual USB flash memory via my USB port for an external device, for example, a satellite receiver that needs a memory for recording TV channels. I want to connect the PC USB port to the satellite USB port and record files directly to a file. I'm working in C#/.NET.
USB Protocol is generally between two distinct devices: The host and the client. The host says what data gets transferred and when, the client has to listen. Then there are different device classes for clients. There are USB removable media, printer, webcam ans others. USB otg differs slightly as a device can be client or host depending on the other one. For example your mobile phone van be client when connected to a PC or host wehn it's connected to a USB stick.
Now there is your satellite receiver. It wants to be host. (You know that when it uses the big Type-A socket) And it expects a removable media device like a USB stick. When you connect a printer it will not know what to to with it. Same with a network adapter or serial port.
N.B.: You cannot possibly implement "Flash Memory protocol via serial port". Because Serial Port is already the client device class. Also, there is no wire compatibility between USB and serial.
As your PC is in the same role and will not act as client in the USB connection, there is no simple solution. (I bet you knew this already, huh?)
Even if you got a PCIexpress card that acted like a flash drive, there would be more hurdles. For example file systems are not designed to be accessed by two computers simultaneously.
Back to constructive answering:
Inspired from this link you could grab some higher end microcontroller and attach a (micro)SD card. Then you let it act as a flash drive on its USB port. Use its Ethernet connection (or wifi for that matter) and provide access to the (micro)SD card via samba.
This is some really high end stuff for a microprocessor, so better not use the very cheap ones. RasberryPI Model A (not the B one, that cannot act as a USB client) or Arduino/Netduino (the most powerful) came to my mind.
I could not find a ready-to-use device.
The important thing is, that the connection to you PC uses some kind of networking and not USB. Because networking protocols have the concurrency (multiple PCs accessing the same data) covered whereas local file systems don't.

How to detect the presence of certain device

In a C# application, what are some good ways to detect the presence of certain device connected to the computer? Programatically, of course. I need to support Windows XP and 7.
Background
I've been given a huge C# application that uses some connected device. The devices are custom hardware and are not designed to use without the software. When the C# app starts, it searches for such connected devices and communicates with them when appropriate. There can be more than one connected devices. I haven't looked into the source code that searches the devices. The devices are plugged into the PC with either USB or serial cable. They appear as COM port in device manager. Sometimes there can be USB hub or serial to USB converters in between the PC and the device.
When the device is connected with certain USB hub, or certain serial to USB converter is used, sometimes the software cannot detect the device properly. Sometimes it varies from PC to PC. We're not sure if it causes for some driver.
I'm told to look into the device searching algorithm and if possible, come up with better solution and replace current implementation. I haven't done this sort of task before and I need to learn how Windows manage the devices under the hood.
How can I search for specific connected devices in C#? What are some good practice and what I should be aware of or avoid?
You can find all devices in registry: HKLM/CurrentControlSet/Enum ( http://msdn.microsoft.com/en-us/library/windows/hardware/ff546173(v=vs.85).aspx )
But there will be problem with serial port. You can't be certain in which device is connected to a serial port. It can be mobile phone, modem, mouse, your device, another custom device, etc. To guarantee that it is your device connected to a given serial port you must try to communicate with it. And if it responds in proper way - then yes, it is your device.
Because of this many programs that works with serial devices asks user to manually select serial port, where device is connected.
UPD:
Another link about enumerating serial ports: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/afb62e84-53e5-4f17-ba91-8de15c4c2e38/

Categories

Resources