
#if !defined(DO_MYPORT_IO_H__)
#define DO_MYPORT_IO_H__

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <winioctl.h>
#include <winsvc.h>

// 设备类型定义
// 0-32767被Microsoft占用，用户自定义可用32768-65535
#define FILE_DEVICE_MYPORT	0x0000E880

// I/O控制码定义
// 0-2047被Microsoft占用，用户自定义可用2048-4095 
#define MYPORT_IOCTL_BASE 0xC8B

#define IOCTL_MYPORT_READ_BYTE		CTL_CODE(FILE_DEVICE_MYPORT, MYPORT_IOCTL_BASE, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_MYPORT_WRITE_BYTE		CTL_CODE(FILE_DEVICE_MYPORT, MYPORT_IOCTL_BASE+1, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_MYPORT_READ_WORD		CTL_CODE(FILE_DEVICE_MYPORT, MYPORT_IOCTL_BASE+2, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_MYPORT_WRITE_WORD		CTL_CODE(FILE_DEVICE_MYPORT, MYPORT_IOCTL_BASE+3, METHOD_BUFFERED, FILE_ANY_ACCESS)


// 接口函数
BOOL OpenMyPort();
BOOL CloseMyPort();
BYTE ReadPortByte(WORD port);
void WritePortByte(WORD port, BYTE data);
WORD ReadPortWord(WORD port);
void WritePortWord(WORD port, WORD data);

#endif // !defined(DO_MYPORT_IO_H__)
