#include "StdAfx.h"
|
#include "CHLightControls/LightControl_LFusion_PDSeries.h"
|
|
|
CLightControl_LFusion_PDSeries::CLightControl_LFusion_PDSeries(int nIndex) : CLightControl(nIndex)
|
{
|
m_bConnected = FALSE;
|
m_nPortIndex = 1;
|
m_nBaudRate = 9600;
|
m_nCurrentValue = 100;
|
m_nCurrentStatus = 0;
|
}
|
|
CLightControl_LFusion_PDSeries::~CLightControl_LFusion_PDSeries(void)
|
{
|
Disconnect();
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::Connect(const CLightControlInfo& controlInfo)
|
{
|
m_ControlInfo = controlInfo;
|
|
int nPort = _ttoi(controlInfo.GetConnectionPort());
|
if(nPort < 1) return FALSE;
|
|
if(IsOpen()) Close();
|
CString strProt = _T("");
|
|
if(nPort > 9)
|
{
|
strProt.Format(_T("\\\\.\\\\COM%d"), nPort);
|
}
|
else
|
{
|
strProt.Format(_T("COM%d"), nPort);
|
}
|
|
if (Open(strProt,NULL) != ERROR_SUCCESS)
|
{
|
m_bConnected = FALSE;
|
return false;
|
}
|
Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);
|
SetupHandshaking(CSerial::EHandshakeOff);
|
|
m_nPortIndex = nPort;
|
m_nBaudRate = controlInfo.GetBaudRate();
|
m_bConnected = TRUE;
|
/*
|
//Turn On
|
char Data[50];
|
memset(&Data[0],0x00,sizeof(Data));
|
sprintf_s(Data, "POWER%c%c", ASCII_CR, ASCII_LF);
|
Write(Data, strlen(Data));
|
*/
|
return TRUE;
|
}
|
|
void CLightControl_LFusion_PDSeries::Disconnect()
|
{
|
if (!m_bConnected) return;
|
|
m_bConnected = FALSE;
|
|
Close();
|
}
|
|
LONG CLightControl_LFusion_PDSeries::ConnectEx( const CLightControlInfo& controlInfo )
|
{
|
return TRUE;
|
}
|
|
void CLightControl_LFusion_PDSeries::DisconnectEx()
|
{
|
|
}
|
|
|
BOOL CLightControl_LFusion_PDSeries::SetLightAllOn()
|
{
|
if (!m_bConnected) return FALSE;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetLightAllOff()
|
{
|
if (!m_bConnected) return FALSE;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetLightOn()
|
{
|
if (!m_bConnected) return FALSE;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetLightOff()
|
{
|
if (!m_bConnected) return FALSE;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetLightOn(int nChannel /*= 0*/)
|
{
|
if (!m_bConnected) return FALSE;
|
/*
|
nValue = m_nCurrentValue;
|
|
int nHigh = nValue / 16;
|
int nLow = nValue % 16;
|
*/
|
CString hex("0123456789ABCDEF");
|
|
char Data[50];
|
memset(&Data[0],0x00,sizeof(Data));
|
//sprintf_s(Data, "CT%02x%c%c", nValue, ASCII_CR, ASCII_LF);
|
//sprintf_s(Data, "CT%c%c%c%c", hex.GetAt(nHigh), hex.GetAt(nLow), ASCII_CR, ASCII_LF);
|
|
sprintf_s(Data, "H%dON%c%c", (nChannel+1), ASCII_CR, ASCII_LF);
|
|
Write(Data, strlen(Data));
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetLightOff(int nChannel /*= 0*/)
|
{
|
if (!m_bConnected) return FALSE;
|
/*
|
nValue = m_nCurrentValue;
|
|
int nHigh = nValue / 16;
|
int nLow = nValue % 16;
|
|
CString hex("0123456789ABCDEF");
|
*/
|
char Data[50];
|
memset(&Data[0],0x00,sizeof(Data));
|
//sprintf_s(Data, "CT%02x%c%c", nValue, ASCII_CR, ASCII_LF);
|
//sprintf_s(Data, "CT%c%c%c%c", hex.GetAt(nHigh), hex.GetAt(nLow), ASCII_CR, ASCII_LF);
|
|
sprintf_s(Data, "H%dOF%c%c", (nChannel+1), ASCII_CR, ASCII_LF);
|
|
Write(Data, strlen(Data));
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetLightLevel(int nValue, int Channel/*= 0*/)
|
{
|
if (!m_bConnected) return FALSE;
|
|
int nHigh = nValue / 16;
|
int nLow = nValue % 16;
|
|
CString hex("0123456789ABCDEF");
|
|
char Data[50];
|
memset(&Data[0],0x00,sizeof(Data));
|
//sprintf_s(Data, "CT%02x%c%c", nValue, ASCII_CR, ASCII_LF);
|
//sprintf_s(Data, "CT%c%c%c%c", hex.GetAt(nHigh), hex.GetAt(nLow), ASCII_CR, ASCII_LF);
|
|
sprintf_s(Data, "C%d%c%c%c%c", (Channel+1), hex.GetAt(nHigh), hex.GetAt(nLow), ASCII_CR, ASCII_LF);
|
|
Write(Data, strlen(Data));
|
|
m_nCurrentValue = nValue;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetLightLevel(double dValue, int Channel)
|
{
|
int nValue = int(dValue+0.5);
|
|
return SetLightLevel(nValue, Channel);
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetAllLightLevel(int nValue)
|
{
|
if (!m_bConnected) return FALSE;
|
|
int nHigh = nValue / 16;
|
int nLow = nValue % 16;
|
|
CString hex("0123456789ABCDEF");
|
|
char Data[50];
|
memset(&Data[0],0x00,sizeof(Data));
|
//sprintf_s(Data, "CT%02x%c%c", nValue, ASCII_CR, ASCII_LF);
|
//sprintf_s(Data, "CT%c%c%c%c", hex.GetAt(nHigh), hex.GetAt(nLow), ASCII_CR, ASCII_LF);
|
|
sprintf_s(Data, "CT%c%c%c%c", hex.GetAt(nHigh), hex.GetAt(nLow), ASCII_CR, ASCII_LF);
|
|
Write(Data, strlen(Data));
|
|
m_nCurrentValue = nValue;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::GetLightLevel(int &nValue, int Channel) const
|
{
|
if (!m_bConnected) return FALSE;
|
|
nValue = m_nCurrentValue;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::GetLightLevel(double &dValue, int Channel) const
|
{
|
if (!m_bConnected) return FALSE;
|
|
dValue = (double)m_nCurrentValue;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetLightStatus(int nValue, int Channel)
|
{
|
if (!m_bConnected) return FALSE;
|
|
int nHigh = nValue / 16;
|
int nLow = nValue % 16;
|
|
CString hex("0123456789ABCDEF");
|
|
char Data[50];
|
memset(&Data[0],0x00,sizeof(Data));
|
//sprintf_s(Data, "CT%02x%c%c", nValue, ASCII_CR, ASCII_LF);
|
//sprintf_s(Data, "CT%c%c%c%c", hex.GetAt(nHigh), hex.GetAt(nLow), ASCII_CR, ASCII_LF);
|
|
if (nValue==0)
|
sprintf_s(Data, "H%dOF%c%c", (Channel+1), hex.GetAt(nHigh), hex.GetAt(nLow), ASCII_CR, ASCII_LF);
|
else
|
sprintf_s(Data, "H%dON%c%c", (Channel+1), hex.GetAt(nHigh), hex.GetAt(nLow), ASCII_CR, ASCII_LF);
|
|
Write(Data, strlen(Data));
|
|
m_nCurrentValue = nValue;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::GetLightStatus(int &nValue, int Channel) const
|
{
|
if (!m_bConnected) return FALSE;
|
|
nValue = m_nCurrentStatus;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetLightResolution( int nResolution /*= 0*/ )
|
{
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetLightFilter( int nFilterPosition /*= 0*/ )
|
{
|
return TRUE;
|
}
|
|
int CLightControl_LFusion_PDSeries::GetLightFilter()
|
{
|
return 1;
|
}
|
|
int CLightControl_LFusion_PDSeries::GetStatus( int& nStatusCode, CString& strStatusMessage )
|
{
|
|
CLightControlInfo controlInfo;
|
controlInfo.SetIndex(0);
|
controlInfo.SetName(_T("TestLightControl"));
|
controlInfo.SetControllerType(-1);
|
controlInfo.SetConnectionPort(m_ControlInfo.GetConnectionPort());
|
controlInfo.SetBaudRate(9600);
|
controlInfo.SetDefaultValue(100);
|
controlInfo.SetCurrentValue(100);
|
controlInfo.SetMaxValue(255);
|
controlInfo.SetMinValue(0);
|
controlInfo.SetChannel(0);
|
controlInfo.SetMaster(1);
|
|
if (Connect(controlInfo) == FALSE)
|
{
|
nStatusCode = LightStatus_NotConnected;
|
strStatusMessage = _T("Not_Connected");
|
}
|
else
|
{
|
nStatusCode = LightStatus_Connected;
|
strStatusMessage = _T("Connected");
|
|
|
char Data[50];
|
memset(&Data[0],0x00,sizeof(Data));
|
|
sprintf_s(Data, "S102%c%c", ASCII_CR, ASCII_LF); // S102 ERRORÈ®ÀÎ
|
|
Write(Data, strlen(Data));
|
|
::Sleep(50);
|
|
char buf[200] = {0,};
|
int m_lLastError = Read(buf,200, 0, 0, 1000); // Àӽ÷Π1000ms(?) ¼ÂÆÃ
|
|
if (m_lLastError == NO_ERROR)
|
{
|
if (buf[0] == 'R' && buf[1] == '1' && buf[2]=='O' && buf[3]=='K') return 1;
|
else if (buf[0] == 'R' && buf[1] == '1' && buf[2]=='E' && buf[3]=='R') return 2;
|
else return 3;
|
}
|
else return 0;
|
}
|
return 0;
|
}
|
|
/*
|
BOOL CLightControl_LFusion_PDSeries::SetCalibrationModeCheck( int nValue, int Channel )
|
{
|
return TRUE;
|
}
|
|
BOOL CLightControl_LFusion_PDSeries::SetCalibrationData( VectorCalibrationData &vectorCaliData )
|
{
|
return TRUE;
|
}
|
*/
|