My program needs to find out the resource number of lpt1: which can be different from computer to computer. It is usually something like 0x278 or 0x378...
Can someone please help me with this ?
Printable View
My program needs to find out the resource number of lpt1: which can be different from computer to computer. It is usually something like 0x278 or 0x378...
Can someone please help me with this ?
Look at WMI class Win32_Printer.
http://msdn.microsoft.com/library/en...asp?frame=true
http://www.codeproject.com/system/UsingWMI.asp
Hi,
I did take a look at it, but all that I can see is that I can get the name of the printer ports like "lpt1" and I can get that already with enumports. What I need is the corresponding hardware resource port adress (0x278, 0x378, etc...).
But thanks anyway...
:)
I found a way to enumerate the number of the real lpt ports and find the matching port addresses.
If anybody wants to know the solution let me know and I will upload it...
:)
Thats so nice u dude... :) and nothing wrong in sending the code now as it might use for someone latter when they search this forum .. :)Quote:
Originally Posted by Zaph-0
Well, I needed this function because I am controlling a robot arm with avr microprocessors connected to the parallel port. I didn't find anything on the net on how to get the port adresses automatically which would mean I would have to set the parallel port adress manually and I didn't like that. So I had to get a little "creative" with the registry...Quote:
Originally Posted by jayender.vs
I tried it on several computers with different settings for the parallel port (including automatic setting, boot setting and forced setting) and it always worked for me.
If someone uses it and finds a mistake please let me know...
But here you go:
:)
The return value is either NULL if it couldn't find anything or an array of ints with the first value the number of parallelports and then pairs of ints describing the lpt number and the serial adress. You have to delete the array if you don't need it anymore or it will result in a memory leak.Code:int * CMicrobotView::GetPortAddresses()
{ HKEY key1;
HKEY key2;
int i,x;
char buffer[2000];
char branch1[300];
char branch2[300];
int type,size;
int * list;
//
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Enum\\ACPI", NULL, KEY_READ, &key1) != ERROR_SUCCESS)
{ return NULL;
}
//
list = new int[2*10 + 1];
x = 0;
// Enumerate HW
for(i=0;(RegEnumKey(key1, i, buffer, sizeof(buffer)) == ERROR_SUCCESS) && (x<10); i++)
{ if((strlen("SYSTEM\\CurrentControlSet\\Enum\\ACPI") + strlen(buffer)) < (sizeof(branch1) - 2))
{ sprintf(branch1, "SYSTEM\\CurrentControlSet\\Enum\\ACPI\\%s\\", buffer);
// Enter HW-Tree
if((RegOpenKeyEx(HKEY_LOCAL_MACHINE, branch1, NULL, KEY_READ, &key2) != ERROR_SUCCESS)
|| (RegEnumKey(key2, 0, buffer, sizeof(buffer)) != ERROR_SUCCESS))
{ RegCloseKey(key2);
continue;
}
strcat(branch1,buffer);
// Check Device Parameters
size = sizeof(buffer);
sprintf(branch2,"%s\\Device Parameters", branch1);
if((RegOpenKeyEx(HKEY_LOCAL_MACHINE, branch2, NULL, KEY_READ, &key2) != ERROR_SUCCESS)
|| (RegQueryValueEx(key2, "PortName", 0, (DWORD*)&type, (BYTE*)buffer, (DWORD*)&size) != ERROR_SUCCESS)
|| (strncmp(buffer,"LPT",3) != 0))
{ RegCloseKey(key2);
continue;
}
list[x+1+0] = buffer[3]-'0';
// Portname found -> Extract Data
RegCloseKey(key2);
size = sizeof(buffer);
sprintf(branch2,"%s\\LogConf", branch1);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, branch2, NULL, KEY_READ, &key2) != ERROR_SUCCESS)
{ RegCloseKey(key2);
continue;
}
//
if((RegQueryValueEx(key2, "ForcedConfig", 0, (DWORD*)&type, (BYTE*)buffer, (DWORD*)&size) == ERROR_SUCCESS)
|| (RegQueryValueEx(key2, "BootConfig" , 0, (DWORD*)&type, (BYTE*)buffer, (DWORD*)&size) == ERROR_SUCCESS))
{ list[x+1+1] = ((BYTE)buffer[24]) + ((BYTE)buffer[25]) * 0x100;
x++;
}
else
{ if(RegQueryValueEx(key2, "BasicConfigVector", 0, (DWORD*)&type, (BYTE*)buffer, (DWORD*)&size) == ERROR_SUCCESS)
{ list[x+1+1] = buffer[57] * 0x100 + buffer[56];
x++;
}
}
//
RegCloseKey(key2);
}
}
RegCloseKey(key1);
//
if(x == 0)
{ delete [] list;
return NULL;
}
list[0] = x;
return list;
}
example:
list[0] = 2 -> number of parallel ports found (up to 10)
list[1] = 1 -> lpt1:
list[2] = 0x2f8 -> serial adress 0x278
list[3] = 2 -> lpt2:
list[4] = 0x3f8 -> serial adress 0x378
Have fun...
:)
To find Printer port address
Step 1, Go to the command prompt
Type debug
ex:
c:\ debug
the prompt will change to "-"
Then type the following
- 0004:0008 l8
All four port address will be displayed( i forgot the order).
Mind you it is (L8) not (one 8), in the above command
i know, this was not the solution you were expecting, may be you may
get new ideas to solve your problem.
regards
pradish