dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 07 January 2006, 17:45 PM Post subject: |
|
|
We use a process called "comm port enumeration" where we look at entries in the registry to see what devices are available. The actual code used is:
| Code: | //
// Enumerate the existing comm ports, invoking a caller-supplied function
// for each port.
//
void CommPort::
EnumCommPorts(EnumCommPortProc func, void *arg)
{
HKEY hkCommMap;
if (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", 0,
KEY_QUERY_VALUE, &hkCommMap) != ERROR_SUCCESS)
return;
char *nameBuf = 0;
char *valBuf = 0;
DWORD cnt, maxNameLen, maxValLen;
if (::RegQueryInfoKey(hkCommMap, NULL, NULL, NULL, NULL, NULL, NULL,
&cnt, &maxNameLen, &maxValLen, NULL, NULL) == ERROR_SUCCESS)
{
// The max value name size is returned in TCHARs not including
// the terminating null character.
nameBuf = new char[++maxNameLen * sizeof(char)];
// The max value size is returned in bytes needed to hold the UNICODE
// strings including terminating null character regardless of the
// function type (ANSI or UNICODE).
maxValLen = (maxValLen / 2) * sizeof(char);
valBuf = new char[maxValLen];
if (nameBuf && valBuf)
{
for (DWORD idx = 0; idx < cnt; ++idx)
{
DWORD nameLen = maxNameLen;
DWORD valLen = maxValLen;
DWORD type;
LONG nRes = ::RegEnumValue(hkCommMap, idx, reinterpret_cast<LPTSTR>(nameBuf),
&nameLen, NULL, &type, reinterpret_cast<LPBYTE>(valBuf), &valLen);
unsigned port = GetPort(valBuf);
if ((nRes == ERROR_SUCCESS) && (type == REG_SZ) && !func(valBuf, port, arg))
break;
}
}
}
delete[] valBuf;
delete[] nameBuf;
::RegCloseKey(hkCommMap);
}
//
// Extract the comm port number from a string in the form COMnnn.
// Return zero for an invalid string or other error.
//
unsigned CommPort::
GetPort(const char *str)
{
unsigned port = 0;
if (str != NULL)
{
while (isspace(*str))
str++;
if (memicmp(str, "COM", 3) == 0)
{
str += 3;
while (isdigit(*str))
port = port * 10 + (*str++ - '0');
}
}
return(port);
}
|
Another user has reported that this does not work on Win98SE. So far, there have been no reports of it not working on Win2K or later.
As a workaround, you can set the comm port and related parameters by adding/editing lines in the User Options file. The lines have the following form:
| Code: | debug.comport=2
debug.speed=19200
debug.capture=1
debug.reset=1
download.verify=1
download.clear=1
download.quiet=0
|
The first two lines set the port and speed (other than for downloading). These should be all that you need. The remaining entries correspond to checkboxes on the Device Options dialog. |
|
pjc30943
Joined: 02 Dec 2005
Posts: 220
|
|
Posted: 08 January 2006, 1:43 AM Post subject: |
|
|
| dhouston wrote: | This is a 98SE machine but all of the ports are listed in the registry where you're looking.
I'll try the workaround. |
That happened to me as well: in the registry, but not the box. The workaround has functioned perfectly, including using the zload instead of the default F5 (see one of Don's previous emails). |
|