SDC C-Project CF Review 프로그램
LYW
2021-08-17 572aebd50409d2f11183d6ebbb9d12fe9041e7a5
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
#include "StdAfx.h"
#include "VcrControl_WinforSys_CodeImage.h"
 
 
CVcrControl_WinforSys_CodeImage::CVcrControl_WinforSys_CodeImage(int nIndex) : CVcrControl(nIndex)
{
    m_bConnected    = FALSE;
    m_nPortIndex    = 1;
    m_nBaudRate        = 9600;
    m_nCurrentValue = 100;
    m_nCurrentStatus = 0;
}
 
CVcrControl_WinforSys_CodeImage::~CVcrControl_WinforSys_CodeImage(void)
{
    Disconnect();
}
 
BOOL CVcrControl_WinforSys_CodeImage::Connect(const CVcrControlInfo& 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, "CTON%c%c", ASCII_CR, ASCII_LF);
    Write(Data, strlen(Data));
 
    return TRUE;
}
 
void CVcrControl_WinforSys_CodeImage::Disconnect()
{
    if (!m_bConnected) return;
 
    m_bConnected = FALSE;
 
    Close();
}
 
BOOL CVcrControl_WinforSys_CodeImage::SetLightOn()
{
    if (!m_bConnected) return FALSE;
 
    return TRUE;
}
 
BOOL CVcrControl_WinforSys_CodeImage::SetLightOff()
{
    if (!m_bConnected) return FALSE;
 
    return TRUE;
}
 
BOOL CVcrControl_WinforSys_CodeImage::SetLightLevel(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);
 
    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 CVcrControl_WinforSys_CodeImage::SetLightLevel(double dValue, int Channel)
{
    int nValue = int(dValue+0.5);
 
    return SetLightLevel(nValue, Channel);
}
 
BOOL CVcrControl_WinforSys_CodeImage::GetLightLevel(int &nValue, int Channel) const
{
    if (!m_bConnected) return FALSE;
 
    nValue = m_nCurrentValue;
 
    return TRUE;
}
 
BOOL CVcrControl_WinforSys_CodeImage::GetLightLevel(double &dValue, int Channel) const
{
    if (!m_bConnected) return FALSE;
 
    dValue = (double)m_nCurrentValue;
 
    return TRUE;
}
 
BOOL CVcrControl_WinforSys_CodeImage::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 CVcrControl_WinforSys_CodeImage::GetLightStatus(int &nValue, int Channel) const
{
    if (!m_bConnected) return FALSE;
 
    nValue = m_nCurrentStatus;
 
    return TRUE;
}