vb没有提供直接读写i/o口的方法。所以只能借助其他语言来编写dll,然后在vb中调用。
如果你在windows下使用过c/c++,那么编写这样的dll可能没有什么困难。在c语言里都包括inp和outp函数。可以把下面这段c语言代码(32位)编译生成dll,然后在vb中调用。
代码如下:
#include
#include
/*作用:从指定端口读入一个字节
参数:portid端口号
返回值:读入的字节*/
int _stdcall inport(short portid)
{
return inp(portid);}
/*作用:向指定端口写入一个字节
参数:portid端口号*/
void _stdcall output(short portid,short byte)
{
outp(portid,byte);
}
/*作用:从指定端口读入一个字节
参数:portid端口号
返回值:读入的字节*/
int _stdcall inportw(short portid)
{
return inpw(portid);}
/*作用:向指定端口写入一个字节
参数:portid端口号*/
void _stdcall outportw(short portid,short word)
{
outpw(portid,(unsigned short) word);
}
注意:这种方法只能用于windows 95,不能用于windows nt