5 |
#include "H7 Server.h" |
#include "H7 Server.h" |
6 |
#include "H7 ServerDlg.h" |
#include "H7 ServerDlg.h" |
7 |
#include ".\h7 serverdlg.h" |
#include ".\h7 serverdlg.h" |
8 |
|
#include <vector> |
9 |
|
|
10 |
#ifdef _DEBUG |
#ifdef _DEBUG |
11 |
#define new DEBUG_NEW |
#define new DEBUG_NEW |
12 |
#endif |
#endif |
13 |
|
|
14 |
|
|
15 |
|
std::vector<CString> GetAvailableComPorts() |
16 |
|
{ |
17 |
|
std::vector<CString> ports; |
18 |
|
|
19 |
|
for (int i = 1; i < 20; i++) |
20 |
|
{ |
21 |
|
CString port; |
22 |
|
port.Format("COM%d", i); |
23 |
|
|
24 |
|
|
25 |
|
HANDLE handle = CreateFile(port, |
26 |
|
GENERIC_READ | GENERIC_WRITE, |
27 |
|
0, |
28 |
|
0, |
29 |
|
OPEN_EXISTING, |
30 |
|
0, |
31 |
|
NULL); |
32 |
|
|
33 |
|
if (handle != INVALID_HANDLE_VALUE) |
34 |
|
{ |
35 |
|
CloseHandle(handle); |
36 |
|
ports.push_back(port); |
37 |
|
} |
38 |
|
} |
39 |
|
return ports; |
40 |
|
} |
41 |
|
|
42 |
// CAboutDlg dialog used for App About |
// CAboutDlg dialog used for App About |
43 |
|
|
44 |
class CAboutDlg : public CDialog |
class CAboutDlg : public CDialog |
98 |
ON_WM_QUERYDRAGICON() |
ON_WM_QUERYDRAGICON() |
99 |
//}}AFX_MSG_MAP |
//}}AFX_MSG_MAP |
100 |
ON_BN_CLICKED(IDC_Start, OnBnClickedStart) |
ON_BN_CLICKED(IDC_Start, OnBnClickedStart) |
101 |
|
ON_BN_CLICKED(IDC_TEST, OnBnClickedTest) |
102 |
END_MESSAGE_MAP() |
END_MESSAGE_MAP() |
103 |
|
|
104 |
|
|
133 |
|
|
134 |
/**********************************************************************/ |
/**********************************************************************/ |
135 |
// TODO: Add extra initialization here |
// TODO: Add extra initialization here |
136 |
|
// Sets values in baud-rate combo box |
137 |
|
m_BaudRate.AddString("1200"); |
138 |
|
m_BaudRate.AddString("2400"); |
139 |
|
m_BaudRate.AddString("4800"); |
140 |
|
m_BaudRate.AddString("9600"); |
141 |
|
m_BaudRate.AddString("19200"); |
142 |
|
|
143 |
|
std::vector<CString> Serial = GetAvailableComPorts(); |
144 |
|
for (int i=0;i<Serial.size();i++) |
145 |
|
m_Serial.AddString(Serial[i]); |
146 |
|
m_Serial.SetCurSel(0); |
147 |
|
|
148 |
/**********************************************************************/ |
/**********************************************************************/ |
149 |
return TRUE; // return TRUE unless you set the focus to a control |
return TRUE; // return TRUE unless you set the focus to a control |
200 |
|
|
201 |
void CH7ServerDlg::OnBnClickedStart() |
void CH7ServerDlg::OnBnClickedStart() |
202 |
{ |
{ |
|
CString Port = NULL; |
|
|
CString Tmp; |
|
|
m_Port.GetWindowText(Port); |
|
203 |
CRegKey reg; |
CRegKey reg; |
204 |
reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Server"); |
reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Server"); |
205 |
reg.SetStringValue("Port",Port); |
unsigned long Port; |
206 |
reg.Close(); |
reg.QueryDWORDValue("Port", Port); |
|
|
|
207 |
|
|
208 |
m_Status.SetWindowText(Port); |
CString tmp; |
209 |
|
tmp.Format("%d", Port); |
210 |
|
m_Port.SetWindowText(tmp); |
211 |
} |
} |
212 |
|
|
213 |
/*CString CH7ServerDlg::SetTcpPort(CString Port) |
int CH7ServerDlg::StartTcp(void) |
214 |
{ |
{ |
215 |
CString Tmp; |
unsigned long Port; |
216 |
m_Port.GetWindowText(Tmp); |
CRegKey reg; |
217 |
// if( Tmp ) |
reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Server"); |
218 |
// Port = atoi(Tmp); |
reg.QueryDWORDValue("Port", Port); |
219 |
MessageBox(Port); |
TcpServer.Create(Port); |
220 |
|
TcpServer.Listen(); |
221 |
|
return 0; |
222 |
|
} |
223 |
|
|
224 |
return Port; |
void CH7ServerDlg::OnBnClickedTest() |
225 |
|
{ |
226 |
|
//**************** <TCP Port section> ****************/ |
227 |
|
CString Port = ""; |
228 |
|
|
229 |
|
m_Port.GetWindowText(Port); |
230 |
|
// Saving Port number in regedit as int |
231 |
|
CRegKey reg; |
232 |
|
reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Server"); |
233 |
|
reg.SetDWORDValue("Port", atoi(Port) ); |
234 |
|
reg.Close(); |
235 |
|
// Debug info to the status edit box. |
236 |
|
m_Status.SetWindowText(Port); |
237 |
|
//**************** </TCP Port section> ****************/ |
238 |
|
StartTcp(); |
239 |
} |
} |
|
*/ |
|
240 |
|
|