You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
4.5 KiB
160 lines
4.5 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgDeviceGPIOPCI1762.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgDeviceGPIOPCI1762.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LgDeviceGPIOPCI1762.h"
|
|
|
|
CLgDeviceGPIOPCI1762::CLgDeviceGPIOPCI1762()
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgDeviceGPIOPCI1762::CLgDeviceGPIOPCI1762") );
|
|
}
|
|
|
|
CLgDeviceGPIOPCI1762::~CLgDeviceGPIOPCI1762()
|
|
{
|
|
Destroy();
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgDeviceGPIOPCI1762::~CLgDeviceGPIOPCI1762") );
|
|
}
|
|
|
|
BOOL CLgDeviceGPIOPCI1762::Create( INT nDevice )
|
|
{
|
|
if( !CLgDeviceGPIO::Create( 16, 16 ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgDeviceGPIO::Create failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
if( !CLgAdvantechPCI1762::Create( nDevice ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgAdvantechPCI1762::Create failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
DWORD dwState;
|
|
if( !CLgAdvantechPCI1762::GetDirectInputAll( CLgAdvantechPCI1762::DIM_ALL, &dwState ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgAdvantechPCI1762::GetDirectInputAll failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
if( !CLgDeviceGPIO::InitInputState( 0, dwState ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgDeviceGPIO::InitInputState failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
if( !CLgAdvantechPCI1762::SetDirectOutputAll( CLgAdvantechPCI1762::DOM_ALL, 0 ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgAdvantechPCI1762::SetDirectOutputAll failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
if( !CLgAdvantechPCI1762::GetDirectOutputAll( CLgAdvantechPCI1762::DOM_ALL, &dwState ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgAdvantechPCI1762::GetDirectOutputAll failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
if( !CLgDeviceGPIO::SetOutputState( 0, CLgAdvantechPCI1762::DOM_ALL, dwState ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgDeviceGPIO::SetOutputState failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CLgDeviceGPIOPCI1762::Destroy()
|
|
{
|
|
CLgAdvantechPCI1762::Destroy();
|
|
}
|
|
|
|
BOOL CLgDeviceGPIOPCI1762::ReadWriteProc( DWORD dwTimeout )
|
|
{
|
|
INT nCmd = GetCmd();
|
|
switch( nCmd )
|
|
{
|
|
case CMD_GET_INPUT:
|
|
{
|
|
// avalible for new commands
|
|
ReleaseCmd();
|
|
// get input
|
|
DWORD dwState;
|
|
CLgDeviceGPIO::GetInputState( 0, &dwState );
|
|
// call handler
|
|
OnEvtGetInput( m_Input, ( dwState & (1 << m_Input) ) ? TRUE : FALSE );
|
|
}
|
|
break;
|
|
|
|
case CMD_GET_INPUT_ALL:
|
|
{
|
|
// avalible for new commands
|
|
ReleaseCmd();
|
|
// call handler
|
|
OnEvtGetInputAll( GetInputPins() );
|
|
}
|
|
break;
|
|
|
|
case CMD_SET_OUTPUT:
|
|
{
|
|
// avalible for new commands
|
|
ReleaseCmd();
|
|
// set output
|
|
CLgAdvantechPCI1762::SetDirectOutput( m_Output.nIndex, m_Output.bOn );
|
|
// store output state
|
|
CLgDeviceGPIO::SetOutputState( 0, 1 << m_Output.nIndex, m_Output.bOn ? 1 << m_Output.nIndex : 0 );
|
|
// call handler
|
|
OnEvtSetOutput( m_Output.nIndex, m_Output.bOn );
|
|
}
|
|
break;
|
|
|
|
case CMD_GET_OUTPUT_ALL:
|
|
{
|
|
// avalible for new commands
|
|
ReleaseCmd();
|
|
// call handler
|
|
OnEvtGetOutputAll( GetOutputPins() );
|
|
}
|
|
break;
|
|
|
|
case CMD_NONE:
|
|
break;
|
|
|
|
default:
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgDeviceGPIOPCI1762::ReadWriteProc"), _T("received unsupported command %d"), nCmd );
|
|
ReleaseCmd();
|
|
OnEvtCommandError( nCmd, _T("UNSUPPORTED") );
|
|
break;
|
|
}
|
|
|
|
if( CLgAdvantechPCI1762::WaitForEvent( dwTimeout ) )
|
|
{
|
|
DWORD dwState;
|
|
if( !CLgAdvantechPCI1762::GetDirectInputAll( CLgAdvantechPCI1762::DIM_ALL, &dwState ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::ReadWriteProc"), _T("CLgAdvantechPCI1762::GetDirectInputAll failed") );
|
|
}
|
|
else
|
|
if( !CLgDeviceGPIO::UpdateInputState( 0, dwState ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgDeviceGPIO::InitInputState failed") );
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CLgDeviceGPIOPCI1762::OnInputChange( INT nBit, BOOL bOn )
|
|
{
|
|
OnEvtInputChange( nBit, bOn );
|
|
}
|