SDC C-Project CF Review 프로그램
SWK
2023-03-10 5ce2e7ca14f09da2138ea783ef16044a01423413
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#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;
}