Hello,
I have rencently read the article "Programming Parallel Port in Win2k an XP Problem" and that's the same question I am facing right now.
Can anybody please tell me what to do to build a program that controls my device via parallel cable? I was just trying to write a small program and to see if my board reacts to my program. I have tried to use "UserPort" but error occurs when running inportb (at __asm in al,dx).
My sample code is listed below, please tell me if there is anything I missed:
//------------------------
----------
----------
----------
----------
----------
-
#include <windows.h>
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//------------------------
----------
----------
----------
----------
----------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
static BOOL bPrivException = FALSE;
//------------------------
----------
----------
----------
----------
----------
-
__fastcall TForm1::TForm1(TComponent*
Owner)
: TForm(Owner)
{
}
//------------------------
----------
----------
----------
----------
----------
-
void outport(UINT portid, UINT value)
{
__asm mov edx,portid;
__asm mov eax,value;
__asm out dx,ax;
}
void outportb(UINT portid, BYTE value)
{
__asm mov edx,portid
__asm mov al,value
__asm out dx,al
}
BYTE inportb(UINT portid)
{
unsigned char value;
__asm mov edx,portid
__asm in al,dx
__asm mov value,al
return value;
}
UINT inport(UINT portid)
{
int value=0;
__asm mov edx,portid
__asm in ax,dx
__asm mov value,eax
return value;
}
LONG WINAPI HandlerExceptionFilter ( EXCEPTION_POINTERS *pExPtrs )
{
if (pExPtrs->ExceptionRecord-
>Exception
Code == EXCEPTION_PRIV_INSTRUCTION
)
{
pExPtrs->ContextRecord->Ei
p ++; // Skip the OUT or IN instruction that caused the exception
bPrivException = TRUE;
return EXCEPTION_CONTINUE_EXECUTI
ON;
}
else
return EXCEPTION_CONTINUE_SEARCH;
}
BOOL StartUpIoPorts(UINT PortToAccess)
{
HANDLE hUserPort;
hUserPort = CreateFile("\\\\.\\UserPor
t", GENERIC_READ, 0, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
CloseHandle(hUserPort); // Activate the driver
Sleep(100); // We must make a process switch
SetUnhandledExceptionFilte
r(HandlerE
xceptionFi
lter);
bPrivException = FALSE;
inportb(PortToAccess); // Try to access the given port address
}
//------------------------
----------
----------
----------
----------
----------
-
void __fastcall TForm1::Button1Click(TObje
ct *Sender)
{
StartUpIoPorts(0x378);
}
//------------------------
----------
----------
----------
----------
----------
-
Thanks!
Start Free Trial