News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

port i/o under winxp

Started by winter, January 15, 2005, 01:11:31 AM

Previous topic - Next topic

winter

without using a driver is it possible to do low level input/output to ports(Primarly 0x378) under windows xp?

Thanks in advance!

dioxin

Winter,
   I use WinIO from http://www.internals.com/ . I don't think it's using a driver (although it has that option) because it gives direct access to the I/O space which you can use with IN and OUT asm instructions.

Paul.

winter

dioxin,
     Thanks, I didn't test yet I'm trying to learn how it works.

Is there any reason that motivated such a restriction?

Thanks in advance!

pbrennick

WinIO does use a device driver.
QuoteIt bypasses Windows protection mechanisms by using a combination of a kernel-mode device driver and several low-level programming techniques.

Paul

dioxin

Paul,
WinIO allows 2 methods for accesssing the I/O space once it is installed.
you can use

GetPortVal(201, joy,1)

which would call a device driver and read the port value from I/O location 201 into location joy

Or
you can use direct I/O access using IN and OUT

mov dx,201
in al,dx
mov joy,ax


The first way uses a device driver which is slow and not compatible with software written the "usual" way.
The second method, although stuff has to be installed and setup, I don't think is classed as using a device driver because the application gets direct access to the I/O. This is done by WinIO removing the permission restrictions on I/O access.

Paul.

winter

Is there anyway to change settings in windows XP (Doesn't have to be programaticly) so that my program may atleast access port 0x378?

Thanks in advance!

tenkey

#6
No. Officially, the device driver is the only way on NT-derived systems to directly access hardware.

The device driver provides centralized control over a device. The device driver can be set up so that one program does not cancel the desired effects of another program, if they are sharing the device. Because of the one-code-for-access-to-all-device-functions capability, the file/device opening function CreateFile can also enforce that, at most, one program, at any given time, is granted access to the hardware.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

winter

Lets say I have a joystick(2 buttons) that sets 2 pins on port 0x378 to 1, 0 respectufully to if the button is up, or down. Where should I start for developing this driver?

Thanks in advance!

dioxin

Winter,
    use WinIO from http://www.internals.com/ . It'll do what you need.


Paul.

winter

ok

Heres what I have
  SC_HANDLE hSCManager;
  SC_HANDLE hService;
  SC_HANDLE hs;
  HANDLE hDriver;

// adds " around path of exe
char *f;
f = new char[512];
memset(f, 0, 512);
f[0] = '\"';
f[strlen(argv[0])] = '\"';
strcpy(&f[1], argv[0]);
f[strlen(argv[0])+1] = '\"';


hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

if(hSCManager == NULL)
{
cout << "Manager failed" << flush;
freeze(); // Goes into an infite loop for console not to close
}
    hService = CreateService(hSCManager,
                             "WINIO1",
                             "WINIO1",
                             SERVICE_ALL_ACCESS,
                             SERVICE_KERNEL_DRIVER,
                             (1 == true) ? SERVICE_DEMAND_START : SERVICE_SYSTEM_START,
                             SERVICE_ERROR_NORMAL,
                             TEXT("C:\\ab.sys"),
                             NULL,
                             NULL,
                             NULL,
                             NULL,
                             NULL);
if(hService == NULL)
{
cout << "Service failed\n";
cout << flush;
hs = OpenService(hSCManager, "WINIO1", SERVICE_ALL_ACCESS);
if(hs != NULL)
DeleteService(hs);
freeze();
}
hs = OpenService(hSCManager, "WINIO1", SERVICE_ALL_ACCESS);
if(hs == NULL)
{
cout << "failed to open service\n" << flush;
freeze();
}
if(StartService(hs, 0, NULL)==0) // This fails
{
cout << "start failed\n" << flush;
if(GetLastError()==ERROR_SERVICE_ALREADY_RUNNING)
cout << "already running\n" << flush;
freeze();
}


    hDriver = CreateFile("\\\\.\\WINIO1",
                         GENERIC_READ | GENERIC_WRITE,
                         0,
                         NULL,
                         OPEN_EXISTING,
                         FILE_ATTRIBUTE_NORMAL,
                         NULL);
if(hDriver==INVALID_HANDLE_VALUE)
{
cout << "opened failed\n" << flush;;
//freeze();
}
__asm{
mov dx, 0x378
mov al, 2
out dx, al
}
DeleteService(hs);
CloseServiceHandle(hs);
CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);


Why does StartService fail.

Thanks in advance!

farrier

winter,

You could start at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/communications_resources.asp

You can use:

CreateFile - to open a serial or parallel port
ReadFile - to read from that port
WriteFile - to write to that port

This works in all Window versions without any drivers or "tricks"

hth

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)


tenkey

Quote from: farrier on January 16, 2005, 04:19:15 AM
You can use:

CreateFile - to open a serial or parallel port
ReadFile - to read from that port
WriteFile - to write to that port

These functions actually use device drivers to perform their functions. The drivers just happen to be included with Windows. They might have too much latency.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

farrier

Too much latency for serial comminications?  Hard to believe!  I must admit that I've only used these functions up to 115,200 bps, but have never noticed any latency problems.  But it might depend on the application in question.

Quote from: tenkey on January 17, 2005, 01:26:36 AM

These functions actually use device drivers to perform their functions. The drivers just happen to be included with Windows

I was referring to something a programmer/user would have to add to their Windows installation/application.

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

tenkey

For data communications, latency is usually not a problem.

However, when controlling or sampling electronics, you sometimes need a guaranteed response time. And that response time might be very short. When this requirement is too hard to meet, you increase the intelligence of the device, so that it relies less on the PC for timed control.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8