|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
#include "PciCh365Mgr.h"
|
|
|
|
|
#include "LogMgr.h"
|
|
|
|
|
#include "LaipuVbDllMgr.h"
|
|
|
|
|
#include "PciPortMgr.h"
|
|
|
|
|
#include "ExceptionMsg.h"
|
|
|
|
|
#include "Mirror.h"
|
|
|
|
|
|
|
|
|
|
#define LASER_PORT 7//<2F><><EFBFBD><EFBFBD>ض˿<D8B6>
|
|
|
|
|
|
|
|
|
|
CPciCh365Mgr *gPciCh365Mgr = new CPciCh365Mgr;
|
|
|
|
|
CPciCh365Mgr::CPciCh365Mgr(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
CPciCh365Mgr::~CPciCh365Mgr(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
bool CPciCh365Mgr::ReadDll()
|
|
|
|
|
{
|
|
|
|
|
m_PciCh365Handle = LoadLibrary( "CH365DLL.DLL" );
|
|
|
|
|
if( !m_PciCh365Handle )
|
|
|
|
|
{
|
|
|
|
|
gLogMgr->WriteDebugLog("pci <20><><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD>ӿ<EFBFBD>CH365DLL.DLL <20><>ȡʧ<C8A1><CAA7>",_LOG_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)
|
|
|
|
|
{
|
|
|
|
|
gLogMgr->WriteDebugLog("CH365DLL.DLL <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1><CAA7>",_LOG_ERROR);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#if 1
|
|
|
|
|
//<2F><>ʼ<EFBFBD><CABC>pci <20><>
|
|
|
|
|
void CPciCh365Mgr::Ini()
|
|
|
|
|
{
|
|
|
|
|
m_bIni = false;//pci <20><><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
|
|
//<2F><>ȡӲ<C8A1><D3B2>֧<EFBFBD>ֵĸ߾<C4B8><DFBE>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>
|
|
|
|
|
IniClockFre();
|
|
|
|
|
|
|
|
|
|
if(ReadDll())//<2F><>ȡdll
|
|
|
|
|
{
|
|
|
|
|
//<2F>Լ<EFBFBD><D4BC><EFBFBD>ʼ<EFBFBD><CABC>pci <20><>
|
|
|
|
|
if(IniPciCard())
|
|
|
|
|
{
|
|
|
|
|
#if 0
|
|
|
|
|
gLaipuVbDllMgr->VbIniCard(m_OutPortStateLow,m_OutPortStateHigh);
|
|
|
|
|
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>˿ڵ<CBBF>״̬
|
|
|
|
|
IniOutPortState();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
//<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD>˿<EFBFBD>
|
|
|
|
|
CloseLaserPort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F>Լ<EFBFBD><D4BC><EFBFBD>ʼ<EFBFBD><CABC>pci <20><>
|
|
|
|
|
bool CPciCh365Mgr::IniPciCard()
|
|
|
|
|
{
|
|
|
|
|
//<2F><>ʼ<EFBFBD><CABC>pci <20><>
|
|
|
|
|
m_DeviceHandle = CH365mOpenDevice(0,true,true);
|
|
|
|
|
if((int)m_DeviceHandle==-1)
|
|
|
|
|
{
|
|
|
|
|
gLogMgr->WriteDebugLog("δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ch365 pci <20><>",_LOG_ERROR);
|
|
|
|
|
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>ַ
|
|
|
|
|
|
|
|
|
|
m_bIni = true;
|
|
|
|
|
gLogMgr->WriteDebugLog("ch 365 pci <20><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>˿ڵ<CBBF>״̬
|
|
|
|
|
void CPciCh365Mgr::IniOutPortState()
|
|
|
|
|
{
|
|
|
|
|
gLogMgr->WriteDebugLog("IniOutPortState",_LOG_FUNC);
|
|
|
|
|
|
|
|
|
|
int OutPortDefaultStateL = gPciPortMgr->GetOutPortDefaultStateL();
|
|
|
|
|
int OutPortDefaultStateH = gPciPortMgr->GetOutPortDefaultStateH();
|
|
|
|
|
for(int i=0;i<8;i++)//<2F>Ͱ<EFBFBD>λ
|
|
|
|
|
{
|
|
|
|
|
if(IsBitOn((BYTE)OutPortDefaultStateL,i))
|
|
|
|
|
{
|
|
|
|
|
SPciPort PciPort;
|
|
|
|
|
PciPort.num = i;
|
|
|
|
|
WritePortState(PciPort,true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(int i=0;i<8;i++)//<2F>߰<EFBFBD>λ
|
|
|
|
|
{
|
|
|
|
|
if(IsBitOn((BYTE)OutPortDefaultStateH,i))
|
|
|
|
|
{
|
|
|
|
|
SPciPort PciPort;
|
|
|
|
|
PciPort.num = i+8;
|
|
|
|
|
WritePortState(PciPort,true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>pci <20>Ƿ<EFBFBD><C7B7><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ˣ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>׳<EFBFBD><D7B3>쳣<EFBFBD><ECB3A3>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱPCI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
|
|
|
|
void CPciCh365Mgr::CheckIniState()
|
|
|
|
|
{
|
|
|
|
|
if(!m_bIni)
|
|
|
|
|
{
|
|
|
|
|
CString str(_T("PCI <20><>δ<EFBFBD><CEB4>ʼ<EFBFBD><CABC>"));
|
|
|
|
|
CExceptionMsg Msg;
|
|
|
|
|
Msg.SetMsg(str);
|
|
|
|
|
throw Msg;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#if 1//<2F><>ʱ
|
|
|
|
|
//<>뼶<EFBFBD><EBBCB6>ʱ<EFBFBD><CAB1>usΪ<CEAA><CEA2>
|
|
|
|
|
void CPciCh365Mgr::DelayTime(unsigned int us)
|
|
|
|
|
{
|
|
|
|
|
if(m_bHasSmartClock && us>0)
|
|
|
|
|
{
|
|
|
|
|
LARGE_INTEGER start, end;
|
|
|
|
|
LONGLONG count = (us*m_ClockFre.QuadPart)/(1000*1000);
|
|
|
|
|
QueryPerformanceCounter(&start);
|
|
|
|
|
count = count + start.QuadPart ;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
QueryPerformanceCounter(&end);
|
|
|
|
|
}while(end.QuadPart<count);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ȡӲ<C8A1><D3B2>֧<EFBFBD>ֵĸ߾<C4B8><DFBE>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>
|
|
|
|
|
void CPciCh365Mgr::IniClockFre()
|
|
|
|
|
{
|
|
|
|
|
m_bHasSmartClock = QueryPerformanceFrequency(&m_ClockFre);
|
|
|
|
|
if(!m_bHasSmartClock)
|
|
|
|
|
{
|
|
|
|
|
gLogMgr->WriteDebugLog("<EFBFBD><EFBFBD>ȡ<EFBFBD>߾<EFBFBD><EFBFBD>ȼ<EFBFBD>ʱ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>",_LOG_ERROR);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gLogMgr->WriteDebugLog("<EFBFBD><EFBFBD>ȡ<EFBFBD>߾<EFBFBD><EFBFBD>ȼ<EFBFBD>ʱ<EFBFBD><EFBFBD>Ƶ<EFBFBD>ʳɹ<EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
//<2F><>ָ<EFBFBD><D6B8><EFBFBD>˿ڶ<CBBF><DAB6><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>
|
|
|
|
|
BOOL CPciCh365Mgr::ReadIoPortByte(int PortAddr,long &PortVal)
|
|
|
|
|
{
|
|
|
|
|
BOOL result = FALSE;
|
|
|
|
|
UCHAR ChByte;
|
|
|
|
|
USHORT mAddr=(USHORT)PortAddr;
|
|
|
|
|
UINT mIndex= 0 ;
|
|
|
|
|
if(PortAddr<255)
|
|
|
|
|
{
|
|
|
|
|
if(CH365mReadIoByte(mIndex,(PVOID)mAddr,&ChByte))
|
|
|
|
|
{
|
|
|
|
|
PortVal = (long)ChByte;
|
|
|
|
|
result = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ChByte = PortAddr/256;
|
|
|
|
|
CH365mSetA15_A8(0,ChByte);//<2F>趨<EFBFBD><E8B6A8>8λ<38><CEBB>ַ
|
|
|
|
|
|
|
|
|
|
PortAddr = PortAddr%256;
|
|
|
|
|
if(CH365mReadIoByte(mIndex,(PVOID)&PortAddr,&ChByte))
|
|
|
|
|
{
|
|
|
|
|
PortVal = (long)ChByte;
|
|
|
|
|
result = TRUE;
|
|
|
|
|
}
|
|
|
|
|
ChByte = 0xFF;
|
|
|
|
|
CH365mSetA15_A8(0,ChByte);//<2F>ָ<EFBFBD><D6B8><EFBFBD>8λ<38><CEBB>ַ
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ָ<EFBFBD><D6B8><EFBFBD>˿<EFBFBD>д<EFBFBD><D0B4>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>
|
|
|
|
|
void CPciCh365Mgr::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>ַ
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD>ö˿<C3B6>״̬
|
|
|
|
|
void CPciCh365Mgr::WritePortState(SPciPort PciPort,bool bOpen)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>pci <20><>ʼ<EFBFBD><CABC>״̬
|
|
|
|
|
CheckIniState();
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//PortNum <20>˿ں<CBBF>0~15
|
|
|
|
|
//Delay <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱus
|
|
|
|
|
void CPciCh365Mgr::SendOnePulse(SPciPort PciPort,unsigned int Delay)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>pci <20><>ʼ<EFBFBD><CABC>״̬
|
|
|
|
|
CheckIniState();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>߰<EFBFBD>λ<EFBFBD><CEBB><EFBFBD>ǵͰ<C7B5>λ
|
|
|
|
|
bool bLow = LowOrHight(PciPort.num);
|
|
|
|
|
//<2F><><EFBFBD>ö˿ڵ<CBBF>ַ
|
|
|
|
|
int PortAddr = GetPortAddr(bLow,true);
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>״̬
|
|
|
|
|
long &OutPortState = GetOutPortState(bLow);
|
|
|
|
|
|
|
|
|
|
//<2F>ȸߺ<C8B8><DFBA><EFBFBD>---------------------------------
|
|
|
|
|
OutPortState = SetBitOn(OutPortState,PciPort.num);
|
|
|
|
|
WriteIoPortByte(PortAddr,OutPortState);
|
|
|
|
|
DelayTime(Delay);
|
|
|
|
|
OutPortState = SetBitOff(OutPortState,PciPort.num);
|
|
|
|
|
WriteIoPortByte(PortAddr,OutPortState);
|
|
|
|
|
DelayTime(Delay);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
//<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD>˿<EFBFBD>
|
|
|
|
|
void CPciCh365Mgr::CloseLaserPort()
|
|
|
|
|
{
|
|
|
|
|
SPciPort PciPort;
|
|
|
|
|
PciPort.num = LASER_PORT;
|
|
|
|
|
gLogMgr->WriteDebugLog("<EFBFBD>رն˿<EFBFBD>","PortNum", LASER_PORT);
|
|
|
|
|
bool b = false;
|
|
|
|
|
if(gMirror->IsLaserSwitch())
|
|
|
|
|
b = !b;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
gPciCh365Mgr->WritePortState(PciPort,b);
|
|
|
|
|
}
|
|
|
|
|
catch(CExceptionMsg &Msg)
|
|
|
|
|
{
|
|
|
|
|
CString str("Func : CloseLaserPort---->");
|
|
|
|
|
str += Msg.GetMsgStr();
|
|
|
|
|
gLogMgr->WriteDebugLog(str,_LOG_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|