|
|
|
|
|
#include "Pci365CardMgr.h"
|
|
|
|
|
|
|
|
|
|
|
|
Pci365CardMgr* Pci365CardMgr::m_instance = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
void Pci365CardMgr::InitPci365Card()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_bIniPci365Card)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
m_OutPortStateLow = 0;//<2F><>¼<EFBFBD><C2BC>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>˿ڵ<CBBF>״̬--<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
|
m_OutPortStateHigh = 0;//<2F><>¼<EFBFBD><C2BC>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>˿ڵ<CBBF>״̬--<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
if (ReadDll())//<2F><>ȡdll
|
|
|
|
|
|
{
|
|
|
|
|
|
//<2F>Լ<EFBFBD><D4BC><EFBFBD>ʼ<EFBFBD><CABC>pci <20><>
|
|
|
|
|
|
IniPciCard();
|
|
|
|
|
|
|
|
|
|
|
|
//<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD>˿<EFBFBD>
|
|
|
|
|
|
CtrlLaserGate(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Pci365CardMgr::ReadDll()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_PciCh365Handle = LoadLibrary(L"CH365DLL.DLL");
|
|
|
|
|
|
if (!m_PciCh365Handle)
|
|
|
|
|
|
{
|
|
|
|
|
|
LaserLogger::GetInstance()->WriteLog(0, "LoadLibrary CH365DLL.DLL is error");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1>Ҫ<EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
|
bool result = true;
|
|
|
|
|
|
result &= ((CH365mOpenDevice = (pCH365mOpenDevice)GetProcAddress(m_PciCh365Handle, "CH365mOpenDevice")) != NULL);
|
|
|
|
|
|
result &= ((CH365mReadIoByte = (pCH365mReadIoByte)GetProcAddress(m_PciCh365Handle, "CH365mReadIoByte")) != NULL);
|
|
|
|
|
|
result &= ((CH365mSetA15_A8 = (pCH365mSetA15_A8)GetProcAddress(m_PciCh365Handle, "CH365mSetA15_A8")) != NULL);
|
|
|
|
|
|
result &= ((CH365mWriteIoByte = (pCH365mWriteIoByte)GetProcAddress(m_PciCh365Handle, "CH365mWriteIoByte")) != NULL);
|
|
|
|
|
|
result &= ((CH365mCloseDevice = (pCH365mCloseDevice)GetProcAddress(m_PciCh365Handle, "CH365mCloseDevice")) != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
|
|
{
|
|
|
|
|
|
LaserLogger::GetInstance()->WriteLog(0, "CH365mOpenDevice is error");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Pci365CardMgr::IniPciCard()
|
|
|
|
|
|
{
|
|
|
|
|
|
//<2F><>ʼ<EFBFBD><CABC>pci <20><>
|
|
|
|
|
|
m_DeviceHandle = CH365mOpenDevice(0, true, true);
|
|
|
|
|
|
if ((int)m_DeviceHandle == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
LaserLogger::GetInstance()->WriteLog(0, "ch365 pci is not discovered");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><DEB7><EFBFBD>ȡ)
|
|
|
|
|
|
UCHAR ChByte = 0xFF;
|
|
|
|
|
|
CH365mSetA15_A8(0, ChByte);//<2F>ָ<EFBFBD><D6B8><EFBFBD>8λ<38><CEBB>ַ
|
|
|
|
|
|
|
|
|
|
|
|
LaserLogger::GetInstance()->WriteLog(0, "ch365 pci IniPciCard is OK");
|
|
|
|
|
|
|
|
|
|
|
|
m_bIniPci365Card = true;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Pci365CardMgr::CtrlLaserGate(bool bon)
|
|
|
|
|
|
{
|
|
|
|
|
|
SPciPort PciPort;
|
|
|
|
|
|
PciPort.num = LASER_PORT;
|
|
|
|
|
|
/*if (gMirror->IsLaserSwitch())
|
|
|
|
|
|
bon = !bon;
|
|
|
|
|
|
*/
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
WritePortState(PciPort, bon);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (...)
|
|
|
|
|
|
{
|
|
|
|
|
|
LaserLogger::GetInstance()->WriteLog(0, "function:WritePortState is error");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Pci365CardMgr::WritePortState(SPciPort PciPort, bool bOpen)
|
|
|
|
|
|
{
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>pci <20><>ʼ<EFBFBD><CABC>״̬
|
|
|
|
|
|
if (m_bIniPci365Card == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (PciPort.num == -1)
|
|
|
|
|
|
return;
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>߰<EFBFBD>λ<EFBFBD><CEBB><EFBFBD>ǵͰ<C7B5>λ
|
|
|
|
|
|
bool bLow = LowOrHight(PciPort.num);
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>״̬
|
|
|
|
|
|
long &OutPortState = GetOutPortState(bLow);
|
|
|
|
|
|
//<2F><><EFBFBD>ö˿ڵ<CBBF>ַ
|
|
|
|
|
|
int PortAddr = GetPortAddr(bLow, true);
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (PciPort.bReverse)
|
|
|
|
|
|
{
|
|
|
|
|
|
bOpen = !bOpen;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (bOpen)
|
|
|
|
|
|
{
|
|
|
|
|
|
OutPortState = SetBitOn(OutPortState, PciPort.num);
|
|
|
|
|
|
WriteIoPortByte(PortAddr, OutPortState);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
OutPortState = SetBitOff(OutPortState, PciPort.num);
|
|
|
|
|
|
WriteIoPortByte(PortAddr, OutPortState);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Pci365CardMgr::LowOrHight(int &PortNum)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool bLow = true;//<2F>Ͱ<EFBFBD>λ
|
|
|
|
|
|
if (PortNum >= PORT_CNT)//<2F>߰<EFBFBD>λ
|
|
|
|
|
|
{
|
|
|
|
|
|
bLow = false;
|
|
|
|
|
|
PortNum -= PORT_CNT;//ͳһ8 λ<><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
}
|
|
|
|
|
|
return bLow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long& Pci365CardMgr::GetOutPortState(bool bLow)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (bLow)
|
|
|
|
|
|
return m_OutPortStateLow;
|
|
|
|
|
|
else
|
|
|
|
|
|
return m_OutPortStateHigh;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Pci365CardMgr::GetPortAddr(bool bLow, bool bWirte)
|
|
|
|
|
|
{
|
|
|
|
|
|
int addr;
|
|
|
|
|
|
if (bLow)//<2F>Ͱ<EFBFBD>λ
|
|
|
|
|
|
{
|
|
|
|
|
|
if (bWirte)
|
|
|
|
|
|
{
|
|
|
|
|
|
addr = OUT_PORT_ADDR_L;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
addr = IN_PORT_ADDR_L;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else//<2F>߰<EFBFBD>λ
|
|
|
|
|
|
{
|
|
|
|
|
|
if (bWirte)
|
|
|
|
|
|
{
|
|
|
|
|
|
addr = OUT_PORT_ADDR_H;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
addr = IN_PORT_ADDR_H;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return addr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long Pci365CardMgr::SetBitOn(long PortVal, int PortIdx)
|
|
|
|
|
|
{
|
|
|
|
|
|
PortVal = PortVal | (1 << PortIdx);
|
|
|
|
|
|
return PortVal;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BYTE Pci365CardMgr::SetBitOff(BYTE PortVal, int PortIdx)
|
|
|
|
|
|
{
|
|
|
|
|
|
PortVal = (PortVal)&(~(1 << PortIdx));
|
|
|
|
|
|
return PortVal;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Pci365CardMgr::WriteIoPortByte(int PortAddr, long PortVal)
|
|
|
|
|
|
{
|
|
|
|
|
|
UCHAR ChByte;
|
|
|
|
|
|
if (PortAddr < 255)
|
|
|
|
|
|
{
|
|
|
|
|
|
USHORT mAddr = (USHORT)PortAddr;
|
|
|
|
|
|
ChByte = (UCHAR)PortVal;
|
|
|
|
|
|
CH365mWriteIoByte(0, (PVOID)mAddr, ChByte);//<2F>˿<EFBFBD>д<EFBFBD><D0B4>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC>Ҫ4us
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ChByte = PortAddr >> 8;
|
|
|
|
|
|
CH365mSetA15_A8(0, ChByte);//<2F>趨<EFBFBD><E8B6A8>8λ<38><CEBB>ַ
|
|
|
|
|
|
|
|
|
|
|
|
USHORT mAddr = (USHORT)(PortAddr % 256);
|
|
|
|
|
|
ChByte = (UCHAR)PortVal;
|
|
|
|
|
|
CH365mWriteIoByte(0, (PVOID)mAddr, ChByte);
|
|
|
|
|
|
ChByte = 0xFF;
|
|
|
|
|
|
CH365mSetA15_A8(0, ChByte);//<2F>ָ<EFBFBD><D6B8><EFBFBD>8λ<38><CEBB>ַ
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Pci365CardMgr::Pci365CardMgr()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pci365CardMgr::~Pci365CardMgr()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|