--- trunk/FlisServer/FlisServerDlg.cpp 2007/12/03 10:42:07 131 +++ trunk/FlisServer/FlisServerDlg.cpp 2007/12/03 11:46:03 132 @@ -162,11 +162,13 @@ CString SerialPort = "COM3"; Baud = 1200; - if( Serial.isOpen() ){ + if( Serial.isOpen() ) + { Serial.close(); Serial.open( SerialPort, Baud ); } - else { + else + { Serial.open( SerialPort, Baud ); } @@ -178,9 +180,9 @@ std::vector buf; while(Serial.getComstat().cbInQue > 0) { - unsigned char data = Serial.readByte(); + unsigned char data = Serial.readByte(); - buf.push_back(data); + buf.push_back(data); } return buf; } @@ -214,28 +216,6 @@ data.push_back('5'); writeFrame(data); -/* Sleep(750); - if(Serial.getComstat().cbInQue > 0) - { - std::vector answer = readFrame(); - Sleep(50); - char array1[25]; - int i; - for (int i=0; i data) { @@ -390,31 +370,28 @@ Flis = Splitter(FyrData); FremFejl = Splitter(FyrData); PowerFail = Splitter(FyrData); -/////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////// Her skal sendes data til databasen ////NÅR HEDIN KAN SENDE SMS/////////////////// - m_Textwindow.GetWindowText(oldtekst); - oldtekst.Append("\r\n"); - oldtekst.Append("På næste linie kommer SmsCount. \r\n"); - oldtekst.Append(SmsCount); - oldtekst.Append("\r\n"); - oldtekst.Append("På næste linie kommer Temper. \r\n"); - oldtekst.Append(Temper); - oldtekst.Append("\r\n"); - oldtekst.Append("På næste linie kommer Flamme. \r\n"); - oldtekst.Append(Flamme); - oldtekst.Append("\r\n"); - oldtekst.Append("På næste linie kommer Flis. \r\n"); - oldtekst.Append(Flis); - oldtekst.Append("\r\n"); - oldtekst.Append("På næste linie kommer FremFejl. \r\n"); - oldtekst.Append(FremFejl); - oldtekst.Append("\r\n"); - oldtekst.Append("På næste linie kommer PowerFail. \r\n"); - oldtekst.Append(PowerFail); - oldtekst.Append("\r\n"); - oldtekst.Append("På næste linie kommer TlfNR. \r\n"); - oldtekst.Append(TlfNr); - m_Textwindow.SetWindowText(oldtekst); + + CString SQL, Textwindow, InstallNR; + SQL.Format("select ID from installation where installationphonenr=%s",TlfNr); + + CRecordset rs(&db); + rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); + if (rs.GetRecordCount()>0) + { + rs.MoveFirst(); + rs.GetFieldValue((short)0,InstallNR); + } + rs.Close(); + + SQL.Format("insert into logtable (logtime,temperature,flamedetector,solidfuelempty,conveyorerror,powerfailure,messagenr,installationnr) Values (now(),%s,'%s','%s','%s','%s',%s,%s)",Temper, Flamme, Flis, FremFejl, PowerFail, SmsCount,InstallNR); + db.ExecuteSQL(SQL); + + m_Textwindow.GetWindowText(Textwindow); + Textwindow.Append("\r\n"); + Textwindow.Append("Sms added to Log"); + m_Textwindow.SetWindowText(Textwindow); + Sleep(150); + /////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////// Her skal sendes data til databasen ////////////////////////////////////////////// } @@ -434,7 +411,7 @@ { // TODO: Add your control notification handler code here continueThread = 0; - DeleteSms(); //<--- crasher, men gider ikke bruge flere af mine penge på at teste det med sms'er, hele close laver crash, bare ikke når jeg stepper. :S + DeleteSms(); Sleep(500); if( Serial.isOpen() ) @@ -444,7 +421,7 @@ if(db.IsOpen()) { - db.Close(); + db.Close(); } OnOK(); @@ -454,8 +431,16 @@ void CFlisServerDlg::OnBnClickedGsmpin() { // TODO: Add your control notification handler code here + m_Textwindow.SetWindowText("Indsætter Pinkode, efterfuldt af 60sec pause"); + UpdateWindow(); SetPin(); - Sleep(35000); + Sleep(50000); + + while (Serial.getComstat().cbInQue > 0) + { + Serial.readByte(); //Flush the incoming queue + } + OnBnClickedStart(); } void CFlisServerDlg::DeleteSms() @@ -583,9 +568,11 @@ { data.push_back(smscount[i]); } + m_Textwindow.GetWindowText(oldteskst); + oldteskst.Append("\r\n"); for (int i=0; i 1) { - testdata.Append(data[i].InstallationsID); - testdata.Append(":"); + testdata.Append(data[i].InstallationsID); + testdata.Append(":"); } } sIDnr = Splitter(testdata); @@ -636,8 +636,8 @@ sInstallationsID = "0"; if (commandtest > 1) { - sInstallationsID = Splitter(testdata); - iAll = 0; + sInstallationsID = Splitter(testdata); + iAll = 0; } if (sIDnr.GetLength() > 0) @@ -774,6 +774,6 @@ // TODO: Add your control notification handler code here continueThread = 1; - + m_Textwindow.SetWindowText("Started"); AfxBeginThread(threadWrapper,AfxGetMainWnd()); }