166 |
} |
} |
167 |
m_Restart.EnableWindow(false); |
m_Restart.EnableWindow(false); |
168 |
m_Stop.EnableWindow(false); |
m_Stop.EnableWindow(false); |
169 |
m_BaudRate.EnableWindow(false); |
//m_BaudRate.EnableWindow(false); |
170 |
m_First = true; |
m_First = true; |
171 |
/**********************************************************************/ |
/**********************************************************************/ |
172 |
return TRUE; // return TRUE unless you set the focus to a control |
return TRUE; // return TRUE unless you set the focus to a control |
229 |
void CH7ServerDlg::OnBnClickedStart() |
void CH7ServerDlg::OnBnClickedStart() |
230 |
{ |
{ |
231 |
// Add's user defined Baud-Rate to regedit before the server start. |
// Add's user defined Baud-Rate to regedit before the server start. |
232 |
CRegKey reg; |
// CRegKey reg; |
233 |
CString Baud = "9600"; |
// CString Baud = "9600"; |
234 |
// m_BaudRate.GetWindowText(Baud); |
// m_BaudRate.GetWindowText(Baud); |
235 |
|
|
236 |
reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Server"); |
// reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Server"); |
237 |
reg.SetDWORDValue("BaudRate", atoi(Baud) ); |
// reg.SetDWORDValue("BaudRate", atoi(Baud) ); |
238 |
|
|
239 |
StartTcp(); |
// StartTcp(); |
240 |
StartSerial(); |
StartSerial(); |
241 |
m_Stop.EnableWindow(true); |
m_Stop.EnableWindow(true); |
242 |
m_Restart.EnableWindow(true); |
m_Restart.EnableWindow(true); |
281 |
|
|
282 |
int CH7ServerDlg::StartSerial(void) |
int CH7ServerDlg::StartSerial(void) |
283 |
{ |
{ |
284 |
|
int Baud; |
285 |
|
int dBaud; |
286 |
CString SerialPort; |
CString SerialPort; |
|
unsigned long size = 6; |
|
|
unsigned long Baud; |
|
|
|
|
287 |
|
|
288 |
CRegKey reg; |
Baud = m_BaudRate.GetCurSel(); |
|
|
|
|
reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Server"); |
|
|
reg.QueryDWORDValue("BaudRate", Baud); |
|
289 |
m_Serial.GetWindowText(SerialPort); |
m_Serial.GetWindowText(SerialPort); |
290 |
|
|
291 |
// Starter Serial forbindelsen, hvis den ikke allerede er startet. |
switch (Baud) |
|
if( m_First == 1 ){ |
|
|
Baud = 9600; |
|
|
} |
|
|
else |
|
|
{ |
|
|
int selected = m_BaudRate.GetCurSel(); |
|
|
try |
|
|
{ |
|
|
H7Serial.writeTarget(10,selected); |
|
|
} |
|
|
catch (std::exception e) |
|
|
{ |
|
|
MessageBox("PIC could not use selected baudrate"); |
|
|
return 0; |
|
|
|
|
|
} |
|
|
switch (selected) |
|
292 |
{ |
{ |
293 |
case 0: |
case 0: |
294 |
Baud = 1200; |
dBaud = 1200; |
295 |
break; |
break; |
296 |
case 1: |
case 1: |
297 |
Baud = 2400; |
dBaud = 2400; |
298 |
break; |
break; |
299 |
case 2: |
case 2: |
300 |
Baud = 4800; |
dBaud = 4800; |
301 |
break; |
break; |
302 |
case 3: |
case 3: |
303 |
Baud = 9600;; |
dBaud = 9600; |
304 |
break; |
break; |
305 |
case 4: |
case 4: |
306 |
Baud = 19200; |
dBaud = 19200; |
307 |
break; |
break; |
308 |
|
|
309 |
default: //this should not be possible, but ... |
default: //this should not be possible, but ... |
310 |
Baud = 9600; |
dBaud = 9600; |
311 |
break; |
break; |
312 |
} |
} |
313 |
|
|
314 |
|
if( H7Serial.isOpen() ){ |
315 |
|
try |
316 |
|
{ |
317 |
|
H7Serial.writeTarget(10, Baud); |
318 |
|
} |
319 |
|
catch (std::exception e) |
320 |
|
{ |
321 |
|
MessageBox( "Pic could not use selected baud rate." ); |
322 |
|
return 0; |
323 |
|
} |
324 |
H7Serial.close(); |
H7Serial.close(); |
325 |
|
H7Serial.open( SerialPort, dBaud ); |
326 |
|
} |
327 |
|
else { |
328 |
|
H7Serial.open( SerialPort, dBaud ); |
329 |
} |
} |
330 |
|
|
331 |
if (!H7Serial.isOpen()) |
Sleep(50); |
332 |
H7Serial.open( SerialPort,Baud); |
|
333 |
|
|
334 |
|
try { |
335 |
m_First = false; |
int pot = H7Serial.readTarget(5); |
336 |
// Nulstiller LED's |
CString debug; |
337 |
H7Serial.writeTarget(LED3,OFF); |
debug.Format("%d", pot); |
338 |
H7Serial.writeTarget(LED4,OFF); |
MessageBox(debug); |
339 |
H7Serial.writeTarget(LED5,OFF); |
} |
340 |
return 0; |
catch (...) |
341 |
|
{ |
342 |
|
MessageBox("Major fuck-up"); |
343 |
|
} |
344 |
|
|
345 |
|
|
346 |
|
return 0; |
347 |
} |
} |
348 |
|
|
349 |
void CH7ServerDlg::UpdateClient(TcpClientClass* caller) |
void CH7ServerDlg::UpdateClient(TcpClientClass* caller) |