一般访问设备使用CreateFile打开设备,然后使用ReadFile/WriteFile读写设备。
比如:
HANDLE hFile = CreateFile(..., FILE_FLAG_OVERLAPPED, ...)//指定以异步方式打开
BYTE bBuffer[100]
OVERLAPPED o = { 0 }
o.Offset = 345
BOOL bReadDone = ReadFile(hFile, bBuffer, 100, NULL, &o)// bReadDone 指定I/O请求是不是以同步方式打开
DWORD dwError = GetLastError()
if (!bReadDone &&(dwError == ERROR_IO_PENDING)) { //异步方式打开
// The I/O is being performed asynchronouslywait for it to complete
WaitForSingleObject(hFile, INFINITE)
bReadDone = TRUE
}
if (bReadDone) {
// o.Internal contains the I/O error
// o.InternalHigh contains the number of bytes transferred
// bBuffer contains the read data
} else {
// An error occurredsee dwError
}
可以,仅记住,linux的一切都是文件,对文件的 *** 作也就是对设备的 *** 作。比如我接上一个鼠标,目录下有对应设备文件(一般是在/dev/input/mouse1),我可以对其进行IO *** 作,从而检测鼠标位移,点击等。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)