在WINDOWS下有什么办法可以读写任一个IO端口?

overflywing 2003-08-21 01:30:33
在WINDOWS下有什么办法可以读写任一个IO端口?除了写驱动外。
...全文
297 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
kittycai 2003-08-27
  • 打赏
  • 举报
回复
还是自己写个简单的驱动吧
spbabyba 2003-08-27
  • 打赏
  • 举报
回复
下载 winio吧,里面有说明我原程序.
spbabyba 2003-08-27
  • 打赏
  • 举报
回复
下载winio吧,里面有使用说明.
ajn_sailing 2003-08-26
  • 打赏
  • 举报
回复
不是的,98下可以,2000下不行的。

利用winio好些
AthlonxpX86 2003-08-26
  • 打赏
  • 举报
回复
CreateFile();只能打开驱动程序,通过驱动程序倒是能访问端口,但是前提是有驱动
lygfqy 2003-08-26
  • 打赏
  • 举报
回复
赞成使用CreateFile();
AthlonxpX86 2003-08-26
  • 打赏
  • 举报
回复
楼上的兄弟,这些函数只能访问串口,不能读写端口
AthlonxpX86 2003-08-26
  • 打赏
  • 举报
回复

#include <conio.h>

int _inp( unsigned short port );

unsigned short _inpw( unsigned short port );

unsigned long _inpd( unsigned short port );

int _outp( unsigned short port, int databyte );

unsigned short _outpw( unsigned short port, unsigned short dataword );

unsigned long _outpd( unsigned short port, unsigned long dataword );

98可以

///////////////////////////////
正好说反了,2000下可以,98下不可以,
另外这个不是太好的方法,可能会出错并受到限制,MSDN上介绍好像着使用的是DOS虚拟机上的函数,只是访问的虚拟的物理端口,然后驱动程序把虚拟端口映射到物理端口,所以在98和2000下最好都用驱动的方法,winio是这样做的,98下写了VXD驱动来操作端口,2000下用#include <conio.h>

int _inp( unsigned short port );

unsigned short _inpw( unsigned short port );

unsigned long _inpd( unsigned short port );

int _outp( unsigned short port, int databyte );

unsigned short _outpw( unsigned short port, unsigned short dataword );
等来操作端口,所以建议98下面用winio,2000下自己写驱动吧,如果2000下的不会写,我这里有http://yds_086.html.533.net/
nicepose 2003-08-26
  • 打赏
  • 举报
回复
最好使用window的api这样什么版本的windows都可以用了
通用性强,资料和实例也多
------------------------------------------
看一下以下几个函数和结构吧
OVERLAPPED
COMMTIMEOUTS
DCB

CreateFile
ReadFile
WriteFile
ClearCommError
PurgeComm
GetOverlappedResult
GetCommState
SetCommState
SetCommTimeouts

CreateEvent
SetEvent
WaitForSingleObject
AthlonxpX86 2003-08-26
  • 打赏
  • 举报
回复
楼上不信去看看winio代码
#include <windows.h>
#include <winioctl.h>
#include <conio.h>
#include "port32.h"
#include "..\drv\nt\winio_nt.h"
#include "..\drv\9x\winio_9x.h"
#include "winio.h"


bool _stdcall GetPortVal(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize)
{
tagPort32Struct Port32Struct;
DWORD dwBytesReturned;

if (!IsWinIoInitialized)
return false;

if (IsNT)//如果是winnt/2000/xp
{
switch (bSize)
{
case 1:

*pdwPortVal = _inp(wPortAddr);

break;

case 2:

*pdwPortVal = _inpw(wPortAddr);

break;

case 4:

*pdwPortVal = _inpd(wPortAddr);

break;
}
}
else//win9x
{
Port32Struct.bSize = bSize;
Port32Struct.wPortAddr = wPortAddr;

return DeviceIoControl(hDriver, WINIO_READPORT, &Port32Struct, sizeof(Port32Struct),
pdwPortVal, sizeof(DWORD), &dwBytesReturned, NULL);
}

return true;
}
在2000下的单布运行结果是调用了
switch (bSize)
{
case 1:

*pdwPortVal = _inp(wPortAddr);

break;

case 2:

*pdwPortVal = _inpw(wPortAddr);

break;

case 4:

*pdwPortVal = _inpd(wPortAddr);

break;
}
ndy_w 2003-08-22
  • 打赏
  • 举报
回复
用别人写好的驱动。google一下winio。
BSRONG 2003-08-21
  • 打赏
  • 举报
回复

#include <conio.h>

int _inp( unsigned short port );

unsigned short _inpw( unsigned short port );

unsigned long _inpd( unsigned short port );

int _outp( unsigned short port, int databyte );

unsigned short _outpw( unsigned short port, unsigned short dataword );

unsigned long _outpd( unsigned short port, unsigned long dataword );

98可以
balas 2003-08-21
  • 打赏
  • 举报
回复
98下可以,2000下不行。
_input();_output()

2,640

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧