AN197 Silicon_Laboratories, AN197 Datasheet - Page 9

no-image

AN197

Manufacturer Part Number
AN197
Description
Serial Communications Guide FOR THE Cp210x
Manufacturer
Silicon_Laboratories
Datasheet
7.2. Windows 98 SE
Alternatively, to find the port number in Windows 98 SE the corresponding key listed above needs to be opened.
This is also done using several registry calls using Windows API functions. This key is not directly entered using
the VID, PID, and serial number. Instead, each time a new device appears it is enumerated and stored in the
registry. So two lookups have to be performed: one to determine if the current key in question contains the VID, PID
and serial number needed, and another to actually determine the port number if the VID, PID, and serial number
match from the previous lookup. The function is passed the VID, PID, and serial number, and the return value is
either the port number that the CP210x is located on, or a –1 if there is a failure. Here is the function to find the
CP210x port number in Windows 98 (this function can be copied straight into application code that needs to
discover the COM port number):
int GetPortNum98(WORD vid, WORD pid, char* ser)
{
// Variables used for Registry access
HKEY tmpKey;
CString portKeyString, serKeyString;
int serialIndex;
DWORD valtype;
char* portString;
DWORD length = 100;
portString = new char[101];
// Set portnum to -1, so if there is an error we will
// know by returning a negative port value
int portNum = -1;
// We will search through the keys by index, starting at 0
// Use this index in the key "Enum\SLABCR\guid\XXXX"
serialIndex = 0;
serKeyString.Format("Enum\\SLABCR\\guid\\%.4d", serialIndex);
// Loop through and convert the serial string to all upper case and replace spaces
// for Win98
int i = 0;
while (ser[i] != '\0')
{
}
// The portkey string should look like this when we query the CLowerDeviceID
// "USB\VID_XXXX&PID_XXXX&MI_00\\XXXX_00" where the XXXX's are Vid, Pid and serial
// string
portKeyString.Format("USB\\VID_%04X&PID_%04X&MI_00\\%s_00", vid, pid, ser);
//
//
// in the registry
while (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, serKeyString, &tmpKey))
{
if (ser[i] == 0x20)
else if ((ser[i] >= 0x61) && (ser[i] <= 0x7A))
i++;
// Determine the status of the call
DWORD status = RegQueryValueEx(tmpKey, "CRLowerDeviceID", NULL, &valtype,
Open keys to get to the key where the port number is located. This key is:
HKLM\Enum\SLABCR\guid\XXXX\Portname is the key and we will loop through each key
ser[i] = '_';
ser[i] -= 32;
(unsigned char *)portString, &length);
Rev. 0.6
AN197
9

Related parts for AN197