#include "StdAfx.h"
|
#include "CHLightControls/LightControl_ALT_8RSDF.h"
|
|
CLightControl_ALT_8RSDF::CLightControl_ALT_8RSDF(int nIndex) : CLightControl(nIndex)
|
{
|
m_bConnected = FALSE;
|
m_nPortIndex = 1;
|
m_nBaudRate = EBaud19200;
|
m_nIndex = nIndex;
|
m_bMultiCH = FALSE;
|
m_nCurrentChannel = 0;
|
|
for (int i=0; i<MAX_CHANNEL; i++)
|
{
|
m_nCurrentValue[i] = 0;
|
m_nCurrentStatus[i] = 0;
|
}
|
}
|
|
CLightControl_ALT_8RSDF::~CLightControl_ALT_8RSDF(void)
|
{
|
Disconnect();
|
}
|
|
BOOL CLightControl_ALT_8RSDF::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::EBaud19200,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);
|
SetupHandshaking(CSerial::EHandshakeOff);
|
|
m_nPortIndex = nPort;
|
m_nBaudRate = controlInfo.GetBaudRate();
|
m_bConnected = TRUE;
|
|
//Turn On
|
SetLightAllOn();
|
|
return TRUE;
|
}
|
|
void CLightControl_ALT_8RSDF::Disconnect()
|
{
|
if (!m_bConnected) return;
|
|
SetLightAllOff();
|
|
m_bConnected = FALSE;
|
|
Close();
|
}
|
|
// [2017:1:20]-[WEZASW] : Align CameraÀÇ Á¶¸í ä³Î ºÐ¸®(´ÙÁß Ã¤³Î »ç¿ë)
|
LONG CLightControl_ALT_8RSDF::ConnectEx(const CLightControlInfo& controlInfo)
|
{
|
LONG lErrorCode = ERROR_SUCCESS;
|
|
m_ControlInfo = controlInfo;
|
|
int nPort = _ttoi(controlInfo.GetConnectionPort());
|
if(nPort < 1) return FALSE;
|
|
if (controlInfo.GetMaster() == TRUE)
|
{
|
CString strProt = _T("");
|
|
if(IsOpen()) { Close(); }
|
|
if(nPort > 9) {
|
strProt.Format(_T("\\\\.\\\\COM%d"), nPort);
|
}else{
|
strProt.Format(_T("COM%d"), nPort);
|
}
|
|
lErrorCode = Open(strProt,NULL);
|
if (lErrorCode != ERROR_SUCCESS)
|
{
|
m_bConnected = FALSE;
|
return lErrorCode;
|
}
|
|
m_bMultiCH = FALSE;
|
Setup(CSerial::EBaud19200,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);
|
SetupHandshaking(CSerial::EHandshakeOff);
|
}
|
else
|
{
|
m_bMultiCH = TRUE;
|
|
if (controlInfo.GetIndex() == CHANNEL2)
|
{
|
return 100; // Multi ChannelÀÇ Slave ä³Î ¼³Á¤
|
}
|
return 10; // Multi ChannelÀÇ Master ä³Î ¼³Á¤ ¿À·ù
|
}
|
|
m_nPortIndex = nPort;
|
m_nBaudRate = controlInfo.GetBaudRate();
|
m_bConnected = TRUE;
|
|
//Turn On
|
SetLightAllOn();
|
|
return lErrorCode;
|
}
|
|
void CLightControl_ALT_8RSDF::DisconnectEx()
|
{
|
if (!m_bConnected) return;
|
|
SetLightAllOff();
|
|
m_bConnected = FALSE;
|
|
Close();
|
}
|
|
BOOL CLightControl_ALT_8RSDF::SetLightStatus(int nValue, int Channel)
|
{
|
if (!m_bConnected) return FALSE;
|
|
m_nCurrentStatus[Channel] = nValue;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_ALT_8RSDF::GetLightStatus(int &nValue, int Channel) const
|
{
|
if (!m_bConnected) return FALSE;
|
|
nValue = m_nCurrentStatus[Channel];
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_ALT_8RSDF::GetLightLevel(int &nValue, int Channel) const
|
{
|
if (!m_bConnected) return FALSE;
|
|
nValue = m_nCurrentValue[Channel];
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_ALT_8RSDF::GetLightLevel(double &dValue, int Channel) const
|
{
|
if (!m_bConnected) return FALSE;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_ALT_8RSDF::SetLightLevel(int nValue, int nChannel)
|
{
|
if (!m_bConnected) return FALSE;
|
if (nValue<0 || nValue>255) return FALSE;
|
|
char sendData[50];
|
memset(&sendData[0],0x00,sizeof(sendData));
|
|
char lightValue[5] = {0,};
|
|
lightValue[0] = (UCHAR)nChannel + 0x30;
|
lightValue[1] = 0x30 + nValue/100;
|
lightValue[2] = 0x30 + (nValue%100)/10;
|
lightValue[3] = 0x30 + (nValue%100)%10;
|
|
sprintf_s(sendData, "%c%c%c%c%c%c%c",
|
ALT_HEADER, lightValue[0], lightValue[1], lightValue[2], lightValue[3], ALT_TAIL1, ALT_TAIL2);
|
|
if (Write(sendData, 7)!=0) { return FALSE; }
|
|
/*
|
// Read
|
DWORD dwBytesRead = 0;
|
BYTE abBuffer[50];
|
do
|
{
|
// Read data from the COM-port
|
Read(abBuffer,sizeof(abBuffer),&dwBytesRead);
|
if (dwBytesRead > 0)
|
{
|
// TODO: Process the data
|
}
|
}
|
while (dwBytesRead == sizeof(abBuffer));
|
*/
|
|
m_nCurrentValue[nChannel] = nValue;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_ALT_8RSDF::SetLightLevel(double dValue, int nChannel)
|
{
|
if (!m_bConnected) return FALSE;
|
|
return TRUE;
|
}
|
|
|
BOOL CLightControl_ALT_8RSDF::SetLightOn()
|
{
|
return TRUE;
|
}
|
|
BOOL CLightControl_ALT_8RSDF::SetLightOff()
|
{
|
return TRUE;
|
}
|
|
BOOL CLightControl_ALT_8RSDF::SetLightOn(int Channel)
|
{
|
if (!m_bConnected) return FALSE;
|
|
char sendData[50];
|
memset(&sendData[0],0x00,sizeof(sendData));
|
|
char lightValue[5] = {0,};
|
|
lightValue[0] = (UCHAR)(Channel) + 0x30;
|
lightValue[1] = 0x30 + m_nCurrentValue[Channel]/100;
|
lightValue[2] = 0x30 + (m_nCurrentValue[Channel]%100)/10;
|
lightValue[3] = 0x30 + (m_nCurrentValue[Channel]%100)%10;
|
|
sprintf_s(sendData, "%c%c%c%c%c%c%c",
|
ALT_HEADER, lightValue[0], lightValue[1], lightValue[2], lightValue[3], ALT_TAIL1, ALT_TAIL2);
|
|
if (Write(sendData, 7)!=0) { return FALSE; }
|
m_nCurrentStatus[Channel] = 1;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_ALT_8RSDF::SetLightOff(int Channel)
|
{
|
if (!m_bConnected) return FALSE;
|
|
char sendData[50];
|
memset(&sendData[0],0x00,sizeof(sendData));
|
|
char lightValue[5] = {0,};
|
|
lightValue[0] = (UCHAR)(Channel) + 0x30;
|
lightValue[1] = 0x30 + 0/100;
|
lightValue[2] = 0x30 + (0%100)/10;
|
lightValue[3] = 0x30 + (0%100)%10;
|
|
sprintf_s(sendData, "%c%c%c%c%c%c%c",
|
ALT_HEADER, lightValue[0], lightValue[1], lightValue[2], lightValue[3], ALT_TAIL1, ALT_TAIL2);
|
|
if (Write(sendData, 7)!=0) { return FALSE; }
|
m_nCurrentStatus[Channel] = 0;
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_ALT_8RSDF::SetLightAllOn()
|
{
|
if (!m_bConnected) return FALSE;
|
|
for (int i=0; i<MAX_CHANNEL; i++)
|
{
|
SetLightOn(i);
|
Sleep(10);
|
}
|
|
return TRUE;
|
}
|
|
BOOL CLightControl_ALT_8RSDF::SetLightAllOff()
|
{
|
if (!m_bConnected) return FALSE;
|
|
for (int i=0; i<MAX_CHANNEL; i++)
|
{
|
SetLightOff(i);
|
Sleep(10);
|
}
|
|
return TRUE;
|
}
|
|
int CLightControl_ALT_8RSDF::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;
|
}
|