I have recently begun a project involving the control of stepper motors through the parallel port. In order to minimize risk to my new computer's motherboard from back emf and the like, I exhumed an old Windows 95 computer. It seemed lucky enough that Windows 95 also happens to support direct parallel port access through the use of the outportb function, but Dev-C++ is throwing linker errors.
Here's a little program. I'm retyping this now as this old computer's not hooked up to the internet and I have no floppies lying around.
include <stdio.h>
include <stdlib.h>
include <dos.h>
int main(int argc, char *argv[])
{
outportb(0x378,1);
return 0;
}
retyping the log file...
Compiler: default compiler
building makefile: "E:\dev-cp]makefile.win" all
gcc.exe -c templates/main.c -o templates/main.o -l " e:/dev-cpp/include"
gcc.exe templates/main.0 -o "project1.exe" -L"e:/dev-cpp/lib"
templates/main.o(.text+0x3a):main.c:undefined reference to 'outportb'
colect2:id returned 1 exit status
execution terminated
and the error again:
[linker error] undefined reference to 'outportb'
id returned 1 exit status
So, any helpful hints?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-07-27
Hmmm... its a solution. But the extern declaration would have worked and allowed you to remain with 32bit code - just not on NT/2K/XP/Vista or whatever comes next. The 16 bit code solution might give you greater portability, but note that Win64 does not have support for 16 bit code so although the TC2 code will run on Win32 and get around the ioport access issue it is not future proof.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-07-26
While you can use port I/O in Win95/98/ME, it is not possible in later versions of Windows, so it is probably a good idea not to rely upon it.
In the MSVCRT library (used by MinGW), the functions are _outp, _outpw, _outpd, _inp, _inpw, _inpd. The functions you are to use are the Borland versions. These functions are declared in Microsoft's conio.h header - this is neither the same as Borland's conio.h nor is it provided with Dev-C++. You can make your own extern declarations to access the functions:
extern int _outp( unsigned short port, int databyte );
extern unsigned short _outpw( unsigned short port, unsigned short dataword );
extern unsigned long _outpd( unsigned short port, unsigned long dataword );
extern int _outp( unsigned short port, int databyte );
extern unsigned short _outpw( unsigned short port, unsigned short dataword );
extern unsigned long _outpd( unsigned short port, unsigned long dataword );
Many such drivers that I'd normally recommend (and which you will find by searching the forum) such as the often recommended logix4u inpout32.dll driver seem to have disappeared from the Web.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have recently begun a project involving the control of stepper motors through the parallel port. In order to minimize risk to my new computer's motherboard from back emf and the like, I exhumed an old Windows 95 computer. It seemed lucky enough that Windows 95 also happens to support direct parallel port access through the use of the outportb function, but Dev-C++ is throwing linker errors.
Here's a little program. I'm retyping this now as this old computer's not hooked up to the internet and I have no floppies lying around.
include <stdio.h>
include <stdlib.h>
include <dos.h>
int main(int argc, char *argv[])
{
outportb(0x378,1);
return 0;
}
retyping the log file...
Compiler: default compiler
building makefile: "E:\dev-cp]makefile.win" all
gcc.exe -c templates/main.c -o templates/main.o -l " e:/dev-cpp/include"
gcc.exe templates/main.0 -o "project1.exe" -L"e:/dev-cpp/lib"
templates/main.o(.text+0x3a):main.c:undefined reference to 'outportb'
colect2:id returned 1 exit status
execution terminated
and the error again:
[linker error] undefined reference to 'outportb'
id returned 1 exit status
So, any helpful hints?
Hmmm... its a solution. But the extern declaration would have worked and allowed you to remain with 32bit code - just not on NT/2K/XP/Vista or whatever comes next. The 16 bit code solution might give you greater portability, but note that Win64 does not have support for 16 bit code so although the TC2 code will run on Win32 and get around the ioport access issue it is not future proof.
I'm sorry, I forgot to give you the version:
It's 4.9.9.2
While you can use port I/O in Win95/98/ME, it is not possible in later versions of Windows, so it is probably a good idea not to rely upon it.
In the MSVCRT library (used by MinGW), the functions are _outp, _outpw, _outpd, _inp, _inpw, _inpd. The functions you are to use are the Borland versions. These functions are declared in Microsoft's conio.h header - this is neither the same as Borland's conio.h nor is it provided with Dev-C++. You can make your own extern declarations to access the functions:
extern int _outp( unsigned short port, int databyte );
extern unsigned short _outpw( unsigned short port, unsigned short dataword );
extern unsigned long _outpd( unsigned short port, unsigned long dataword );
extern int _outp( unsigned short port, int databyte );
extern unsigned short _outpw( unsigned short port, unsigned short dataword );
extern unsigned long _outpd( unsigned short port, unsigned long dataword );
For portability and longevity however you should consider using a Port I/O driver such as: http://www.beyondlogic.org/porttalk/porttalk.htm
Many such drivers that I'd normally recommend (and which you will find by searching the forum) such as the often recommended logix4u inpout32.dll driver seem to have disappeared from the Web.
Thanks very much for your reply. Actually, portability is the least of my concerns and the solution I ended up taking was to install Turbo C 2 :)
I have inpout32.dll installed on my normal computer.
Thanks again