TO dycdyc123(重出江湖) :kingbug 原来是你,前两天我还当是谁。这个帖子我好几天没看了,今天看揭帖了,所以看看。以后多交流吧。
to dycdyc123(重出江湖) :我不知道你仔细看了没有!?你摘录得说明里写得很清楚啊。
你的问题:
“用winio以后,怎么还用_outp(0x378,outcommand),_inp(0x378)?读写端口需要用winio的GetPortVal SetPortVal来读写,”
你得答案:
Note: Under Windows 98/ME, an application must use the GetPortVal function to read values from an I/O port. Under Windows NT/2000/XP, it is possible to use the _inp/_inpw/_inpd functions instead of using GetPortVal, provided that the InitializeWinIo function has been called beforehand.
to xiaohedou(小黑豆):不知道你用过winio没有,用winio以后,怎么还用_outp(0x378,outcommand),_inp(0x378)?读写端口需要用winio的GetPortVal SetPortVal来读写,下面是winio提供的这两个函数说明
GetPortVal
This function reads a BYTE/WORD/DWORD value from an I/O port.
bool _stdcall GetPortVal(
WORD wPortAddr,
PDWORD pdwPortVal,
BYTE bSize
);
Parameters
wPortAddr
[in] I/O port address
pdwPortVal
[out] Pointer to a DWORD variable that receives the value obtained from the port.
bSize
[in] Number of bytes to read.
Can be 1 (BYTE), 2 (WORD) or 4 (DWORD).
Return Values
If the function succeeds, the return value is true. Otherwise, the function returns false.
Remarks
The GetPortVal function reads a byte, a word or a double word from the specified I/O port.
Note: Under Windows 98/ME, an application must use the GetPortVal function to read values from an I/O port. Under Windows NT/2000/XP, it is possible to use the _inp/_inpw/_inpd functions instead of using GetPortVal, provided that the InitializeWinIo function has been called beforehand.
SetPortVal
This function writes a BYTE/WORD/DWORD value to an I/O port.
bool _stdcall SetPortVal(
WORD wPortAddr,
DWORD dwPortVal,
BYTE bSize
);
Parameters
wPortAddr
[in] I/O port address
dwPortVal
[in] Value to be written to the port
bSize
[in] Number of bytes to write.
Can be 1 (BYTE), 2 (WORD) or 4 (DWORD).
Return Values
If the function succeeds, the return value is true. Otherwise, the function returns false.
Remarks
The SetPortVal function writes a byte, a word or a double word to the specified I/O port.
Note: Under Windows 98/ME, an application must use the SetPortVal function to write values to an I/O port. Under Windows NT/2000/XP, it is possible to use the _outp/_outpw/_outpd functions instead of using SetPortVal, provided that the InitializeWinIo function has been called beforehand.
void CParallelPort::Open(int nPort)
{
//Call Close just in case we already have the port open
Close();
m_nPortIndex = nPort - 1;
if (m_nPortIndex < sm_Ports.GetSize())
{
//Cache the base address of the port for performance reasons
m_nBaseAddress = sm_Ports.ElementAt(m_nPortIndex).m_nBaseAddress;
//Call CreateFile to open up the parallel port. This prevents other apps
//causing problems when we do the Port IO directly.
CString sPort;
sPort.Format(_T("\\\\.\\LPT%d"), nPort);
m_hPort = CreateFile(sPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (m_hPort == INVALID_HANDLE_VALUE)
{
TRACE(_T("Failed to open parallel port, LPT%d\n"), nPort);
Close();
AfxThrowParallelException();
}
}
else
{
TRACE(_T("Could not find the parallel port, LPT%d\n"), nPort);
Close();
AfxThrowParallelException(ERROR_FILE_NOT_FOUND);
}
}
SUBPRINT PORC NEAR
PUSH AX
PUSH DX
MOV DX,378H
OUT DX,AL
MOV DX,379H
SUBWAIT:
IN AL,DX
TEST AL,10000000B
JE SUBWAIT
MOV AL,00001101B
MOV DX,37AH
OUT DX,AL
MOV AL,00001100B
OUT DX,AL
POP DX
POP AL
RET
SUBPRINT ENDP