You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.3 KiB
C++

#pragma once
#include <windows.h>
#include "LaserLogger.h"
typedef HANDLE(WINAPI*pCH365mOpenDevice)(ULONG iIndex, BOOL iEnableMemory, BOOL iEnableInterrupt);
typedef BOOL(WINAPI*pCH365mReadIoByte)(ULONG iIndex, PVOID iAddr, PUCHAR oByte);
typedef BOOL(WINAPI*pCH365mSetA15_A8)(ULONG iIndex, UCHAR iA15_A8);
typedef BOOL(WINAPI*pCH365mWriteIoByte)(ULONG iIndex, PVOID iAddr, UCHAR iByte);
typedef VOID(WINAPI*pCH365mCloseDevice)(ULONG iIndex);
#define LASER_PORT 7 //激光开关端口
#define PORT_CNT 8 //低位端口的个数
#define OUT_PORT_ADDR_L 0xDE //输出端口的地址--低8 位
#define OUT_PORT_ADDR_H 0xDD //输出端口的地址--高8 位
#define IN_PORT_ADDR_L 0x1F //输入端口的地址--低8 位 10 进制31
#define IN_PORT_ADDR_H 0xDF //输入端口的地址--高8 位 10 进制223
class Pci365CardMgr
{
typedef struct SPciPort
{
SPciPort()
{
num = -1;
bReverse = false;
}
public:
int num;//端口的编号
bool bReverse;//是否反转(反转了以后读取和写入都会反过来)
}SPciPort;
public:
Pci365CardMgr();
~Pci365CardMgr();
public:
static Pci365CardMgr* m_instance;
long m_OutPortStateLow;//记录当前输出端口的状态(低八位)--用于向端口写数据
long m_OutPortStateHigh;//记录当前输出端口的状态(高八位)--用于向端口写数据
HINSTANCE m_PciCh365Handle;//保存Ch365动态链接库的句柄
HANDLE m_DeviceHandle;//pci设备的句柄
bool m_bIniPci365Card = false;
public:
void InitPci365Card();
public:
bool ReadDll();
bool IniPciCard();
void CtrlLaserGate(bool bon);
void WritePortState(SPciPort PciPort, bool bOpen);
bool LowOrHight(int &PortNum);
long& GetOutPortState(bool bLow);
int GetPortAddr(bool bLow, bool bWirte);
long SetBitOn(long PortVal, int PortIdx);
BYTE SetBitOff(BYTE PortVal, int PortIdx);
void WriteIoPortByte(int PortAddr, long PortVal);
//dll 函数指针
pCH365mOpenDevice CH365mOpenDevice;// 打开CH365设备,返回句柄,出错则无效
pCH365mReadIoByte CH365mReadIoByte;//从I/O端口读取一个字节
pCH365mSetA15_A8 CH365mSetA15_A8;//设置高地址,即设置A15-A8的输出
pCH365mWriteIoByte CH365mWriteIoByte;// 向I/O端口写入一个字节
pCH365mCloseDevice CH365mCloseDevice;// 关闭CH365设备
public:
static Pci365CardMgr* GetInstance()
{
if (m_instance == nullptr) {
m_instance = new Pci365CardMgr();
}
return m_instance;
}
};