Detecting USB virtual COM port at runtime

mjd

New member
I'm writing VB.Net code to write to an XE634BK-TFB-KU USB display. I can't guarantee, and thus hardcode, what virtual COM port it will be on. Is there a standard/best way to detect that at runtime? I think I can use WMI, but I wanted to check with The Community (you know who you are) first to see if I was overlooking an obvious/simpler solution.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

CF Tech

Administrator
There is code in the 635_WinTest (EnumSerialPort) that detects what ports are available, and it can inspect the ports for the attributes shown in device manager (COM#, USB, Module name, etc). I suppose something like that is available for VB also.
 

mjd

New member
Thanks very much for the tip; I'll delve deeper into the source you pointed out, and WMI, which I suspect is the ".Net way" of getting at that information.

Is there any lowest-common-denominator trait that I can search for to identify an LCD display on a USB port? Some sort of device class id? Ideally, I want my code to be able to work with as many devices as possible. I know that even within your own line, different displays are sent messages in very different formats, so I have no illusions about being able to talk to every LCD.
 

CF Tech

Administrator
For our USB LCDs, the base part number shows up in the string (CFA-633, CFA-635, etc).

I think you can just look for those. I would think that you would still want to give the user the option of selecting a serial port (which will not have the string)--the serial displays are still pretty popular.
 

Dexter

New member
I don't know if this helps you or not, but I used *this * code and ran with it to autodetect the port, enumerating the devices and pulling out the one with the Crystalfontz string. My app is written mainly for me, with only one 633 in use. I would have just hardcoded it but Windows likes to change port numbers on me *all* the time, and that got very annoying.
 

mjd

New member
Thanks for that link, it was very informative. I'm currently using WMI to grab descriptions of all the plug and play devices, and then I find the one one whose description contains the crystalfontz name, the model number my code knows how to communicate with, and the COM port. I then parse out the COM port number from that description. If anyone familiar with WMI knows of a better way, I'd happily convert. I like using WMI for this because .Net has classes that encapsulate it nicely. The 2.0 .Net framework will be adding classes for serial ports, which may solve this problem more neatly.
 
Top