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.
146 lines
4.3 KiB
C++
146 lines
4.3 KiB
C++
|
|
#pragma once
|
|
#include "Module.h"
|
|
#include "CH365DLL.H"
|
|
#include "GlobalFunction.h"
|
|
#include "PciPort.h"
|
|
#include "BitOperation.h"
|
|
#include "EnumPropertieType.h"
|
|
|
|
|
|
#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
|
|
|
|
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);
|
|
|
|
//ch365 pci卡管理类:
|
|
class CPciCh365Mgr:public CModule
|
|
{
|
|
public:
|
|
CPciCh365Mgr(void);
|
|
~CPciCh365Mgr(void);
|
|
virtual void Ini();
|
|
virtual MODULE GetModuleType(){return _MODULE_PCI365;};
|
|
|
|
bool IsInitialize(){return m_bIni;};
|
|
bool ReadPortState(SPciPort PciPort,bool bCheckIniState = true);
|
|
void WritePortState(SPciPort PciPort,bool bOpen);
|
|
void SendOnePulse(SPciPort PciPort,unsigned int Delay);
|
|
long &GetOutPortState(bool bLow);
|
|
void DelayTime(unsigned int us);
|
|
LARGE_INTEGER GetClockFre(){return m_ClockFre;};
|
|
void CloseLaserPort();
|
|
private:
|
|
bool ReadDll();
|
|
bool IniPciCard();
|
|
void IniOutPortState();
|
|
void CheckIniState();
|
|
int GetPortAddr(bool bLow,bool bWirte);
|
|
|
|
void IniClockFre();
|
|
|
|
BOOL ReadIoPortByte(int PortAddr,long &PortVal);
|
|
void WriteIoPortByte(int PortAddr,long PortVal);
|
|
bool LowOrHight(int &PortNum);
|
|
private:
|
|
bool m_bIni;//pci 卡是否初始化成功
|
|
//dll 函数指针
|
|
pCH365mOpenDevice CH365mOpenDevice;// 打开CH365设备,返回句柄,出错则无效
|
|
pCH365mReadIoByte CH365mReadIoByte;//从I/O端口读取一个字节
|
|
pCH365mSetA15_A8 CH365mSetA15_A8;//设置高地址,即设置A15-A8的输出
|
|
pCH365mWriteIoByte CH365mWriteIoByte;// 向I/O端口写入一个字节
|
|
pCH365mCloseDevice CH365mCloseDevice;// 关闭CH365设备
|
|
|
|
HINSTANCE m_PciCh365Handle;//保存Ch365动态链接库的句柄
|
|
HANDLE m_DeviceHandle;//pci设备的句柄
|
|
|
|
long m_OutPortStateLow;//记录当前输出端口的状态(低八位)--用于向端口写数据
|
|
long m_OutPortStateHigh;//记录当前输出端口的状态(高八位)--用于向端口写数据
|
|
|
|
bool m_bHasSmartClock;//是否有内部时钟
|
|
LARGE_INTEGER m_ClockFre;//内部计时器的时钟频率
|
|
};
|
|
|
|
extern CPciCh365Mgr *gPciCh365Mgr;
|
|
|
|
|
|
//处理高八位还是低八位
|
|
inline bool CPciCh365Mgr::LowOrHight(int &PortNum)
|
|
{
|
|
bool bLow = true;//低八位
|
|
if(PortNum>=PORT_CNT)//高八位
|
|
{
|
|
bLow = false;
|
|
PortNum -= PORT_CNT;//统一8 位来处理
|
|
}
|
|
return bLow;
|
|
}
|
|
//获得输出端口状态
|
|
//bLow 是否为低8 位
|
|
inline long &CPciCh365Mgr::GetOutPortState(bool bLow)
|
|
{
|
|
if(bLow)
|
|
return m_OutPortStateLow;
|
|
else
|
|
return m_OutPortStateHigh;
|
|
}
|
|
|
|
//获取端口对应的地址
|
|
inline int CPciCh365Mgr::GetPortAddr(bool bLow,bool bWirte)
|
|
{
|
|
int addr;
|
|
if(bLow)//低八位
|
|
{
|
|
if(bWirte)
|
|
{
|
|
addr = OUT_PORT_ADDR_L;
|
|
}
|
|
else
|
|
{
|
|
addr = IN_PORT_ADDR_L;
|
|
}
|
|
}
|
|
else//高八位
|
|
{
|
|
if(bWirte)
|
|
{
|
|
addr = OUT_PORT_ADDR_H;
|
|
}
|
|
else
|
|
{
|
|
addr = IN_PORT_ADDR_H;
|
|
}
|
|
}
|
|
return addr;
|
|
}
|
|
//读取PortNum 端口状态(1 或者0)
|
|
inline bool CPciCh365Mgr::ReadPortState(SPciPort PciPort,bool bCheckIniState)
|
|
{
|
|
if(bCheckIniState)
|
|
CheckIniState();
|
|
|
|
//处理高八位还是低八位
|
|
bool bLow = LowOrHight(PciPort.num);
|
|
//获得端口地址
|
|
int PortAddr = GetPortAddr(bLow,false);
|
|
//读取输入口的值
|
|
long InPortState;
|
|
ReadIoPortByte(PortAddr,InPortState);
|
|
|
|
bool ret = IsBitOn(InPortState,PciPort.num);
|
|
//反向操作
|
|
if(PciPort.bReverse)
|
|
{
|
|
ret = !ret;
|
|
}
|
|
return ret;
|
|
}
|
|
|