#include "StdAfx.h"
|
#include "CHLightControls/LightControl_Byon_ERI2.h"
|
|
|
CLightControl_Byon_ERI2::CLightControl_Byon_ERI2(int nIndex) : CLightControl(nIndex)
|
{
|
m_hLightControl = NULL;
|
m_nCurLightLevel = 0;
|
}
|
|
|
CLightControl_Byon_ERI2::~CLightControl_Byon_ERI2(void)
|
{
|
Disconnect();
|
}
|
|
BOOL CLightControl_Byon_ERI2::Connect( const CLightControlInfo& controlInfo )
|
{
|
m_ControlInfo =controlInfo;
|
int nPort = _ttoi(m_ControlInfo.GetConnectionPort());
|
|
DCB dcb;
|
COMMTIMEOUTS tout;
|
|
int ret;
|
CHAR szPort[15];
|
|
sprintf( szPort, _T("COM%d"), nPort );
|
|
m_hLightControl = CreateFile( szPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
|
|
if (m_hLightControl == INVALID_HANDLE_VALUE)
|
{
|
CloseHandle(m_hLightControl);
|
m_hLightControl = NULL;
|
return FALSE;
|
}
|
|
dcb.DCBlength = sizeof(DCB);
|
if (GetCommState(m_hLightControl,(LPDCB) &dcb))
|
{
|
dcb.DCBlength = sizeof(DCB);
|
dcb.BaudRate = CBR_38400;
|
dcb.ByteSize = 8;
|
dcb.fParity = FALSE;
|
dcb.Parity = NOPARITY;
|
//dcb.StopBits = 1;
|
dcb.fOutxCtsFlow = 0;
|
dcb.fOutxDsrFlow = 0;
|
dcb.fOutX = 0;
|
dcb.fInX = 0;
|
|
if (!SetCommState(m_hLightControl,(LPDCB) &dcb))
|
{
|
CloseHandle(m_hLightControl);
|
m_hLightControl = NULL;
|
return FALSE;
|
}
|
}
|
else
|
{
|
CloseHandle(m_hLightControl);
|
m_hLightControl = NULL;
|
return FALSE;
|
}
|
|
tout.ReadIntervalTimeout = 100;
|
tout.ReadTotalTimeoutMultiplier = 1;
|
tout.ReadTotalTimeoutConstant = 100;
|
if((ret = SetCommTimeouts(m_hLightControl, &tout)) == NULL)
|
{
|
CloseHandle(m_hLightControl);
|
m_hLightControl = NULL;
|
return FALSE;
|
}
|
m_nCurLightLevel = m_ControlInfo.GetDefaultValue();
|
|
return TRUE;
|
}
|
|
void CLightControl_Byon_ERI2::Disconnect()
|
{
|
if (m_hLightControl)
|
CloseHandle(m_hLightControl);
|
m_hLightControl = NULL;
|
}
|
|
LONG CLightControl_Byon_ERI2::ConnectEx( const CLightControlInfo& controlInfo )
|
{
|
return TRUE;
|
}
|
|
void CLightControl_Byon_ERI2::DisconnectEx()
|
{
|
|
}
|
|
BOOL CLightControl_Byon_ERI2::GetLightLevel( int &nValue, int nChannel /*= 0*/ ) const
|
{
|
nValue = m_nCurLightLevel;
|
return TRUE;
|
}
|
|
BOOL CLightControl_Byon_ERI2::GetLightLevel( double &dValue, int nChannel /*= 0*/ ) const
|
{
|
int nTemp = 0;
|
GetLightLevel(nTemp);
|
dValue = nTemp;
|
return TRUE;
|
}
|
|
BOOL CLightControl_Byon_ERI2::GetLightStatus( int &nValue, int nChannel /*= 0*/ ) const
|
{
|
if(!m_hLightControl){
|
nValue = TRUE;
|
}
|
|
else
|
{
|
nValue = FALSE;
|
}
|
return TRUE;
|
}
|
|
BOOL CLightControl_Byon_ERI2::SetLightLevel( int nValue, int nChannel /*= 0*/ )
|
{
|
OnOffLightControler(nChannel,1);
|
|
if (!m_hLightControl)
|
return FALSE;
|
|
CString tmp;
|
char Outbuf[100];
|
DWORD NumberOfBytesWritten;
|
|
m_nCurLightLevel = nValue;
|
|
tmp.Format(_T("setbrightness %d %3d\r"),nChannel,nValue);
|
|
int nLength = tmp.GetLength();
|
|
sprintf_s(Outbuf,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",tmp.GetAt(0),tmp.GetAt(1),tmp.GetAt(2),tmp.GetAt(3),tmp.GetAt(4),tmp.GetAt(5),tmp.GetAt(6),tmp.GetAt(7),tmp.GetAt(8),tmp.GetAt(9),tmp.GetAt(10),tmp.GetAt(11),tmp.GetAt(12),tmp.GetAt(13),tmp.GetAt(14),tmp.GetAt(15),tmp.GetAt(16),tmp.GetAt(17),tmp.GetAt(18),tmp.GetAt(19));
|
|
BOOL bRet = WriteFile( m_hLightControl,(LPCVOID) Outbuf,nLength,(LPDWORD) &NumberOfBytesWritten,NULL);
|
|
return bRet;
|
}
|
|
BOOL CLightControl_Byon_ERI2::SetLightLevel( double dValue, int nChannel /*= 0*/ )
|
{
|
int nTemp = (int)dValue;
|
|
return SetLightLevel(nTemp);
|
}
|
|
BOOL CLightControl_Byon_ERI2::SetLightStatus( int nValue, int nChannel /*= 0*/ )
|
{
|
return TRUE;
|
}
|
|
BOOL CLightControl_Byon_ERI2::SetLightOn()
|
{
|
return TRUE;
|
}
|
|
BOOL CLightControl_Byon_ERI2::SetLightOff()
|
{
|
return TRUE;
|
}
|
|
BOOL CLightControl_Byon_ERI2::SetLightOn(int Channel)
|
{
|
return TRUE;
|
}
|
|
BOOL CLightControl_Byon_ERI2::SetLightOff(int Channel)
|
{
|
return TRUE;
|
}
|
|
BOOL CLightControl_Byon_ERI2::SetLightAllOn()
|
{
|
if (!m_bConnected) return FALSE;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_Byon_ERI2::SetLightAllOff()
|
{
|
if (!m_bConnected) return FALSE;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_Byon_ERI2::OnOffLightControler( int nChannel, int nValue )
|
{
|
if (!m_hLightControl)
|
return FALSE;
|
|
CString tmp;
|
char Outbuf[100];
|
DWORD NumberOfBytesWritten;
|
|
tmp.Format(_T("seton %d %d\r"),nChannel,nValue);
|
|
int nLength = tmp.GetLength();
|
|
sprintf_s(Outbuf,"%c%c%c%c%c%c%c%c%c%c",tmp.GetAt(0),tmp.GetAt(1),tmp.GetAt(2),tmp.GetAt(3),tmp.GetAt(4),tmp.GetAt(5),tmp.GetAt(6),tmp.GetAt(7),tmp.GetAt(8),tmp.GetAt(9));
|
|
BOOL bRet = WriteFile( m_hLightControl,(LPCVOID) Outbuf,nLength,(LPDWORD) &NumberOfBytesWritten,NULL);
|
|
return bRet;
|
}
|
|
int CLightControl_Byon_ERI2::GetStatus( int& nStatusCode, CString& strStatusMessage )
|
{
|
if (GetConnected()==FALSE)
|
{
|
nStatusCode = LightStatus_NotConnected;
|
strStatusMessage = _T("Not_Connected");
|
return 0;
|
}
|
|
nStatusCode = LightStatus_Connected;
|
strStatusMessage = _T("Connected");
|
|
return 1;
|
}
|