I am writing a program to access parallel port in Windows XP.
taking help from net i found a program called UserPort which opens ports.
Using a small program in C using stdio and conio include files i could access the port.
However the problem is i have to write code in C++ and when i try to compile the same code in C++ as a .cpp file the compiler gives an error saying "_outp undeclared " and " sleep undeclared". the same code compiles properly in c using same IDE.
I am using Dev-C++ 4.9.9.2. I cant use any other compiler.
My code is given below as a c file
/******
binary counter : This will count from 0 to 255 This takes printer port address as 0x378 and pauses for 250 mS between every count *******/
include <stdio.h>
include <conio.h> /required for _outp/
int main()
{
int x;
for(x = 0;x<=255;x++)
{
_outp(0x378,x);
sleep(250);
}
return 0;
}
Pl help. Its urgent as same code doesnt work when compiled as C++ file.
Shaleen Singh
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-08-17
The _outp() function is declared in Microsoft's conio.h - however if you have a conio.h file at all, it is likely to be a clone of the Borland library header (which is very different). Moreover direct hardware I/O will not work at all in NT/2K/XP because they are kernel protected resources, you will need a port I/O driver.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've always just used window.h and Sleep(), which works with C and C++. I checked my header files and I don't even have "sleep" defined anywhere, so you must be doing something different if that worked for you in C. I do have _sleep, and I stuck it into a C++ prog and it did compile with stdlib.h included. Hope that helps.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks guys windows.h and stdlib.h both solved my problem of Sleep function. both Sleep and _sleep are working, but what about _outp function. Is there any other function to output data to a parallel port in Dev c++.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
/******
binary counter : This will count from 0 to 255 This takes printer port address as 0x378 and pauses for 250 mS between every count
*******/
include <stdio.h>
include <conio.h> /required for _outp/
int main()
{
int x;
for(x = 0;x<=255;x++)
{
_outp(0x378,x);
sleep(250);
}
return 0;
}
Shaleen Singh
The _outp() function is declared in Microsoft's conio.h - however if you have a conio.h file at all, it is likely to be a clone of the Borland library header (which is very different). Moreover direct hardware I/O will not work at all in NT/2K/XP because they are kernel protected resources, you will need a port I/O driver.
Clifford
I've always just used window.h and Sleep(), which works with C and C++. I checked my header files and I don't even have "sleep" defined anywhere, so you must be doing something different if that worked for you in C. I do have _sleep, and I stuck it into a C++ prog and it did compile with stdlib.h included. Hope that helps.
Sorry that should be windows.h, duh. Too early in the morning.
Thanks guys windows.h and stdlib.h both solved my problem of Sleep function. both Sleep and _sleep are working, but what about _outp function. Is there any other function to output data to a parallel port in Dev c++.